Skip to content

Commit

Permalink
WIP: testing against VC library doing parsing but no serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Nov 12, 2023
1 parent 219c180 commit 0e69c0c
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 81 deletions.
81 changes: 56 additions & 25 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
},
"dependencies": {
"@inrupt/solid-client": "^1.25.1",
"@inrupt/solid-client-vc": "^0.8.0-alpha.0",
"@inrupt/solid-client-vc": "file:../solid-client-vc-js",
"@inrupt/universal-fetch": "^1.0.1",
"@types/rdfjs__dataset": "^1.0.5",
"auth-header": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/common/getters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe("getAccessModes", () => {
const gConsentGrant = await mockGConsentGrant();
expect(
gConsentGrant.credentialSubject.providedConsent.mode,
).toStrictEqual(["Read"]);
).toStrictEqual(["http://www.w3.org/ns/auth/acl#Read"]);
expect(getAccessModes(gConsentGrant)).toStrictEqual({
read: true,
append: false,
Expand Down
15 changes: 11 additions & 4 deletions src/common/verify/isValidAccessGrant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import { jest, describe, it, expect } from "@jest/globals";
import { jest, describe, it, expect, beforeAll } from "@jest/globals";
import { Response } from "@inrupt/universal-fetch";
import type * as CrossFetch from "@inrupt/universal-fetch";
import {
isVerifiableCredential,
getVerifiableCredentialApiConfiguration,
verifiableCredentialToDataset

Check failure on line 28 in src/common/verify/isValidAccessGrant.test.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `,`
} from "@inrupt/solid-client-vc";

Check failure on line 29 in src/common/verify/isValidAccessGrant.test.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Unable to resolve path to module '@inrupt/solid-client-vc'

import type * as VcLibrary from "@inrupt/solid-client-vc";
Expand All @@ -40,11 +41,11 @@ jest.mock("@inrupt/solid-client", () => {
});

jest.mock("@inrupt/solid-client-vc", () => {
const { getVerifiableCredentialFromResponse } = jest.requireActual(
const { verifiableCredentialToDataset } = jest.requireActual(

Check warning on line 44 in src/common/verify/isValidAccessGrant.test.ts

View workflow job for this annotation

GitHub Actions / lint / lint

'verifiableCredentialToDataset' is already declared in the upper scope on line 28 column 3
"@inrupt/solid-client-vc",
) as jest.Mocked<typeof VcLibrary>;
return {
getVerifiableCredentialFromResponse,
verifiableCredentialToDataset,
isVerifiableCredential: jest.fn(),
issueVerifiableCredential: jest.fn(),
getVerifiableCredentialApiConfiguration: jest.fn(),
Expand All @@ -62,7 +63,7 @@ jest.mock("@inrupt/universal-fetch", () => {
});

describe("isValidAccessGrant", () => {
const MOCK_ACCESS_GRANT = {
const MOCK_ACCESS_GRANT_BASE = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://vc.inrupt.com/credentials/v1",
Expand Down Expand Up @@ -93,6 +94,12 @@ describe("isValidAccessGrant", () => {
const MOCK_ACCESS_ENDPOINT = "https://consent.example.com";
const MOCK_VERIFY_RESPONSE = { checks: [], warning: [], errors: [] };

let MOCK_ACCESS_GRANT: VcLibrary.VerifiableCredential

Check failure on line 97 in src/common/verify/isValidAccessGrant.test.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `;`

beforeAll(async () => {
MOCK_ACCESS_GRANT = await verifiableCredentialToDataset(MOCK_ACCESS_GRANT_BASE)

Check failure on line 100 in src/common/verify/isValidAccessGrant.test.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Replace `MOCK_ACCESS_GRANT_BASE)` with `⏎······MOCK_ACCESS_GRANT_BASE,⏎····);`
});

it("uses the provided fetch if any", async () => {
jest.mocked(isVerifiableCredential).mockReturnValueOnce(true);
const mockedFetch = jest
Expand Down
6 changes: 2 additions & 4 deletions src/gConsent/manage/approveAccessRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ jest.mock("@inrupt/solid-client", () => {
});

jest.mock("@inrupt/solid-client-vc", () => {
const { getVerifiableCredentialFromResponse } = jest.requireActual(
const { verifiableCredentialToDataset } = jest.requireActual(
"@inrupt/solid-client-vc",
) as jest.Mocked<typeof VcClient>;
return {
getVerifiableCredentialFromResponse,
verifiableCredentialToDataset,
issueVerifiableCredential: jest.fn(),
};
});
Expand Down Expand Up @@ -760,8 +760,6 @@ describe("approveAccessRequest", () => {
});

it("issues a proper access grant from a request VC using the deprecated signature", async () => {
// console.log('calling issue request with', accessRequestVc)

mockAcpClient();
mockAccessApiEndpoint();
const mockedVcModule = jest.requireMock(
Expand Down
4 changes: 2 additions & 2 deletions src/gConsent/manage/denyAccessRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ jest.mock("@inrupt/solid-client", () => {
});

jest.mock("@inrupt/solid-client-vc", () => {
const { getVerifiableCredentialFromResponse, isVerifiableCredential } =
const { verifiableCredentialToDataset, isVerifiableCredential } =
jest.requireActual("@inrupt/solid-client-vc") as jest.Mocked<
typeof VcLibrary
>;
return {
getVerifiableCredentialFromResponse,
verifiableCredentialToDataset,
isVerifiableCredential,
issueVerifiableCredential: jest.fn(),
};
Expand Down
20 changes: 2 additions & 18 deletions src/gConsent/manage/getAccessGrant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,7 @@ import { getAccessGrant } from "./getAccessGrant";
* problems
*/
function withoutDataset(data: any) {
return {
...data,
add: undefined,
match: undefined,
has: undefined,
[Symbol.iterator]: undefined,
delete: undefined,
};
return JSON.parse(JSON.stringify(data));
}

jest.mock("@inrupt/universal-fetch", () => {
Expand Down Expand Up @@ -140,16 +133,7 @@ describe("getAccessGrant", () => {
const accessGrant = await getAccessGrant("https://some.vc.url", {
fetch: mockedFetch,
});
expect(withoutDataset(accessGrant)).toEqual({
...withoutDataset(mockAccessGrant),
credentialSubject: {
...withoutDataset(mockAccessGrant).credentialSubject,
providedConsent: {
...withoutDataset(mockAccessGrant).credentialSubject.providedConsent,
hasStatus: "Consent:StatusDenied",
},
},
});
expect(withoutDataset(accessGrant)).toEqual(withoutDataset(mockedAccessGrant));

Check failure on line 136 in src/gConsent/manage/getAccessGrant.test.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Replace `withoutDataset(mockedAccessGrant)` with `⏎······withoutDataset(mockedAccessGrant),⏎····`
});

it("returns the access grant with the given IRI", async () => {
Expand Down
1 change: 0 additions & 1 deletion src/gConsent/manage/getAccessGrant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export async function getAccessGrant(
data = await getVerifiableCredentialFromResponse(
response,
accessGrantVcUrl.toString(),
{ fetch: sessionFetch, baseIRI: accessGrantVcUrl.toString() },
);
} catch (e) {
throw new Error(
Expand Down
4 changes: 2 additions & 2 deletions src/gConsent/manage/getAccessGrantAll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ import { mockAccessGrantVc } from "../util/access.mock";
const otherFetch = jest.fn(global.fetch);

jest.mock("@inrupt/solid-client-vc", () => {
const { getVerifiableCredentialFromResponse } = jest.requireActual(
const { verifiableCredentialToDataset } = jest.requireActual(
"@inrupt/solid-client-vc",
) as jest.Mocked<typeof VcLibrary>;
return {
getVerifiableCredentialFromResponse,
verifiableCredentialToDataset,
issueVerifiableCredential: jest.fn(),
getVerifiableCredentialAllFromShape: jest.fn(() =>
mockAccessGrantVc().then((res) => [res]),
Expand Down
4 changes: 2 additions & 2 deletions src/gConsent/manage/revokeAccessGrant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import { MOCKED_CREDENTIAL_ID } from "../request/request.mock";
import { mockAccessGrantVc, mockAccessRequestVc } from "../util/access.mock";

jest.mock("@inrupt/solid-client-vc", () => {
const { getVerifiableCredentialFromResponse } = jest.requireActual(
const { verifiableCredentialToDataset } = jest.requireActual(
"@inrupt/solid-client-vc",
) as jest.Mocked<typeof VcLibrary>;
return {
getVerifiableCredentialFromResponse,
verifiableCredentialToDataset,
issueVerifiableCredential: jest.fn(),
revokeVerifiableCredential: jest.fn(),
};
Expand Down
4 changes: 2 additions & 2 deletions src/gConsent/request/cancelAccessRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ jest.mock("@inrupt/solid-client", () => {
});

jest.mock("@inrupt/solid-client-vc", () => {
const { getVerifiableCredentialFromResponse } = jest.requireActual(
const { verifiableCredentialToDataset } = jest.requireActual(
"@inrupt/solid-client-vc",
) as jest.Mocked<typeof VcLibrary>;
return {
getVerifiableCredentialFromResponse,
verifiableCredentialToDataset,
issueVerifiableCredential: jest.fn(),
revokeVerifiableCredential: jest.fn(),
};
Expand Down
4 changes: 2 additions & 2 deletions src/gConsent/request/issueAccessRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ jest.mock("@inrupt/solid-client", () => {
return solidClientModule;
});
jest.mock("@inrupt/solid-client-vc", () => {
const { getVerifiableCredentialFromResponse } = jest.requireActual(
const { verifiableCredentialToDataset } = jest.requireActual(
"@inrupt/solid-client-vc",
) as jest.Mocked<typeof VcLibrary>;
return {
getVerifiableCredentialFromResponse,
verifiableCredentialToDataset,
issueVerifiableCredential: jest.fn(),
};
});
Expand Down
Loading

0 comments on commit 0e69c0c

Please sign in to comment.