Skip to content

Commit

Permalink
refactor: more descriptive "not a conform" message
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Nov 15, 2024
1 parent ec7a309 commit 0295887
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 18 deletions.
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ export async function processDiscoveryResponse(

if (response.status !== 200) {
throw OPE(
'"response" is not a conform Authorization Server Metadata response',
'"response" is not a conform Authorization Server Metadata response (unexpected HTTP status code)',
RESPONSE_IS_NOT_CONFORM,
response,
)
Expand Down Expand Up @@ -2572,7 +2572,7 @@ export async function processPushedAuthorizationResponse(
})
}
throw OPE(
'"response" is not a conform Pushed Authorization Request Endpoint response',
'"response" is not a conform Pushed Authorization Request Endpoint response (unexpected HTTP status code)',
RESPONSE_IS_NOT_CONFORM,
response,
)
Expand Down Expand Up @@ -3015,7 +3015,7 @@ export async function processUserInfoResponse(

if (response.status !== 200) {
throw OPE(
'"response" is not a conform UserInfo Endpoint response',
'"response" is not a conform UserInfo Endpoint response (unexpected HTTP status code)',
RESPONSE_IS_NOT_CONFORM,
response,
)
Expand Down Expand Up @@ -3301,7 +3301,7 @@ async function processGenericAccessTokenResponse(
})
}
throw OPE(
'"response" is not a conform Token Endpoint response',
'"response" is not a conform Token Endpoint response (unexpected HTTP status code)',
RESPONSE_IS_NOT_CONFORM,
response,
)
Expand Down Expand Up @@ -4215,7 +4215,7 @@ export async function processRevocationResponse(response: Response): Promise<und
})
}
throw OPE(
'"response" is not a conform Revocation Endpoint response',
'"response" is not a conform Revocation Endpoint response (unexpected HTTP status code)',
RESPONSE_IS_NOT_CONFORM,
response,
)
Expand Down Expand Up @@ -4368,7 +4368,7 @@ export async function processIntrospectionResponse(
})
}
throw OPE(
'"response" is not a conform Introspection Endpoint response',
'"response" is not a conform Introspection Endpoint response (unexpected HTTP status code)',
RESPONSE_IS_NOT_CONFORM,
response,
)
Expand Down Expand Up @@ -4455,7 +4455,7 @@ async function processJwksResponse(response: Response): Promise<JWKS> {

if (response.status !== 200) {
throw OPE(
'"response" is not a conform JSON Web Key Set response',
'"response" is not a conform JSON Web Key Set response (unexpected HTTP status code)',
RESPONSE_IS_NOT_CONFORM,
response,
)
Expand Down Expand Up @@ -5490,7 +5490,7 @@ export async function processDeviceAuthorizationResponse(
})
}
throw OPE(
'"response" is not a conform Device Authorization Endpoint response',
'"response" is not a conform Device Authorization Endpoint response (unexpected HTTP status code)',
RESPONSE_IS_NOT_CONFORM,
response,
)
Expand Down
2 changes: 1 addition & 1 deletion test/authorization_code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ test('processAuthorizationCodeResponse()', async (t) => {
await t.throwsAsync(
lib.processAuthorizationCodeResponse(issuer, client, getResponse('', { status: 404 })),
{
message: '"response" is not a conform Token Endpoint response',
message: '"response" is not a conform Token Endpoint response (unexpected HTTP status code)',
},
)
await t.throwsAsync(lib.processAuthorizationCodeResponse(issuer, client, getResponse('{"')), {
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 @@ -178,7 +178,7 @@ test('processClientCredentialsResponse()', async (t) => {
await t.throwsAsync(
lib.processClientCredentialsResponse(issuer, client, getResponse('', { status: 404 })),
{
message: '"response" is not a conform Token Endpoint response',
message: '"response" is not a conform Token Endpoint response (unexpected HTTP status code)',
},
)
await t.throwsAsync(lib.processClientCredentialsResponse(issuer, client, getResponse('{"')), {
Expand Down
5 changes: 3 additions & 2 deletions test/device_flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ test('processDeviceAuthorizationResponse()', async (t) => {
await t.throwsAsync(
lib.processDeviceAuthorizationResponse(issuer, client, getResponse('', { status: 404 })),
{
message: '"response" is not a conform Device Authorization Endpoint response',
message:
'"response" is not a conform Device Authorization Endpoint response (unexpected HTTP status code)',
},
)
await t.throwsAsync(
Expand Down Expand Up @@ -384,7 +385,7 @@ test('processDeviceCodeResponse() without ID Tokens', async (t) => {
await t.throwsAsync(
lib.processDeviceCodeResponse(issuer, client, getResponse('', { status: 404 })),
{
message: '"response" is not a conform Token Endpoint response',
message: '"response" is not a conform Token Endpoint response (unexpected HTTP status code)',
},
)
await t.throwsAsync(lib.processDeviceCodeResponse(issuer, client, getResponse('{"')), {
Expand Down
3 changes: 2 additions & 1 deletion test/discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ test('processDiscoveryResponse()', async (t) => {
message: '"expectedIssuer" must be an instance of URL',
})
await t.throwsAsync(lib.processDiscoveryResponse(expected, getResponse('', { status: 404 })), {
message: '"response" is not a conform Authorization Server Metadata response',
message:
'"response" is not a conform Authorization Server Metadata response (unexpected HTTP status code)',
})
await t.throwsAsync(lib.processDiscoveryResponse(expected, getResponse('{"')), {
message: 'failed to parse "response" body as JSON',
Expand Down
3 changes: 2 additions & 1 deletion test/introspection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ test('processIntrospectionResponse()', async (t) => {
await t.throwsAsync(
lib.processIntrospectionResponse(issuer, client, getResponse('', { status: 404 })),
{
message: '"response" is not a conform Introspection Endpoint response',
message:
'"response" is not a conform Introspection Endpoint response (unexpected HTTP status code)',
},
)
await t.throwsAsync(lib.processIntrospectionResponse(issuer, client, getResponse('{"')), {
Expand Down
3 changes: 2 additions & 1 deletion test/par.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ test('processPushedAuthorizationResponse()', async (t) => {
await t.throwsAsync(
lib.processPushedAuthorizationResponse(issuer, client, getResponse('', { status: 404 })),
{
message: '"response" is not a conform Pushed Authorization Request Endpoint response',
message:
'"response" is not a conform Pushed Authorization Request Endpoint response (unexpected HTTP status code)',
},
)
await t.throwsAsync(
Expand Down
2 changes: 1 addition & 1 deletion test/refresh_token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ test('processRefreshTokenResponse() without ID Tokens', async (t) => {
await t.throwsAsync(
lib.processRefreshTokenResponse(issuer, client, getResponse('', { status: 404 })),
{
message: '"response" is not a conform Token Endpoint response',
message: '"response" is not a conform Token Endpoint response (unexpected HTTP status code)',
},
)
await t.throwsAsync(lib.processRefreshTokenResponse(issuer, client, getResponse('{"')), {
Expand Down
3 changes: 2 additions & 1 deletion test/revocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ test('processRevocationResponse()', async (t) => {
message: '"response" must be an instance of Response',
})
await t.throwsAsync(lib.processRevocationResponse(getResponse('', { status: 404 })), {
message: '"response" is not a conform Revocation Endpoint response',
message:
'"response" is not a conform Revocation Endpoint response (unexpected HTTP status code)',
})

t.is(await lib.processRevocationResponse(getResponse('')), undefined)
Expand Down
3 changes: 2 additions & 1 deletion test/userinfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ test('processUserInfoResponse() - json', async (t) => {
getResponse(JSON.stringify({ sub: 'urn:example:subject' }), { status: 404 }),
),
{
message: '"response" is not a conform UserInfo Endpoint response',
message:
'"response" is not a conform UserInfo Endpoint response (unexpected HTTP status code)',
},
)
await t.throwsAsync(
Expand Down

0 comments on commit 0295887

Please sign in to comment.