Skip to content

Commit

Permalink
Remove support for writing arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
NSeydoux committed Dec 10, 2024
1 parent 21f13bf commit 8d97f4a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 305 deletions.
192 changes: 28 additions & 164 deletions src/gConsent/manage/approveAccessRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,22 +462,6 @@ describe("approveAccessRequest", () => {
key: new URL("https://example.org/ns/customFloat"),
value: 1.1,
},
{
key: new URL("https://example.org/ns/customStringArray"),
value: ["customValue", "otherCustomValue"],
},
{
key: new URL("https://example.org/ns/customBooleanArray"),
value: [true, false],
},
{
key: new URL("https://example.org/ns/customIntArray"),
value: [1, 2],
},
{
key: new URL("https://example.org/ns/customFloatArray"),
value: [1.1, 2.2],
},
];
const customRequest = await mockAccessRequestVc({ custom: customFields });
await approveAccessRequest(customRequest, undefined, {
Expand Down Expand Up @@ -827,22 +811,6 @@ describe("approveAccessRequest", () => {
key: new URL("https://example.org/ns/customFloat"),
value: 1.1,
},
{
key: new URL("https://example.org/ns/customStringArray"),
value: ["customValue", "otherCustomValue"],
},
{
key: new URL("https://example.org/ns/customBooleanArray"),
value: [true, false],
},
{
key: new URL("https://example.org/ns/customIntArray"),
value: [1, 2],
},
{
key: new URL("https://example.org/ns/customFloatArray"),
value: [1.1, 2.2],
},
];
const customRequest = await mockAccessRequestVc({ custom: customFields });
await approveAccessRequest(
Expand Down Expand Up @@ -872,22 +840,6 @@ describe("approveAccessRequest", () => {
key: new URL("https://example.org/ns/customFloat"),
value: 2.2,
},
{
key: new URL("https://example.org/ns/customStringArray"),
value: ["overriden customValue", "overriden otherCustomValue"],
},
{
key: new URL("https://example.org/ns/customBooleanArray"),
value: [false, false, false],
},
{
key: new URL("https://example.org/ns/customIntArray"),
value: [2, 3, 4],
},
{
key: new URL("https://example.org/ns/customFloatArray"),
value: [2.2, 3.3, 4.4],
},
]),
},
{
Expand All @@ -908,13 +860,6 @@ describe("approveAccessRequest", () => {
"https://example.org/ns/customBoolean": false,
"https://example.org/ns/customInt": 2,
"https://example.org/ns/customFloat": 2.2,
"https://example.org/ns/customStringArray": [
"overriden customValue",
"overriden otherCustomValue",
],
"https://example.org/ns/customBooleanArray": [false, false, false],
"https://example.org/ns/customIntArray": [2, 3, 4],
"https://example.org/ns/customFloatArray": [2.2, 3.3, 4.4],
},
inbox: "https://some-custom.inbox",
}),
Expand All @@ -925,7 +870,7 @@ describe("approveAccessRequest", () => {
);
});

it("collapses overriden custom fields using the same key into a single array value", async () => {
it("throws if multiple overriden custom fields use the same key", async () => {
mockAcpClient();
mockAccessApiEndpoint();
const mockedVcModule = jest.requireMock(
Expand All @@ -943,114 +888,33 @@ describe("approveAccessRequest", () => {
},
];
const customRequest = await mockAccessRequestVc({ custom: customFields });
await approveAccessRequest(
customRequest,
{
access: { append: true },
expirationDate: new Date(2021, 9, 14),
issuanceDate: new Date(2021, 9, 15),
purpose: ["https://some-custom.purpose"],
requestor: "https://some-custom.requestor",
resources: ["https://some-custom.resource"],
requestorInboxUrl: "https://some-custom.inbox",
customFields: new Set([
{
key: new URL("https://example.org/ns/customString"),
value: "overridden custom value",
},
{
key: new URL("https://example.org/ns/customString"),
value: "another custom value",
},
{
key: new URL("https://example.org/ns/customString"),
value: "yet another custom value",
},
]),
},
{
fetch: jest.fn<typeof fetch>(),
},
);

expect(spiedIssueRequest).toHaveBeenCalledWith(
`${MOCKED_ACCESS_ISSUER}/issue`,
expect.objectContaining({
providedConsent: expect.objectContaining({
"https://example.org/ns/customString": [
"overridden custom value",
"another custom value",
"yet another custom value",
],
}),
}),
expect.anything(),
expect.anything(),
);
});

it("supports overriden custom fields using the same key having different value types", async () => {
mockAcpClient();
mockAccessApiEndpoint();
const mockedVcModule = jest.requireMock(
"@inrupt/solid-client-vc",
) as typeof VcClient;
const spiedIssueRequest = jest.spyOn(
mockedVcModule,
"issueVerifiableCredential",
);
spiedIssueRequest.mockResolvedValueOnce(accessGrantVc);
const customFields = [
{
key: new URL("https://example.org/ns/customField"),
value: "custom value",
},
];
const customRequest = await mockAccessRequestVc({ custom: customFields });
await approveAccessRequest(
customRequest,
{
access: { append: true },
expirationDate: new Date(2021, 9, 14),
issuanceDate: new Date(2021, 9, 15),
purpose: ["https://some-custom.purpose"],
requestor: "https://some-custom.requestor",
resources: ["https://some-custom.resource"],
requestorInboxUrl: "https://some-custom.inbox",
customFields: new Set([
{
key: new URL("https://example.org/ns/customField"),
value: "overridden custom value",
},
{
key: new URL("https://example.org/ns/customField"),
value: true,
},
{
key: new URL("https://example.org/ns/customField"),
value: 1,
},
]),
},
{
fetch: jest.fn<typeof fetch>(),
},
);

expect(spiedIssueRequest).toHaveBeenCalledWith(
`${MOCKED_ACCESS_ISSUER}/issue`,
expect.objectContaining({
providedConsent: expect.objectContaining({
"https://example.org/ns/customField": [
"overridden custom value",
true,
1,
],
}),
}),
expect.anything(),
expect.anything(),
);
await expect(() =>
approveAccessRequest(
customRequest,
{
access: { append: true },
expirationDate: new Date(2021, 9, 14),
issuanceDate: new Date(2021, 9, 15),
purpose: ["https://some-custom.purpose"],
requestor: "https://some-custom.requestor",
resources: ["https://some-custom.resource"],
requestorInboxUrl: "https://some-custom.inbox",
customFields: new Set([
{
key: new URL("https://example.org/ns/customString"),
value: "overridden custom value",
},
{
key: new URL("https://example.org/ns/customString"),
value: "another custom value",
},
]),
},
{
fetch: jest.fn<typeof fetch>(),
},
),
).rejects.toThrow();
});

it("only overrides specified custom fields", async () => {
Expand Down
Loading

0 comments on commit 8d97f4a

Please sign in to comment.