mirror of
https://github.com/danbulant/jose
synced 2026-05-24 20:41:46 +00:00
test: fix flaky tests
This commit is contained in:
parent
e7ad82cbbc
commit
1cf0da0812
2 changed files with 24 additions and 18 deletions
|
|
@ -92,26 +92,28 @@ if (!('electron' in process.versions)) {
|
|||
}
|
||||
|
||||
test('minimal RSA test', async t => {
|
||||
const key = await generate('RSA')
|
||||
const { d, e, n } = key.toJWK(true)
|
||||
const minKey = asKey({ kty: 'RSA', d, e, n }, { calculateMissingRSAPrimes: true })
|
||||
importKey({ kty: 'RSA', d, e, n }) // deprecated
|
||||
const jwk = {
|
||||
kty: 'RSA',
|
||||
d: 'YN1ucKFpCsgMuIfTynTbNwEXp2lBkrJYfsVOIGdK3bZMblZqxWElm8HTE06-JH_BC5drAAv1Hu-6SE6-sehq9blG-vMJ0wi-jBYfkhlOLEZJXHPb4aJyS8oWKhVO14qyfS_m2BtAW9Wh5vEOXy7HLgrZWjctm0t1Ipb-b_nfNfisGIMjPdWzu_nTfbzIIwM7wQBGnHLqfQq6iD7I8nSPjsc_gZUeeKYkU_Q6K8tIY0gr850-6wk-Nh9JsPA93lR0woTqqMG6UiFE4Y4Jj3M6puBUSU-R3n-gL35I1Cwa5m0IREG8Bz0RPpAEcRQB1xRuM22xD4yE0I4LDegtH056lw',
|
||||
e: 'AQAB',
|
||||
n: '1hZ73O4axgytljzb8gCXxdk3Uov_f7U6c_hKH5EtGtr8XdWce1XLLjARqAQfOpbYqkm1ONiIvhQvxvW0a7gXgEw4no9c_Gi8a803O9LZmYAYDxErlvPQPg9KC5cLPChM-Uyxy4TOakjw1ysUKBX7zXpb_1TIOnlhOYeDbejLkp8sR7BJIsDNxqtkV4KHLWQ9pKsMU28itblQ8nN8UJI5Js4UbR-b417uQ9jIVRhWlDjp11sXYqfnqShCDYGYmLL2IHTVf8tTmEOWsNWcE2nT-qMTGMOq2DBkyr31lxc-4eQXZuwcrk_58xQ69xSrdrsy8J11O50nbvwcqFhjeMV2VQ'
|
||||
};
|
||||
importKey(jwk) // deprecated
|
||||
const key = asKey(jwk, { calculateMissingRSAPrimes: true })
|
||||
key.algorithms('sign').forEach((alg) => {
|
||||
JWS.verify(JWS.sign({}, key), minKey, { alg })
|
||||
JWS.verify(JWS.sign({}, minKey), key, { alg })
|
||||
JWS.verify(JWS.sign({}, key), key, { alg })
|
||||
})
|
||||
key.algorithms('wrapKey').forEach((alg) => {
|
||||
JWE.decrypt(JWE.encrypt('foo', key), minKey, { alg })
|
||||
JWE.decrypt(JWE.encrypt('foo', minKey), key, { alg })
|
||||
JWE.decrypt(JWE.encrypt('foo', key), key, { alg })
|
||||
})
|
||||
t.throws(() => {
|
||||
asKey({ kty: 'RSA', d: d.substr(1), e, n }, { calculateMissingRSAPrimes: true })
|
||||
asKey({ ...jwk, d: jwk.d.substr(1) }, { calculateMissingRSAPrimes: true })
|
||||
}, { instanceOf: errors.JWKImportFailed, code: 'ERR_JWK_IMPORT_FAILED', message: 'failed to calculate missing primes' })
|
||||
t.throws(() => {
|
||||
asKey({ kty: 'RSA', d, e, n })
|
||||
asKey(jwk)
|
||||
}, { instanceOf: errors.JOSENotSupported, code: 'ERR_JOSE_NOT_SUPPORTED', message: 'importing private RSA keys without all other private key parameters is not enabled, see documentation and its advisory on how and when its ok to enable it' })
|
||||
t.throws(() => {
|
||||
asKey({ kty: 'RSA', d: `${d}F`, e, n }, { calculateMissingRSAPrimes: true })
|
||||
asKey({ ...jwk, d: `${jwk.d}F` }, { calculateMissingRSAPrimes: true })
|
||||
}, { instanceOf: errors.JWKInvalid, code: 'ERR_JWK_INVALID', message: 'invalid RSA private exponent' })
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -246,17 +246,21 @@ test('keystore instance is an iterator', t => {
|
|||
})
|
||||
|
||||
test('minimal RSA test', async t => {
|
||||
const key = generateSync('RSA')
|
||||
const { d, e, n } = key.toJWK(true)
|
||||
asKeyStore({ keys: [{ kty: 'RSA', d, e, n }] }, { calculateMissingRSAPrimes: true })
|
||||
KeyStore.fromJWKS({ keys: [{ kty: 'RSA', d, e, n }] }) // deprecated
|
||||
const jwk = {
|
||||
kty: 'RSA',
|
||||
d: 'YN1ucKFpCsgMuIfTynTbNwEXp2lBkrJYfsVOIGdK3bZMblZqxWElm8HTE06-JH_BC5drAAv1Hu-6SE6-sehq9blG-vMJ0wi-jBYfkhlOLEZJXHPb4aJyS8oWKhVO14qyfS_m2BtAW9Wh5vEOXy7HLgrZWjctm0t1Ipb-b_nfNfisGIMjPdWzu_nTfbzIIwM7wQBGnHLqfQq6iD7I8nSPjsc_gZUeeKYkU_Q6K8tIY0gr850-6wk-Nh9JsPA93lR0woTqqMG6UiFE4Y4Jj3M6puBUSU-R3n-gL35I1Cwa5m0IREG8Bz0RPpAEcRQB1xRuM22xD4yE0I4LDegtH056lw',
|
||||
e: 'AQAB',
|
||||
n: '1hZ73O4axgytljzb8gCXxdk3Uov_f7U6c_hKH5EtGtr8XdWce1XLLjARqAQfOpbYqkm1ONiIvhQvxvW0a7gXgEw4no9c_Gi8a803O9LZmYAYDxErlvPQPg9KC5cLPChM-Uyxy4TOakjw1ysUKBX7zXpb_1TIOnlhOYeDbejLkp8sR7BJIsDNxqtkV4KHLWQ9pKsMU28itblQ8nN8UJI5Js4UbR-b417uQ9jIVRhWlDjp11sXYqfnqShCDYGYmLL2IHTVf8tTmEOWsNWcE2nT-qMTGMOq2DBkyr31lxc-4eQXZuwcrk_58xQ69xSrdrsy8J11O50nbvwcqFhjeMV2VQ'
|
||||
};
|
||||
KeyStore.fromJWKS({ keys: [jwk] }) // deprecated
|
||||
asKeyStore({ keys: [jwk] }, { calculateMissingRSAPrimes: true })
|
||||
t.throws(() => {
|
||||
asKeyStore({ keys: [{ kty: 'RSA', d: d.substr(1), e, n }] }, { calculateMissingRSAPrimes: true })
|
||||
asKeyStore({ keys: [{ ...jwk, d: jwk.d.substr(1) }] }, { calculateMissingRSAPrimes: true })
|
||||
}, { instanceOf: errors.JWKImportFailed, code: 'ERR_JWK_IMPORT_FAILED', message: 'failed to calculate missing primes' })
|
||||
t.throws(() => {
|
||||
asKeyStore({ keys: [{ kty: 'RSA', d, e, n }] })
|
||||
asKeyStore({ keys: [jwk] })
|
||||
}, { instanceOf: errors.JOSENotSupported, code: 'ERR_JOSE_NOT_SUPPORTED', message: 'importing private RSA keys without all other private key parameters is not enabled, see documentation and its advisory on how and when its ok to enable it' })
|
||||
t.throws(() => {
|
||||
asKeyStore({ keys: [{ kty: 'RSA', d: `${d}F`, e, n }] }, { calculateMissingRSAPrimes: true })
|
||||
asKeyStore({ keys: [{ ...jwk, d: `${jwk.d}F` }] }, { calculateMissingRSAPrimes: true })
|
||||
}, { instanceOf: errors.JWKInvalid, code: 'ERR_JWK_INVALID', message: 'invalid RSA private exponent' })
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue