Skip to content

Commit 0759b4d

Browse files
committed
Use nock to mock JWKS
1 parent 8e91532 commit 0759b4d

4 files changed

Lines changed: 127 additions & 0 deletions

File tree

jest.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
modulePathIgnorePatterns: ['<rootDir>/coverage/', '<rootDir>/.server/'],
2626
coverageDirectory: '<rootDir>/coverage',
2727
setupFiles: ['<rootDir>/jest.setup.js'],
28+
setupFilesAfterEnv: ['<rootDir>/jest.setup.after-env.js'],
2829
transform: {
2930
'^.+\\.(cjs|js|mjs)$': [
3031
'babel-jest',

jest.setup.after-env.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import nock from 'nock'
2+
3+
const jwksUri = process.env.OIDC_JWKS_URI
4+
const okStatusCode = 200
5+
6+
const testJwks = {
7+
keys: [
8+
{
9+
kty: 'RSA',
10+
use: 'sig',
11+
kid: 'test-jwks-key',
12+
alg: 'RS256',
13+
n: 'test-key-modulus',
14+
e: 'AQAB'
15+
}
16+
]
17+
}
18+
19+
if (jwksUri) {
20+
const { origin, pathname, search } = new URL(jwksUri)
21+
22+
nock.cleanAll()
23+
24+
nock(origin)
25+
.persist()
26+
.get(`${pathname}${search}`)
27+
.reply(okStatusCode, testJwks)
28+
}

package-lock.json

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"jest": "29.7.0",
8787
"lint-staged": "^16.1.2",
8888
"luxon": "^3.6.1",
89+
"nock": "14.0.11",
8990
"nunjucks": "3.2.4",
9091
"oidc-client-ts": "^3.2.1",
9192
"prettier": "^3.5.3",

0 commit comments

Comments
 (0)