From 3e894f59e573588c0608c95cc4e2d3465a7d08f3 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Thu, 13 Oct 2022 19:41:29 +0200 Subject: [PATCH] refactor: update "as" error messages --- src/index.ts | 28 ++++++++++++++-------------- test/authorization_code.test.ts | 4 ++-- test/client_credentials.test.ts | 2 +- test/device_flow.test.ts | 6 +++--- test/introspection.test.ts | 2 +- test/jarm.test.ts | 2 +- test/jwks.test.ts | 2 +- test/par.test.ts | 2 +- test/refresh_token.test.ts | 4 ++-- test/revocation.test.ts | 2 +- test/userinfo.test.ts | 4 ++-- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/index.ts b/src/index.ts index e72f3ca0..83054c26 100644 --- a/src/index.ts +++ b/src/index.ts @@ -710,7 +710,7 @@ export async function discoveryRequest( options?: DiscoveryRequestOptions, ): Promise { if (!(issuerIdentifier instanceof URL)) { - throw new TypeError('"issuer" must be an instance of URL') + throw new TypeError('"issuerIdentifier" must be an instance of URL') } if (issuerIdentifier.protocol !== 'https:' && issuerIdentifier.protocol !== 'http:') { @@ -1010,11 +1010,11 @@ async function privateKeyJwt( function assertIssuer(metadata: AuthorizationServer): metadata is AuthorizationServer { if (typeof metadata !== 'object' || metadata === null) { - throw new TypeError('"issuer" must be an object') + throw new TypeError('"as" must be an object') } if (!validateString(metadata.issuer)) { - throw new TypeError('"issuer.issuer" property must be a non-empty string') + throw new TypeError('"as.issuer" property must be a non-empty string') } return true } @@ -1267,7 +1267,7 @@ export async function pushedAuthorizationRequest( } if (typeof as.pushed_authorization_request_endpoint !== 'string') { - throw new TypeError('"issuer.pushed_authorization_request_endpoint" must be a string') + throw new TypeError('"as.pushed_authorization_request_endpoint" must be a string') } const url = new URL(as.pushed_authorization_request_endpoint) @@ -1542,7 +1542,7 @@ export async function userInfoRequest( assertClient(client) if (typeof as.userinfo_endpoint !== 'string') { - throw new TypeError('"issuer.userinfo_endpoint" must be a string') + throw new TypeError('"as.userinfo_endpoint" must be a string') } const url = new URL(as.userinfo_endpoint) @@ -1753,7 +1753,7 @@ export async function processUserInfoResponse( let json: JsonValue if (getContentType(response) === 'application/jwt') { if (typeof as.jwks_uri !== 'string') { - throw new TypeError('"issuer.jwks_uri" must be a string') + throw new TypeError('"as.jwks_uri" must be a string') } const { claims } = await validateJwt( @@ -1882,7 +1882,7 @@ async function tokenEndpointRequest( options?: Omit, ): Promise { if (typeof as.token_endpoint !== 'string') { - throw new TypeError('"issuer.token_endpoint" must be a string') + throw new TypeError('"as.token_endpoint" must be a string') } const url = new URL(as.token_endpoint) @@ -2036,7 +2036,7 @@ async function processGenericAccessTokenResponse( if (json.id_token) { if (typeof as.jwks_uri !== 'string') { - throw new TypeError('"issuer.jwks_uri" must be a string') + throw new TypeError('"as.jwks_uri" must be a string') } const { header, claims } = await validateJwt( @@ -2520,7 +2520,7 @@ export async function revocationRequest( } if (typeof as.revocation_endpoint !== 'string') { - throw new TypeError('"issuer.revocation_endpoint" must be a string') + throw new TypeError('"as.revocation_endpoint" must be a string') } const url = new URL(as.revocation_endpoint) @@ -2610,7 +2610,7 @@ export async function introspectionRequest( } if (typeof as.introspection_endpoint !== 'string') { - throw new TypeError('"issuer.introspection_endpoint" must be a string') + throw new TypeError('"as.introspection_endpoint" must be a string') } const url = new URL(as.introspection_endpoint) @@ -2689,7 +2689,7 @@ export async function processIntrospectionResponse( let json: JsonValue if (getContentType(response) === 'application/token-introspection+jwt') { if (typeof as.jwks_uri !== 'string') { - throw new TypeError('"issuer.jwks_uri" must be a string') + throw new TypeError('"as.jwks_uri" must be a string') } const { claims } = await validateJwt( @@ -2749,7 +2749,7 @@ export async function jwksRequest( assertIssuer(as) if (typeof as.jwks_uri !== 'string') { - throw new TypeError('"issuer.jwks_uri" must be a string') + throw new TypeError('"as.jwks_uri" must be a string') } const url = new URL(as.jwks_uri) @@ -3006,7 +3006,7 @@ export async function validateJwtAuthResponse( } if (typeof as.jwks_uri !== 'string') { - throw new TypeError('"issuer.jwks_uri" must be a string') + throw new TypeError('"as.jwks_uri" must be a string') } const { claims } = await validateJwt( @@ -3247,7 +3247,7 @@ export async function deviceAuthorizationRequest( } if (typeof as.device_authorization_endpoint !== 'string') { - throw new TypeError('"issuer.device_authorization_endpoint" must be a string') + throw new TypeError('"as.device_authorization_endpoint" must be a string') } const url = new URL(as.device_authorization_endpoint) diff --git a/test/authorization_code.test.ts b/test/authorization_code.test.ts index 2ee8b34e..0fcc50f5 100644 --- a/test/authorization_code.test.ts +++ b/test/authorization_code.test.ts @@ -60,7 +60,7 @@ test('authorizationCodeGrantRequest()', async (t) => { 'verifier', ), { - message: '"issuer.token_endpoint" must be a string', + message: '"as.token_endpoint" must be a string', }, ) @@ -408,7 +408,7 @@ test('processAuthorizationCodeOpenIDResponse() with an ID Token (alg signalled)' ), ), { - message: '"issuer.jwks_uri" must be a string', + message: '"as.jwks_uri" must be a string', }, ) diff --git a/test/client_credentials.test.ts b/test/client_credentials.test.ts index 4a10babb..9ac01c6e 100644 --- a/test/client_credentials.test.ts +++ b/test/client_credentials.test.ts @@ -19,7 +19,7 @@ const tClient: lib.Client = { ...client, client_secret: 'foo' } test('clientCredentialsGrantRequest()', async (t) => { await t.throwsAsync(lib.clientCredentialsGrantRequest(issuer, tClient, new URLSearchParams()), { - message: '"issuer.token_endpoint" must be a string', + message: '"as.token_endpoint" must be a string', }) const tIssuer: lib.AuthorizationServer = { diff --git a/test/device_flow.test.ts b/test/device_flow.test.ts index 52224d42..e76759d7 100644 --- a/test/device_flow.test.ts +++ b/test/device_flow.test.ts @@ -37,7 +37,7 @@ const tClient: lib.Client = { ...client, token_endpoint_auth_method: 'none' } test('deviceAuthorizationRequest()', async (t) => { await t.throwsAsync(lib.deviceAuthorizationRequest(issuer, tClient, new URLSearchParams()), { - message: '"issuer.device_authorization_endpoint" must be a string', + message: '"as.device_authorization_endpoint" must be a string', }) await t.throwsAsync(lib.deviceAuthorizationRequest(issuer, tClient, null), { @@ -233,7 +233,7 @@ test('processDeviceAuthorizationResponse()', async (t) => { test('deviceCodeGrantRequest()', async (t) => { await t.throwsAsync(lib.deviceCodeGrantRequest(issuer, tClient, 'device_code'), { - message: '"issuer.token_endpoint" must be a string', + message: '"as.token_endpoint" must be a string', }) await t.throwsAsync(lib.deviceCodeGrantRequest(issuer, tClient, null), { @@ -481,7 +481,7 @@ test('processDeviceCodeResponse() with an ID Token (alg signalled)', async (t) = ), ), { - message: '"issuer.jwks_uri" must be a string', + message: '"as.jwks_uri" must be a string', }, ) diff --git a/test/introspection.test.ts b/test/introspection.test.ts index 120e459d..64a47e97 100644 --- a/test/introspection.test.ts +++ b/test/introspection.test.ts @@ -66,7 +66,7 @@ const tClient: lib.Client = { ...client, client_secret: 'foo' } test('introspectionRequest()', async (t) => { await t.throwsAsync(lib.introspectionRequest(issuer, tClient, 'token'), { - message: '"issuer.introspection_endpoint" must be a string', + message: '"as.introspection_endpoint" must be a string', }) await t.throwsAsync(lib.introspectionRequest(issuer, tClient, null), { diff --git a/test/jarm.test.ts b/test/jarm.test.ts index 4ba94cd7..335cb2bd 100644 --- a/test/jarm.test.ts +++ b/test/jarm.test.ts @@ -43,7 +43,7 @@ test('validateJwtAuthResponse() error conditions', async (t) => { await t.throwsAsync( () => lib.validateJwtAuthResponse(issuer, client, new URLSearchParams('response=foo')), { - message: '"issuer.jwks_uri" must be a string', + message: '"as.jwks_uri" must be a string', }, ) }) diff --git a/test/jwks.test.ts b/test/jwks.test.ts index 5a28ce53..00f3c517 100644 --- a/test/jwks.test.ts +++ b/test/jwks.test.ts @@ -53,7 +53,7 @@ test('jwksRequest() w/ Custom Headers', async (t) => { test('jwksRequest() requires jwks_uri', async (t) => { await t.throwsAsync(lib.jwksRequest({ ...issuer, jwks_uri: undefined }), { name: 'TypeError', - message: '"issuer.jwks_uri" must be a string', + message: '"as.jwks_uri" must be a string', }) }) diff --git a/test/par.test.ts b/test/par.test.ts index dd90b012..45f2dc37 100644 --- a/test/par.test.ts +++ b/test/par.test.ts @@ -19,7 +19,7 @@ const tClient: lib.Client = { ...client, client_secret: 'foo' } test('pushedAuthorizationRequest()', async (t) => { await t.throwsAsync(lib.pushedAuthorizationRequest(issuer, tClient, new URLSearchParams()), { - message: '"issuer.pushed_authorization_request_endpoint" must be a string', + message: '"as.pushed_authorization_request_endpoint" must be a string', }) await t.throwsAsync(lib.pushedAuthorizationRequest(issuer, tClient, null), { diff --git a/test/refresh_token.test.ts b/test/refresh_token.test.ts index 30bc55af..a58f503c 100644 --- a/test/refresh_token.test.ts +++ b/test/refresh_token.test.ts @@ -37,7 +37,7 @@ const tClient: lib.Client = { ...client, client_secret: 'foo' } test('refreshTokenGrantRequest()', async (t) => { await t.throwsAsync(lib.refreshTokenGrantRequest(issuer, tClient, 'refresh_token'), { - message: '"issuer.token_endpoint" must be a string', + message: '"as.token_endpoint" must be a string', }) await t.throwsAsync(lib.refreshTokenGrantRequest(issuer, tClient, null), { @@ -287,7 +287,7 @@ test('processRefreshTokenResponse() with an ID Token (alg signalled)', async (t) ), ), { - message: '"issuer.jwks_uri" must be a string', + message: '"as.jwks_uri" must be a string', }, ) diff --git a/test/revocation.test.ts b/test/revocation.test.ts index d911c0f3..9b761ef0 100644 --- a/test/revocation.test.ts +++ b/test/revocation.test.ts @@ -19,7 +19,7 @@ const tClient: lib.Client = { ...client, client_secret: 'foo' } test('revocationRequest()', async (t) => { await t.throwsAsync(lib.revocationRequest(issuer, tClient, 'token'), { - message: '"issuer.revocation_endpoint" must be a string', + message: '"as.revocation_endpoint" must be a string', }) await t.throwsAsync(lib.revocationRequest(issuer, tClient, null), { diff --git a/test/userinfo.test.ts b/test/userinfo.test.ts index 353644e5..4af63d97 100644 --- a/test/userinfo.test.ts +++ b/test/userinfo.test.ts @@ -102,7 +102,7 @@ test('userInfoRequest() w/ jwt signal', async (t) => { test('userInfoRequest() requires userinfo_endpoint', async (t) => { await t.throwsAsync(lib.userInfoRequest(issuer, client, 'token'), { name: 'TypeError', - message: '"issuer.userinfo_endpoint" must be a string', + message: '"as.userinfo_endpoint" must be a string', }) }) @@ -189,7 +189,7 @@ test('processUserInfoResponse() - jwt (alg signalled)', async (t) => { getResponse('', { headers: new Headers({ 'content-type': 'application/jwt' }) }), ), { - message: '"issuer.jwks_uri" must be a string', + message: '"as.jwks_uri" must be a string', }, )