Skip to content

Commit

Permalink
refactor: update "as" error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Oct 13, 2022
1 parent 60b21e2 commit 3e894f5
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
28 changes: 14 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ export async function discoveryRequest(
options?: DiscoveryRequestOptions,
): Promise<Response> {
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:') {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1882,7 +1882,7 @@ async function tokenEndpointRequest(
options?: Omit<TokenEndpointRequestOptions, 'additionalParameters'>,
): Promise<Response> {
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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/authorization_code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
)

Expand Down Expand Up @@ -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',
},
)

Expand Down
2 changes: 1 addition & 1 deletion test/client_credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions test/device_flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, <any>null), {
Expand Down Expand Up @@ -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, <any>null), {
Expand Down Expand Up @@ -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',
},
)

Expand Down
2 changes: 1 addition & 1 deletion test/introspection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, <any>null), {
Expand Down
2 changes: 1 addition & 1 deletion test/jarm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
)
})
Expand Down
2 changes: 1 addition & 1 deletion test/jwks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/par.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, <any>null), {
Expand Down
4 changes: 2 additions & 2 deletions test/refresh_token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, <any>null), {
Expand Down Expand Up @@ -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',
},
)

Expand Down
2 changes: 1 addition & 1 deletion test/revocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, <any>null), {
Expand Down
4 changes: 2 additions & 2 deletions test/userinfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
})

Expand Down Expand Up @@ -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',
},
)

Expand Down

0 comments on commit 3e894f5

Please sign in to comment.