Skip to content

Commit 5dbb8a8

Browse files
committed
cleanup tests
1 parent 4d92019 commit 5dbb8a8

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

src/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ const scheme = joi.object({
1212
clientId: joi.string().min(1).required(),
1313
secret: joi.string().min(1),
1414
publicKey: joi.string().regex(/^-----BEGIN(?: RSA)? PUBLIC KEY-----[\s\S]*-----END(?: RSA)? PUBLIC KEY-----$/ig, 'PEM'),
15-
verifyOpts: joi.object().unknown(true),
15+
verifyOpts: joi.object({
16+
ignoreExpiration: joi.any().forbidden(),
17+
ignoreNotBefore: joi.any().forbidden()
18+
}).unknown(true),
1619
cache: joi.alternatives().try(joi.object({
1720
segment: joi.string().default('keycloakJwt')
1821
}), joi.boolean()).default(false),
1922
userInfo: joi.array().items(joi.string().min(1))
2023
})
2124
.xor('secret', 'publicKey')
2225
.without('secret', 'verifyOpts')
23-
.forbidden('verifyOpts.ignoreExpiration', 'verifyOpts.ignoreNotBefore')
2426
.required()
2527

2628
/**

test/_helpers.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ function mock (code, data, isError) {
4444
isError ? base.replyWithError(data) : base.reply(code, data)
4545
}
4646

47+
/**
48+
* @function
49+
* @public
50+
*
51+
* Log the option name with the asserted value.
52+
*
53+
* @param {string} option The name of the option
54+
* @param {*} value The value to be asserted
55+
* @returns {string} The aggregated log message
56+
*/
57+
function log (option, value) {
58+
return `${option}: ${value && value.toString()}`
59+
}
60+
4761
/**
4862
* @function
4963
* @private
@@ -144,7 +158,8 @@ function getServer (options, done) {
144158

145159
module.exports = {
146160
getOptions,
161+
mock,
162+
log,
147163
getServer,
148-
registerPlugin,
149-
mock
164+
registerPlugin
150165
}

test/utils.spec.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test('throw error if options are empty', (t) => {
4343
t.throws(() => utils.verify({}), Error)
4444
})
4545

46-
test('throw error if options are invalid – client.realmUrl', (t) => {
46+
test('throw error if options are invalid – realmUrl', (t) => {
4747
const invalids = [
4848
null,
4949
undefined,
@@ -63,11 +63,11 @@ test('throw error if options are invalid – client.realmUrl', (t) => {
6363
invalids.forEach((invalid) => {
6464
t.throws(() => utils.verify(helpers.getOptions({
6565
realmUrl: invalid
66-
})), Error)
66+
})), Error, helpers.log('realmUrl', invalid))
6767
})
6868
})
6969

70-
test('throw error if options are invalid – client.clientId', (t) => {
70+
test('throw error if options are invalid – clientId', (t) => {
7171
const invalids = [
7272
null,
7373
undefined,
@@ -86,11 +86,11 @@ test('throw error if options are invalid – client.clientId', (t) => {
8686
invalids.forEach((invalid) => {
8787
t.throws(() => utils.verify(helpers.getOptions({
8888
clientId: invalid
89-
})), Error)
89+
})), Error, helpers.log('clientId', invalid))
9090
})
9191
})
9292

93-
test('throw error if options are invalid – client.secret', (t) => {
93+
test('throw error if options are invalid – secret', (t) => {
9494
const invalids = [
9595
null,
9696
undefined,
@@ -109,7 +109,7 @@ test('throw error if options are invalid – client.secret', (t) => {
109109
invalids.forEach((invalid) => {
110110
t.throws(() => utils.verify(helpers.getOptions({
111111
secret: invalid
112-
})), Error)
112+
})), Error, helpers.log('secret', invalid))
113113
})
114114
})
115115

@@ -128,7 +128,7 @@ test('throw error if options are invalid – cache', (t) => {
128128
invalids.forEach((invalid) => {
129129
t.throws(() => utils.verify(helpers.getOptions({
130130
cache: invalid
131-
})), Error)
131+
})), Error, helpers.log('cache', invalid))
132132
})
133133
})
134134

@@ -160,7 +160,7 @@ test('throw error if options are invalid – userInfo', (t) => {
160160
invalids.forEach((invalid) => {
161161
t.throws(() => utils.verify(helpers.getOptions({
162162
userInfo: invalid
163-
})), Error)
163+
})), Error, helpers.log('userInfo', invalid))
164164
})
165165
})
166166

@@ -178,6 +178,8 @@ test('throw no error if options are valid', (t) => {
178178
t.plan(valids.length)
179179

180180
valids.forEach((valid) => {
181-
t.notThrows(() => utils.verify(helpers.getOptions(valid)), Error)
181+
t.notThrows(
182+
() => utils.verify(helpers.getOptions(valid)),
183+
Error, helpers.log('valid', valid))
182184
})
183185
})

0 commit comments

Comments
 (0)