Skip to content

Commit

Permalink
WIP: working towards all tests passing with VC parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Sep 25, 2023
1 parent 54bfacd commit ce76cd2
Show file tree
Hide file tree
Showing 25 changed files with 468 additions and 406 deletions.
12 changes: 6 additions & 6 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export default {
},
},
projects: [
{
...baseConfig,
displayName: "browser",
testEnvironment: "jsdom",
testPathIgnorePatterns: ["e2e", "node.test.ts"],
},
// {
// ...baseConfig,
// displayName: "browser",
// testEnvironment: "jsdom",
// testPathIgnorePatterns: ["e2e", "node.test.ts"],
// },
{
...baseConfig,
displayName: "node",
Expand Down
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"@inrupt/solid-client-authn-browser": "^1.12.2",
"@inrupt/solid-client-authn-node": "^1.12.1",
"@playwright/test": "^1.34.3",
"@rdfjs/types": "^1.1.0",
"@rushstack/eslint-patch": "^1.1.4",
"@types/auth-header": "^1.0.2",
"@types/dotenv-flow": "^3.1.0",
Expand Down
20 changes: 11 additions & 9 deletions src/common/getters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ describe("getResourceOwner", () => {
});

it("returns undefined if the resource owner is absent from a gConsent access request", async () => {
const gConsentRequest = await mockGConsentRequest({
resourceOwner: null,
});
const gConsentRequest = await mockGConsentRequest(
{
resourceOwner: null,
},
{
// The resource owner is actually required on access requests
skipValidation: true,
},
);
expect(getResourceOwner(gConsentRequest)).toBeUndefined();
});
});
Expand Down Expand Up @@ -137,7 +143,7 @@ describe("getAccessModes", () => {
const gConsentGrant = await mockGConsentGrant();
expect(
gConsentGrant.credentialSubject.providedConsent.mode,
).toStrictEqual(["http://www.w3.org/ns/auth/acl#Read"]);
).toStrictEqual(["Read"]);
expect(getAccessModes(gConsentGrant)).toStrictEqual({
read: true,
append: false,
Expand All @@ -147,11 +153,7 @@ describe("getAccessModes", () => {

it("gets the access modes from a gConsent access request", async () => {
const gConsentRequest = await mockGConsentRequest({
modes: [
"http://www.w3.org/ns/auth/acl#Append",
"http://www.w3.org/ns/auth/acl#Read",
"http://www.w3.org/ns/auth/acl#Write",
],
modes: ["Append", "Read", "Write"],
});
expect(getAccessModes(gConsentRequest)).toStrictEqual({
read: true,
Expand Down
14 changes: 13 additions & 1 deletion src/common/verify/isValidAccessGrant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getVerifiableCredentialApiConfiguration,
} from "@inrupt/solid-client-vc";

import type * as VcLibrary from "@inrupt/solid-client-vc";
import { isValidAccessGrant } from "./isValidAccessGrant";

jest.mock("@inrupt/solid-client", () => {
Expand All @@ -37,7 +38,18 @@ jest.mock("@inrupt/solid-client", () => {
solidClientModule.getWellKnownSolid = jest.fn();
return solidClientModule;
});
jest.mock("@inrupt/solid-client-vc");

jest.mock("@inrupt/solid-client-vc", () => {
const { getVerifiableCredentialFromResponse } = jest.requireActual(
"@inrupt/solid-client-vc",
) as jest.Mocked<typeof VcLibrary>;
return {
getVerifiableCredentialFromResponse,
isVerifiableCredential: jest.fn(),
issueVerifiableCredential: jest.fn(),
getVerifiableCredentialApiConfiguration: jest.fn(),
};
});
jest.mock("@inrupt/universal-fetch", () => {
const crossFetch = jest.requireActual(
"@inrupt/universal-fetch",
Expand Down
7 changes: 4 additions & 3 deletions src/gConsent/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,19 @@ const extraContext = [
export const ACCESS_GRANT_CONTEXT_DEFAULT = [
CONTEXT_VC_W3C,
CONTEXT_ESS_DEFAULT,
...extraContext,
// instanciateContextVcEssTemplate("vc.inrupt.com"),
instanciateContextVcEssTemplate("vc.inrupt.com"),
] as const;

export const MOCK_CONTEXT = [...ACCESS_GRANT_CONTEXT_DEFAULT, ...extraContext];

// When issuing a VC using a given service,"https://schema.inrupt.com/credentials/v1.jsonld" be sure to set the context using the following.
export const instanciateEssAccessGrantContext = (
essVcDomain: string,
): typeof ACCESS_GRANT_CONTEXT_DEFAULT =>
[
CONTEXT_VC_W3C,
CONTEXT_ESS_DEFAULT,
// instanciateContextVcEssTemplate(essVcDomain),
instanciateContextVcEssTemplate(essVcDomain),
] as const;

export const WELL_KNOWN_SOLID = ".well-known/solid";
Expand Down
Loading

0 comments on commit ce76cd2

Please sign in to comment.