test: refactor expected error names and causes

This commit is contained in:
Filip Skokan
2024-10-17 18:04:55 +02:00
parent a821075076
commit 941824c1d9
34 changed files with 28 additions and 41 deletions
@@ -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' },
)
@@ -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"/ },
)
+1 -1
View File
@@ -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"/,
},
)
+1 -1
View File
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
rejects(
import.meta.url,
{ code: 'OAUTH_INVALID_RESPONSE' },
{ name: 'OperationProcessingError', message: /"aud"/ },
{ message: /"aud"/ },
)
+1 -1
View File
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
rejects(
import.meta.url,
{ code: 'OAUTH_INVALID_RESPONSE' },
{ name: 'OperationProcessingError', message: /"exp"/ },
{ message: /"exp"/ },
)
+1 -1
View File
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
rejects(
import.meta.url,
{ code: 'OAUTH_INVALID_RESPONSE' },
{ name: 'OperationProcessingError', message: /"iss"/ },
{ message: /"iss"/ },
)
+1 -1
View File
@@ -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 },
)
+1 -1
View File
@@ -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 },
)
+1 -1
View File
@@ -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"/ },
)
-1
View File
@@ -4,7 +4,6 @@ rejects(
import.meta.url,
{ code: 'OAUTH_INVALID_RESPONSE' },
{
name: 'OperationProcessingError',
message: 'unexpected JWT "alg" header parameter',
},
)
+1 -1
View File
@@ -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"/ },
)
+1 -1
View File
@@ -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 },
)
-1
View File
@@ -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)
}
+1 -1
View File
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
rejects(
import.meta.url,
{ code: 'OAUTH_INVALID_RESPONSE' },
{ name: 'OperationProcessingError', message: /"aud"/ },
{ message: /"aud"/ },
)
+1 -1
View File
@@ -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"/ },
)
+1 -1
View File
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
rejects(
import.meta.url,
{ code: 'OAUTH_INVALID_RESPONSE' },
{ name: 'OperationProcessingError', message: /"iat"/ },
{ message: /"iat"/ },
)
+1 -1
View File
@@ -3,5 +3,5 @@ import { rejects } from './run.js'
rejects(
import.meta.url,
{ code: 'OAUTH_INVALID_RESPONSE' },
{ name: 'OperationProcessingError', message: /"sub"/ },
{ message: /"sub"/ },
)
+1 -1
View File
@@ -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"/,
},
)
+2 -2
View File
@@ -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)) {
+1 -1
View File
@@ -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"/ },
)
+6 -2
View File
@@ -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')
}