mirror of
https://github.com/danbulant/jose
synced 2026-05-24 12:35:36 +00:00
test: add all syntaxes to jwks tests
This commit is contained in:
parent
7c70e7b970
commit
0f8a9b5153
1 changed files with 53 additions and 1 deletions
|
|
@ -16,7 +16,16 @@ if ('WEBCRYPTO' in process.env) {
|
||||||
root = keyRoot = '#dist'
|
root = keyRoot = '#dist'
|
||||||
}
|
}
|
||||||
|
|
||||||
const { jwtVerify, SignJWT } = await import(root)
|
const {
|
||||||
|
jwtVerify,
|
||||||
|
SignJWT,
|
||||||
|
FlattenedSign,
|
||||||
|
flattenedVerify,
|
||||||
|
GeneralSign,
|
||||||
|
generalVerify,
|
||||||
|
CompactSign,
|
||||||
|
compactVerify,
|
||||||
|
} = await import(root)
|
||||||
const { importJWK, createRemoteJWKSet } = await import(keyRoot)
|
const { importJWK, createRemoteJWKSet } = await import(keyRoot)
|
||||||
|
|
||||||
const now = 1604416038
|
const now = 1604416038
|
||||||
|
|
@ -124,6 +133,7 @@ test.serial('RemoteJWKSet', async (t) => {
|
||||||
nock('https://as.example.com').get('/jwks').reply(200, jwks)
|
nock('https://as.example.com').get('/jwks').reply(200, jwks)
|
||||||
const url = new URL('https://as.example.com/jwks')
|
const url = new URL('https://as.example.com/jwks')
|
||||||
const JWKS = createRemoteJWKSet(url)
|
const JWKS = createRemoteJWKSet(url)
|
||||||
|
// Signed JWT
|
||||||
{
|
{
|
||||||
const [jwk] = keys
|
const [jwk] = keys
|
||||||
const key = await importJWK({ ...jwk, alg: 'PS256' })
|
const key = await importJWK({ ...jwk, alg: 'PS256' })
|
||||||
|
|
@ -134,6 +144,48 @@ test.serial('RemoteJWKSet', async (t) => {
|
||||||
t.is(resolvedKey.type, 'public')
|
t.is(resolvedKey.type, 'public')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// Compact JWS
|
||||||
|
{
|
||||||
|
const [jwk] = keys
|
||||||
|
const key = await importJWK({ ...jwk, alg: 'PS256' })
|
||||||
|
const jws = await new CompactSign(new Uint8Array(1))
|
||||||
|
.setProtectedHeader({ alg: 'PS256', kid: jwk.kid })
|
||||||
|
.sign(key)
|
||||||
|
await t.notThrowsAsync(async () => {
|
||||||
|
const { key: resolvedKey } = await compactVerify(jws, JWKS)
|
||||||
|
t.truthy(resolvedKey)
|
||||||
|
t.is(resolvedKey.type, 'public')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// Flattened JWS
|
||||||
|
{
|
||||||
|
const [jwk] = keys
|
||||||
|
const key = await importJWK({ ...jwk, alg: 'PS256' })
|
||||||
|
const jws = await new FlattenedSign(new Uint8Array(1))
|
||||||
|
.setProtectedHeader({ alg: 'PS256' })
|
||||||
|
.setUnprotectedHeader({ kid: jwk.kid })
|
||||||
|
.sign(key)
|
||||||
|
await t.notThrowsAsync(async () => {
|
||||||
|
const { key: resolvedKey } = await flattenedVerify(jws, JWKS)
|
||||||
|
t.truthy(resolvedKey)
|
||||||
|
t.is(resolvedKey.type, 'public')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// General JWS
|
||||||
|
{
|
||||||
|
const [jwk] = keys
|
||||||
|
const key = await importJWK({ ...jwk, alg: 'PS256' })
|
||||||
|
const jws = await new GeneralSign(new Uint8Array(1))
|
||||||
|
.addSignature(key)
|
||||||
|
.setProtectedHeader({ alg: 'PS256' })
|
||||||
|
.setUnprotectedHeader({ kid: jwk.kid })
|
||||||
|
.sign()
|
||||||
|
await t.notThrowsAsync(async () => {
|
||||||
|
const { key: resolvedKey } = await generalVerify(jws, JWKS)
|
||||||
|
t.truthy(resolvedKey)
|
||||||
|
t.is(resolvedKey.type, 'public')
|
||||||
|
})
|
||||||
|
}
|
||||||
{
|
{
|
||||||
const [jwk] = keys
|
const [jwk] = keys
|
||||||
const key = await importJWK({ ...jwk, alg: 'RS256' })
|
const key = await importJWK({ ...jwk, alg: 'RS256' })
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue