mirror of
https://github.com/hanzoai/openid-client.git
synced 2026-09-24 17:01:10 +00:00
test: refactor expected error names and causes
This commit is contained in:
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_DECRYPTION_FAILED' },
|
||||
{ code: 'ERR_JOSE_ALG_NOT_ALLOWED' },
|
||||
{ code: 'ERR_JOSE_ALG_NOT_ALLOWED', name: 'JOSEAlgNotAllowed' },
|
||||
)
|
||||
|
||||
+1
-1
@@ -3,6 +3,6 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"state"/ },
|
||||
{ message: /"state"/ },
|
||||
{ useState: true },
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"state"/ },
|
||||
{ message: /"state"/ },
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: 'unexpected JWT "alg" header parameter',
|
||||
},
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_JWT_TIMESTAMP_CHECK_FAILED' },
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: /"exp"/,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -6,7 +6,6 @@ rejects(
|
||||
code: 'OAUTH_INVALID_RESPONSE',
|
||||
},
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: /signature/,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: /"aud"/,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: /"exp"/,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: /"iss"/,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_JWT_TIMESTAMP_CHECK_FAILED' },
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: /"iat"/,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: 'unexpected JWT "alg" header parameter',
|
||||
},
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"iss"/ },
|
||||
{ message: /"iss"/ },
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_JWT_CLAIM_COMPARISON_FAILED' },
|
||||
{ name: 'OperationProcessingError', message: /"c_hash"/ },
|
||||
{ message: /"c_hash"/ },
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_JWT_TIMESTAMP_CHECK_FAILED' },
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: /"exp"/,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"aud"/ },
|
||||
{ message: /"aud"/ },
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"exp"/ },
|
||||
{ message: /"exp"/ },
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"iss"/ },
|
||||
{ message: /"iss"/ },
|
||||
)
|
||||
|
||||
@@ -3,6 +3,6 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"nonce"/ },
|
||||
{ message: /"nonce"/ },
|
||||
{ useNonce: true },
|
||||
)
|
||||
|
||||
@@ -3,6 +3,6 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"s_hash"/ },
|
||||
{ message: /"s_hash"/ },
|
||||
{ useState: true },
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_JWT_CLAIM_COMPARISON_FAILED' },
|
||||
{ name: 'OperationProcessingError', message: /"nonce"/ },
|
||||
{ message: /"nonce"/ },
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: 'unexpected JWT "alg" header parameter',
|
||||
},
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_JWT_CLAIM_COMPARISON_FAILED' },
|
||||
{ name: 'OperationProcessingError', message: /"aud"/ },
|
||||
{ message: /"aud"/ },
|
||||
)
|
||||
|
||||
@@ -3,6 +3,6 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_JWT_CLAIM_COMPARISON_FAILED' },
|
||||
{ name: 'OperationProcessingError', message: /"s_hash"/ },
|
||||
{ message: /"s_hash"/ },
|
||||
{ useState: true },
|
||||
)
|
||||
|
||||
@@ -6,7 +6,6 @@ if (nonRepudiation(plan)) {
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: /signature/,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -5,12 +5,7 @@ for (const module of modules(import.meta.url)) {
|
||||
module.variant?.response_type?.includes('id_token') === true ||
|
||||
variant.response_type?.includes('id_token') === true
|
||||
) {
|
||||
test.serial(
|
||||
rejects(flow()),
|
||||
module,
|
||||
{ name: 'ClientError' },
|
||||
{ name: 'OperationProcessingError' },
|
||||
)
|
||||
test.serial(rejects(flow()), module, { code: 'OAUTH_KEY_SELECTION_FAILED' })
|
||||
} else {
|
||||
test.serial(flow(), module)
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"aud"/ },
|
||||
{ message: /"aud"/ },
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"c_hash"/ },
|
||||
{ message: /"c_hash"/ },
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"iat"/ },
|
||||
{ message: /"iat"/ },
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{ name: 'OperationProcessingError', message: /"sub"/ },
|
||||
{ message: /"sub"/ },
|
||||
)
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_JWT_CLAIM_COMPARISON_FAILED' },
|
||||
{ name: 'OperationProcessingError', message: /"nonce"/ },
|
||||
{ message: /"nonce"/ },
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_INVALID_RESPONSE' },
|
||||
{
|
||||
name: 'OperationProcessingError',
|
||||
message: /"iss"/,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -14,8 +14,8 @@ export function skippable(metaUrl: string, options?: runner.MacroOptions) {
|
||||
|
||||
export function rejects(
|
||||
metaUrl: string,
|
||||
expected: runner.CodeErrorAssertion | runner.NameErrorAssertion,
|
||||
cause?: runner.CodeErrorAssertion | runner.NameErrorAssertion,
|
||||
expected: runner.CodeErrorAssertion | runner.MessageErrorAssertion,
|
||||
cause?: runner.CodeErrorAssertion | runner.MessageErrorAssertion,
|
||||
options?: runner.MacroOptions,
|
||||
) {
|
||||
for (const module of runner.modules(metaUrl)) {
|
||||
|
||||
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
|
||||
rejects(
|
||||
import.meta.url,
|
||||
{ code: 'OAUTH_JSON_ATTRIBUTE_COMPARISON_FAILED' },
|
||||
{ name: 'OperationProcessingError', message: /"sub"/ },
|
||||
{ message: /"sub"/ },
|
||||
)
|
||||
|
||||
@@ -491,6 +491,8 @@ export type CodeErrorAssertion = Partial<ErrorAssertion> &
|
||||
Pick<ErrorAssertion, 'code'>
|
||||
export type NameErrorAssertion = Partial<ErrorAssertion> &
|
||||
Pick<ErrorAssertion, 'name'>
|
||||
export type MessageErrorAssertion = Partial<ErrorAssertion> &
|
||||
Pick<ErrorAssertion, 'message'>
|
||||
|
||||
function assertError(
|
||||
t: ExecutionContext,
|
||||
@@ -520,17 +522,19 @@ export const rejects = (
|
||||
async exec(
|
||||
t,
|
||||
module: ModulePrescription,
|
||||
expected: CodeErrorAssertion | NameErrorAssertion,
|
||||
cause?: CodeErrorAssertion | NameErrorAssertion,
|
||||
expected: CodeErrorAssertion | MessageErrorAssertion,
|
||||
cause?: CodeErrorAssertion | MessageErrorAssertion,
|
||||
) {
|
||||
const err = await t.throwsAsync(
|
||||
() => macro.exec(t, { ...module, skipLogTestFinished: true }) as any,
|
||||
)
|
||||
t.log('rejected with', inspect(err, { depth: Infinity }))
|
||||
|
||||
expected.name ||= 'ClientError'
|
||||
assertError(t, err, expected)
|
||||
|
||||
if (cause) {
|
||||
cause.name ||= 'OperationProcessingError'
|
||||
if (!(err.cause instanceof Error)) {
|
||||
t.fail('expected and Error instance')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user