Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
createJsWithTsPreset,
type JestConfigWithTsJest,
} from "ts-jest";
import { join } from "node:path";

// Jest 30 loads .ts config files as ESM via Node's native TypeScript support,
// so `require` is not available. Use createRequire for require.resolve calls.
Expand All @@ -40,11 +41,20 @@ const baseConfig: ArrayElement<NonNullable<Config["projects"]>> = {
...defaultPreset,
roots: ["<rootDir>"],
testMatch: ["**/*.spec.ts"],
modulePathIgnorePatterns: ["dist/", "<rootDir>/examples/"],
modulePathIgnorePatterns: ["dist", join("<rootDir>", "examples")],
coveragePathIgnorePatterns: [".*.spec.ts", "dist/"],
clearMocks: true,
injectGlobals: false,
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
setupFilesAfterEnv: [join("<rootDir>", "jest.setup.ts")],
transform: {
...defaultPreset.transform,
// [\\\\/] expands to [\\/], which makes the regex Windows-compatible.
"node_modules[\\\\/]jose.+\\.js$": [
"ts-jest",
{ tsconfig: { allowJs: true } },
],
},
transformIgnorePatterns: ["node_modules[\\\\/](?!jose)"],
moduleNameMapper: {
"^jose": esmRequire.resolve("jose"),
},
Expand Down
49 changes: 16 additions & 33 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 packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@inrupt/oidc-client-ext": "^4.0.0",
"@inrupt/solid-client-authn-core": "^4.0.0",
"events": "^3.3.0",
"jose": "^5.1.3",
"jose": "^6.2.3",
"uuid": "^11.1.0"
},
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ import {
} from "@inrupt/solid-client-authn-core/mocks";
import { jest, it, describe, expect } from "@jest/globals";
import type * as OidcClientExt from "@inrupt/oidc-client-ext";
import type { JWK } from "jose";
import type { JWK, CryptoKey } from "jose";
import { importJWK } from "jose";
import type { KeyObject } from "crypto";
import { AuthCodeRedirectHandler } from "./AuthCodeRedirectHandler";
import { SessionInfoManagerMock } from "../../../sessionInfo/__mocks__/SessionInfoManager";
import { LocalStorageMock } from "../../../storage/__mocks__/LocalStorage";
Expand Down Expand Up @@ -126,7 +125,7 @@ const mockTokenEndpointDpopResponse =
webId: mockWebId(),
clientId: "some client",
dpopKey: {
privateKey: (await importJWK(mockJwk())) as KeyObject,
privateKey: (await importJWK(mockJwk())) as CryptoKey,
// Note that here for convenience the private key is also used as public key.
// Obviously, this should never be done in non-test code.
publicKey: mockJwk(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ import {
mockStorageUtility,
// eslint-disable-next-line import/no-unresolved
} from "@inrupt/solid-client-authn-core/mocks";
import type { JWK } from "jose";
import type { JWK, CryptoKey } from "jose";
import { importJWK } from "jose";
import type { refresh } from "@inrupt/oidc-client-ext";
import { EventEmitter } from "events";
import type { KeyObject } from "crypto";
import TokenRefresher from "./TokenRefresher";
import {
mockDefaultIssuerConfigFetcher,
Expand Down Expand Up @@ -70,7 +69,7 @@ const mockJwk = (): JWK => {

const mockKeyPair = async (): Promise<KeyPair> => {
return {
privateKey: (await importJWK(mockJwk())) as KeyObject,
privateKey: (await importJWK(mockJwk())) as CryptoKey,
// Use the same JWK for public and private key out of convenience, don't do
// this in real life.
publicKey: mockJwk(),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"events": "^3.3.0",
"jose": "^5.1.3",
"jose": "^6.2.3",
"uuid": "^11.1.0"
},
"publishConfig": {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/authenticatedFetch/dpopUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
//

import { it, describe, expect } from "@jest/globals";
import type { KeyLike } from "jose";
import type { CryptoKey } from "jose";
import { generateKeyPair, exportJWK, jwtVerify } from "jose";
import { createDpopHeader, generateDpopKeyPair } from "./dpopUtils";

let publicKey: KeyLike | undefined;
let privateKey: KeyLike | undefined;
let publicKey: CryptoKey | undefined;
let privateKey: CryptoKey | undefined;

const mockJwk = async (): Promise<{
publicKey: KeyLike;
privateKey: KeyLike;
publicKey: CryptoKey;
privateKey: CryptoKey;
}> => {
if (typeof publicKey === "undefined" || typeof privateKey === "undefined") {
const generatedPair = await generateKeyPair("ES256");
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/authenticatedFetch/dpopUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import type { JWK, KeyLike } from "jose";
import type { JWK, CryptoKey } from "jose";
import { SignJWT, generateKeyPair, exportJWK } from "jose";
import { v4 } from "uuid";
import { PREFERRED_SIGNING_ALG } from "../constant";
Expand All @@ -36,7 +36,7 @@ function normalizeHTU(audience: string): string {
}

export type KeyPair = {
privateKey: KeyLike;
privateKey: CryptoKey;
publicKey: JWK;
};

Expand Down
18 changes: 10 additions & 8 deletions packages/core/src/authenticatedFetch/fetchFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/* eslint-disable no-shadow */

import { jest, it, describe, expect, afterEach } from "@jest/globals";
import type { KeyLike } from "jose";
import type { CryptoKey } from "jose";
import { jwtVerify, generateKeyPair, exportJWK } from "jose";
import { EventEmitter } from "events";
import {
Expand Down Expand Up @@ -55,15 +55,17 @@ const mockNotRedirectedResponse = () => {
return mockedResponse;
};

let publicKey: KeyLike | undefined;
let privateKey: KeyLike | undefined;
let publicKey: CryptoKey | undefined;
let privateKey: CryptoKey | undefined;

const mockJwk = async (): Promise<{
publicKey: KeyLike;
privateKey: KeyLike;
publicKey: CryptoKey;
privateKey: CryptoKey;
}> => {
if (typeof publicKey === "undefined" || typeof privateKey === "undefined") {
const generatedPair = await generateKeyPair("ES256");
const generatedPair = await generateKeyPair("ES256", {
extractable: true,
});
publicKey = generatedPair.publicKey;
privateKey = generatedPair.privateKey;
}
Expand Down Expand Up @@ -159,7 +161,7 @@ describe("buildAuthenticatedFetch", () => {
const headers = new Headers(mockedFetch.mock.calls[0][1]?.headers);
const { payload } = await jwtVerify(
headers.get("DPoP") as string,
(await mockKeyPair()).privateKey,
(await mockJwk()).publicKey,
);
expect(payload.htu).toBe("http://some.url/");
expect(payload.htm).toBe("POST");
Expand Down Expand Up @@ -198,7 +200,7 @@ describe("buildAuthenticatedFetch", () => {
const headers = new Headers(mockedFetch.mock.calls[1][1]?.headers);
const { payload } = await jwtVerify(
headers.get("DPoP") as string,
(await mockKeyPair()).privateKey,
(await mockJwk()).publicKey,
);
expect(payload.htu).toBe("https://my.pod/container/");
});
Expand Down
14 changes: 8 additions & 6 deletions packages/core/src/storage/StorageUtility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

import type { KeyLike } from "jose";
import type { CryptoKey } from "jose";
import { exportJWK, generateKeyPair } from "jose";
import { jest, describe, it, expect } from "@jest/globals";
import { mockIssuerConfig } from "../login/oidc/__mocks__/IssuerConfig";
Expand Down Expand Up @@ -531,15 +531,17 @@ describe("saveSessionInfoToStorage", () => {
).resolves.toBe("true");
});

let publicKey: KeyLike | undefined;
let privateKey: KeyLike | undefined;
let publicKey: CryptoKey | undefined;
let privateKey: CryptoKey | undefined;

const mockJwk = async (): Promise<{
publicKey: KeyLike;
privateKey: KeyLike;
publicKey: CryptoKey;
privateKey: CryptoKey;
}> => {
if (typeof publicKey === "undefined" || typeof privateKey === "undefined") {
const generatedPair = await generateKeyPair("ES256");
const generatedPair = await generateKeyPair("ES256", {
extractable: true,
});
publicKey = generatedPair.publicKey;
privateKey = generatedPair.privateKey;
}
Expand Down
Loading
Loading