Skip to content
This repository has been archived by the owner on Jan 8, 2021. It is now read-only.

Commit

Permalink
Feat: Check jwks_uri is a valid URL
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieubosquet committed Dec 27, 2020
1 parent 0b4ca95 commit 5e61dfe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-dpop",
"version": "0.3.0",
"version": "0.3.1",
"description": "Verifies Solid access tokens via their WebID claim, and thus asserts ownership of WebIDs.",
"license": "MIT",
"keywords": [
Expand Down
13 changes: 10 additions & 3 deletions src/lib/Issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ async function config(iss: URL): Promise<JSON> {
);
}

async function jwksUri(iss: URL): Promise<string> {
async function jwksUri(iss: URL): Promise<URL> {
const issuerConfig = await config(iss);

if (
isObjectPropertyOf(issuerConfig, "jwks_uri") &&
isString(issuerConfig.jwks_uri)
) {
return issuerConfig.jwks_uri;
try {
return new URL(issuerConfig.jwks_uri);
} catch (_) {
throw new SolidTokenVerifierError(
"SolidIdentityIssuerConfigError",
`Failed parsing jwks_uri from identity issuer configuration at URL ${iss.toString()} as a URL`
);
}
}

throw new SolidTokenVerifierError(
Expand All @@ -48,5 +55,5 @@ async function jwksUri(iss: URL): Promise<string> {
}

export const keySet: GetKeySetFunction = async function (iss: URL) {
return createRemoteJWKSet(new URL(await jwksUri(iss)));
return createRemoteJWKSet(await jwksUri(iss));
};
13 changes: 12 additions & 1 deletion test/Issuer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,18 @@ describe("Issuer key set", () => {
);
});

it("Throws when Issuer doesn't", async () => {
it("Throws when Issuer's JWKS URI is not a URL", async () => {
(crossFetch as jest.Mock).mockResolvedValueOnce({
ok: true,
json: () => ({ jwks_uri: "not_a_URI" }),
});

await expect(keySet(issuer)).rejects.toThrow(
"Failed parsing jwks_uri from identity issuer configuration at URL https://example-issuer.com/ as a URL"
);
});

it("Throws when Issuer config fetch fails", async () => {
(crossFetch as jest.Mock).mockResolvedValueOnce({
status: 400,
json: () => ({}),
Expand Down

0 comments on commit 5e61dfe

Please sign in to comment.