From e059ce1d01466f5b9ab73eb47d52a98816341df0 Mon Sep 17 00:00:00 2001 From: Nicolas Ayral Seydoux Date: Thu, 12 Dec 2024 11:56:08 +0100 Subject: [PATCH] Extend coverage of reserved fields --- .../request/issueAccessRequest.test.ts | 83 +++++++++---------- 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/src/gConsent/request/issueAccessRequest.test.ts b/src/gConsent/request/issueAccessRequest.test.ts index f378b8a4..0524b0ab 100644 --- a/src/gConsent/request/issueAccessRequest.test.ts +++ b/src/gConsent/request/issueAccessRequest.test.ts @@ -22,6 +22,8 @@ import { jest, describe, it, expect, beforeAll } from "@jest/globals"; import type * as VcLibrary from "@inrupt/solid-client-vc"; +import type { NamedNode } from "n3"; +import { INHERIT, acl, gc } from "../../common/constants"; import type { CustomField } from "../../type/CustomField"; import { issueAccessRequest, @@ -715,51 +717,40 @@ describe.each([true, false, undefined])( ).rejects.toThrow(); }); - it("throws if using reserved predicates as custom fields", async () => { - mockAccessApiEndpoint(); - - await expect(() => - issueAccessRequest( - { - access: { read: true }, - resourceOwner: MOCK_RESOURCE_OWNER_IRI, - resources: ["https://some.pod/resource"], - requestorInboxUrl: MOCK_REQUESTOR_INBOX, - }, - { - fetch: jest.fn(), - returnLegacyJsonld, - customFields: new Set([ - { - key: new URL("https://w3id.org/GConsent#forPersonalData"), - value: "customValue", - }, - ]), - }, - ), - ).rejects.toThrow(); - - await expect(() => - issueAccessRequest( - { - access: { read: true }, - resourceOwner: MOCK_RESOURCE_OWNER_IRI, - resources: ["https://some.pod/resource"], - requestorInboxUrl: MOCK_REQUESTOR_INBOX, - }, - { - fetch: jest.fn(), - returnLegacyJsonld, - customFields: new Set([ - { - key: new URL("https://example.org/ns/customField"), - value: { notA: "literal" }, - // Mimic a user passing in bad data not caught by a TS compiler - } as unknown as CustomField, - ]), - }, - ), - ).rejects.toThrow(); - }); + it.each([ + [gc.forPersonalData], + [gc.forPurpose], + [gc.isProvidedTo], + [gc.isProvidedToController], + [gc.isProvidedToPerson], + [acl.mode], + [INHERIT], + ])( + "throws if using reserved predicate %s as custom fields", + async (reserved: NamedNode) => { + mockAccessApiEndpoint(); + + await expect(() => + issueAccessRequest( + { + access: { read: true }, + resourceOwner: MOCK_RESOURCE_OWNER_IRI, + resources: ["https://some.pod/resource"], + requestorInboxUrl: MOCK_REQUESTOR_INBOX, + }, + { + fetch: jest.fn(), + returnLegacyJsonld, + customFields: new Set([ + { + key: new URL(reserved.value), + value: "customValue", + }, + ]), + }, + ), + ).rejects.toThrow(); + }, + ); }, );