mirror of
https://github.com/danbulant/jose
synced 2026-05-19 04:18:52 +00:00
test: bump deno, update imports
This commit is contained in:
parent
119134149e
commit
ee03b7eefa
11 changed files with 58 additions and 68 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import * as Bowser from 'bowser';
|
||||
|
||||
import jwkToKey from '../dist/browser/jwk/parse.js';
|
||||
import keyToJwk from '../dist/browser/jwk/from_key_like.js';
|
||||
import { importJWK } from '../dist/browser/key/import.js';
|
||||
import { exportJWK } from '../dist/browser/key/export.js';
|
||||
import calculateThumbprint from '../dist/browser/jwk/thumbprint.js';
|
||||
|
||||
const browser = Bowser.parse(window.navigator.userAgent);
|
||||
|
|
@ -10,8 +10,8 @@ const p521 = browser.engine.name !== 'WebKit';
|
|||
|
||||
async function test(jwk, alg, assert) {
|
||||
await calculateThumbprint(jwk);
|
||||
const keyLike = await jwkToKey({ ...jwk, ext: true }, alg);
|
||||
assert.deepEqual(await keyToJwk(keyLike), jwk);
|
||||
const keyLike = await importJWK({ ...jwk, ext: true }, alg);
|
||||
assert.deepEqual(await exportJWK(keyLike), jwk);
|
||||
}
|
||||
|
||||
async function failing(jwk, alg, assert) {
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ test('HS256', macro, async () => {
|
|||
const alg = 'HS256';
|
||||
const jwk = JSON.parse('{"kty":"oct","k":"iPYq7qKZWRaVmo1FiJ17M84uADey7-veCAEEsxpPTus"}');
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const secretKey = await utilGenerateSecret(alg);
|
||||
await jwsSymmetricTest(secretKey, alg);
|
||||
});
|
||||
|
|
@ -122,7 +122,7 @@ test('HS384', macro, async () => {
|
|||
'{"kty":"oct","k":"ATgNcVOYFsjbN4GeyXOyryfqqmGp_48-uvVd5J3GsX7ExUMp3WNTDbbZK_5kTjND"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const secretKey = await utilGenerateSecret(alg);
|
||||
await jwsSymmetricTest(secretKey, alg);
|
||||
});
|
||||
|
|
@ -133,7 +133,7 @@ test('HS512', macro, async () => {
|
|||
'{"kty":"oct","k":"2O5x_zEOhSIDiGcOAOYhB1dyDU_ZW27rl-_xDpKE-8tBlL91z6p_8aYo3by6AOsa6ycx6-JC9LBAio0amINXTQ"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const secretKey = await utilGenerateSecret(alg);
|
||||
await jwsSymmetricTest(secretKey, alg);
|
||||
});
|
||||
|
|
@ -144,7 +144,7 @@ test('RS256', macro, async () => {
|
|||
'{"kty":"RSA","n":"rcbWc-i_C8NtS4CpPcMF3QC025re_zzrhv-3ElzxAsMCCepwEqxCzQtsG7mAtROdGR1N_oNPNqr3jmEZdv5C5NtpPeX_gk4-r30_JLXcGNgVbZpmWVSmUI-nrU0cC3kjMS4RUPx7uDQxAUiVUq0k13qjEbEgcZAA3nEH2zuQWg3iWSmwYL0h1VxdINQ-WZZzBJsI_ONyBS5z3-vbyhtnMbgALRZSvNcYpODrH9AEIWNJhcaBVr1vKBdNT76KOl87ilLiKE1dOr72sLJDDsVqXDfxCjU_wdt2bF-YFcKwlYa5Aj2JF-UH7KLniC3P-2sS1zduLoAPAkyLcHgVdOifhQ","e":"AQAB"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const keypair = await utilGenerateKeyPair(alg);
|
||||
await jwsAsymmetricTest(keypair, alg);
|
||||
await testSPKI(fixtures.keys.rsa.publicKey, alg);
|
||||
|
|
@ -158,7 +158,7 @@ test('RS384', macro, async () => {
|
|||
'{"kty":"RSA","n":"yKV00L6PwdO6DGMgsNwuWZ0xviGMqq7nvkULJ8jyQil8viSUvxDMPDZ80CoHUkgobcBU1DasjGO9nTthPYhcpOFh8Fzat1aG-z5Ola2FBHqpdJpwb7lxsLfq6UJy1bial5RCMrLdW3NhuCxIfhnGmvq4hFLAF7gBnEfkbN9qsrzyZruEGIlNG50r779axmgnRZDZ6YS5o_DVbn27f2yCjBLVYIljW5z9CSm6_NjSYVdeNujrgQUWMIrCZiJqmRSOAvn6GliKXFL7sh5xLh_DiCx1Atr477sBxviLY-tFpeXLOqKJKqZ5GASrspxsO96roE4-I4J-7JgoxYptuKD2Bw","e":"AQAB"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const keypair = await utilGenerateKeyPair(alg);
|
||||
await jwsAsymmetricTest(keypair, alg);
|
||||
|
||||
|
|
@ -173,7 +173,7 @@ test('RS512', macro, async () => {
|
|||
'{"kty":"RSA","n":"wdEr4kyCku2F8a2Y45xa1Q-jE5FlkYK6xUDuyckH6U9hhA_1OFaNfTbZ-8ZkXOp0PGzYjCqAk0YxATfnKSc1-PKnOBvBD8FRpgaT61WyOq_yM6YgDrwQvbWTr0r5copjDs4ZA9mrE-bjgvOLut4GpD4NVPWhPkgI45-yYd0H4vjuf36sCe26MBIWBTzInCUdfKTvCdh0Kk__HOENwwke6XrtzvugJymi3zlrdqztq3efJFmA4hvyLzosdBB8g0iWBXFNy51J8RCYygiSXtsPatV1FMVd6ZkTfVrvR3OYJucbuvCbqQwPDB08XjJLXKTE1eolyECk-U-Z_Cg8aNElpw","e":"AQAB"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const keypair = await utilGenerateKeyPair(alg);
|
||||
await jwsAsymmetricTest(keypair, alg);
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ test('PS256', macro, async () => {
|
|||
'{"kty":"RSA","n":"5Yv7aQulm2VYKjSfwPQLSEokqtWu-TxKKkRKT_570Yjk0fIg81IbK5T0SrkBzmEV5bjuoGdVMQf6bvkhOeeborTmbISEE6DCNxN_us3EWJKMKp-OSbeqbvbg252l_wPhcC5OC0Q--ryOqoRlsCKYgCmDbKNmZepGm8Nf1ayeqj3kIuKmgzU7y4dy4Le8Sq-9aHD5_QW52WqHeEnmIfrVnR7mJsrd7LY-28aflUHaEDn1TzhPPq0W_F1lMkdniM4c5JNU5_6fZ8NVla51j-pt0PmQMz-Ch97ZcnpB7DGdNyBDzdnQiabJ7sOxRK33so8cUFh3zHnaeX73XeGgrpD5XQ","e":"AQAB"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const keypair = await utilGenerateKeyPair(alg);
|
||||
await jwsAsymmetricTest(keypair, alg);
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ test('PS384', macro, async () => {
|
|||
'{"kty":"RSA","n":"vyJy0ZJqdGsH3-AGnaw5I35lPhFdWDxxkRn-TBx1GfhIKCjibEjZTCfzBnBdWwIUnr2fL0Vy6VZvTEUcH66r4AJy380ovOJrVIM5nhAGn8uSLCoJ2yiuKeA50gBylINvdAVG7fDzau4-1aSQ1RXILxa88raqDK1h8DQoGZLnRdiKkfNjKmXVltsvDSUxOmKelHh9WLiF2JCs0ydMCCcGDumosLBlP4LR7XfycW2cIavRdxeajL8oyRckD9-IpZLampTkr0Ja4GWHbHnAX-dXmoRDEhqlMeSpKmbm-e95jT_3SHwLj_TLlwF4HsIj-egX78lHcVJzCvhdUG7ogrbjHw","e":"AQAB"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const keypair = await utilGenerateKeyPair(alg);
|
||||
await jwsAsymmetricTest(keypair, alg);
|
||||
|
||||
|
|
@ -218,7 +218,7 @@ test('PS512', macro, async () => {
|
|||
'{"kty":"RSA","n":"sSLTDqh1I2Rt26uCFrbdYuRY3lqDes8Az0GQxgatQhXgIG1jOfuEIaqnMRDuWinroRWuetR1ykQ4SxzIy31ms5PSM5sJm1SNAiynO6dxxGMNaCLt4Rgi_fAn6CD0F4mo2OLmxm1_hQH1SJSymG8p8q9Uu0IToY4KEEmHwc1kfiAosvqfLgY1-CRU8kKbFHzq28x7Jbv4WSDccJ_-Wm8BiyMkIUQfzRsC1hHiMO_NKlLwMqeSQ5XyYqsBxc80cF6Z9IIBzXewjCGGVAfYMeimPcJao6wat-PXEr5axEeBeCFU6Q7TDLcMilotGV6f6-UECUK5q2QCXtoOnZ5TO4yPzQ","e":"AQAB"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const keypair = await utilGenerateKeyPair(alg);
|
||||
await jwsAsymmetricTest(keypair, alg);
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ test('ES256', macro, async () => {
|
|||
'{"kty":"EC","crv":"P-256","x":"E8KpG0wpGUfRBYx8tUhd6tYaFaTZaIyHvAudXbSUFxQ","y":"gcVDlKTo-UhZ-wHDNUdoQP0M9zevurU6A5WMR07B-wQ"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const keypair = await utilGenerateKeyPair(alg);
|
||||
await jwsAsymmetricTest(keypair, alg);
|
||||
await testSPKI(fixtures.keys['P-256'].publicKey, alg);
|
||||
|
|
@ -247,7 +247,7 @@ test('ES384', macro, async () => {
|
|||
'{"kty":"EC","crv":"P-384","x":"HnBAtgpS-GJzTCdLBELPm1VIRoQwlk7luJIGEYWKhWtMHmOq14Hh7674Oxcc52mE","y":"jXGek8Zapkjav7mO-KB-7vEWrqNxHSoXgNn1r6C0BiqS89SVciz6O8uriPdxoWem"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const keypair = await utilGenerateKeyPair(alg);
|
||||
await jwsAsymmetricTest(keypair, alg);
|
||||
await testSPKI(fixtures.keys['P-384'].publicKey, alg);
|
||||
|
|
@ -261,7 +261,7 @@ test('ES512', macro, async () => {
|
|||
'{"kty":"EC","crv":"P-521","x":"AIwG869tNnEGIDg2hSyvXKIOk9rWPO_riIixGliBGBV0kB57QoTrjK-g5JCtazDTcBT23igX9gvAVkLvr2oFTQ9p","y":"AeGZ0Z3JHM1rQWvmmpdfVu0zSNpmu0xPjGUE2hGhloRqF-JJV3aVMS72ZhGlbWi-O7OCcypIfndhpYgrc3qx0Y1w"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const keypair = await utilGenerateKeyPair(alg);
|
||||
await jwsAsymmetricTest(keypair, alg);
|
||||
await testSPKI(fixtures.keys['P-521'].publicKey, alg);
|
||||
|
|
@ -275,7 +275,7 @@ test('EdDSA', macro, async () => {
|
|||
'{"kty":"OKP","crv":"Ed25519","x":"zjV_JsgzH--qhtVlJEYDFeRFITSD0k6lYSSpOKBarZQ"}',
|
||||
);
|
||||
await jwkThumbprint(jwk);
|
||||
await jwkFromKeyLike(await jwkParse({ ...jwk, ext: true }, alg));
|
||||
await keyExport.exportJWK(await keyImport.importJWK({ ...jwk, ext: true }, alg));
|
||||
const keypair = await utilGenerateKeyPair(alg);
|
||||
await jwsAsymmetricTest(keypair, alg);
|
||||
await testSPKI(fixtures.keys.ed25519.publicKey, alg);
|
||||
|
|
@ -292,7 +292,7 @@ test('EdDSA crv: Ed448', macro, async () => {
|
|||
const alg = 'EdDSA';
|
||||
const jwk =
|
||||
'{"kty":"OKP","crv":"Ed448","x":"Wc7ow0-awVkxhTX7Rmkp1dDbR_EJYOH61-Cnx2iFxfq_QhUvIKWpI6UlHoWnKyE0zh4rlKdoJb6A"}';
|
||||
await jwkParse({ ...jwk, ext: true }, alg).then(
|
||||
await keyImport.importJWK({ ...jwk, ext: true }, alg).then(
|
||||
() => {
|
||||
throw new Error('should fail');
|
||||
},
|
||||
|
|
@ -309,7 +309,7 @@ test('EdDSA crv: Ed448', macro, async () => {
|
|||
test('ECDH-ES crv: X25519', macro, async () => {
|
||||
const alg = 'ECDH-ES';
|
||||
const jwk = '{"kty":"OKP","crv":"X25519","x":"HqyMxA2utODyDFMeCiTiOXmHIG_ih52vOX89gbCI71U"}';
|
||||
await jwkParse({ ...jwk, ext: true }, alg).then(
|
||||
await keyImport.importJWK({ ...jwk, ext: true }, alg).then(
|
||||
() => {
|
||||
throw new Error('should fail');
|
||||
},
|
||||
|
|
@ -327,7 +327,7 @@ test('ECDH-ES crv: X448', macro, async () => {
|
|||
const alg = 'ECDH-ES';
|
||||
const jwk =
|
||||
'{"kty":"OKP","crv":"X448","x":"v3Lhxa_bdhGUK7NUYHizRQA55sDS68WeZTGYNvFhdxhL519MkWQTt_LlviW84i6ARWyVxlKgBF0"';
|
||||
await jwkParse({ ...jwk, ext: true }, alg).then(
|
||||
await keyImport.importJWK({ ...jwk, ext: true }, alg).then(
|
||||
() => {
|
||||
throw new Error('should fail');
|
||||
},
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ import jweCompactDecrypt from '../dist/browser/jwe/compact/decrypt.js';
|
|||
import jweFlattenedDecrypt from '../dist/browser/jwe/flattened/decrypt.js';
|
||||
import jweGeneralDecrypt from '../dist/browser/jwe/general/decrypt.js';
|
||||
import jwkEmbedded from '../dist/browser/jwk/embedded.js';
|
||||
import jwkFromKeyLike from '../dist/browser/jwk/from_key_like.js';
|
||||
import jwkParse from '../dist/browser/jwk/parse.js';
|
||||
import jwkThumbprint from '../dist/browser/jwk/thumbprint.js';
|
||||
import jwksRemote from '../dist/browser/jwks/remote.js';
|
||||
import jwsCompactVerify from '../dist/browser/jws/compact/verify.js';
|
||||
|
|
|
|||
|
|
@ -46,14 +46,6 @@ Deno.test('imports EmbeddedJWK', async () => {
|
|||
await import('../dist/deno/jwk/embedded.ts');
|
||||
});
|
||||
|
||||
Deno.test('imports fromKeyLike', async () => {
|
||||
await import('../dist/deno/jwk/from_key_like.ts');
|
||||
});
|
||||
|
||||
Deno.test('imports parseJwk', async () => {
|
||||
await import('../dist/deno/jwk/parse.ts');
|
||||
});
|
||||
|
||||
Deno.test('imports calculateThumbprint', async () => {
|
||||
await import('../dist/deno/jwk/thumbprint.ts');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { assert, assertThrowsAsync } from 'https://deno.land/std@0.104.0/testing/asserts.ts';
|
||||
import { assert, assertThrowsAsync } from 'https://deno.land/std@0.109.0/testing/asserts.ts';
|
||||
|
||||
import generateKeyPair from '../dist/deno/util/generate_key_pair.ts';
|
||||
import random from '../dist/deno/util/random.ts';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { assert } from 'https://deno.land/std@0.104.0/testing/asserts.ts';
|
||||
import { assert } from 'https://deno.land/std@0.109.0/testing/asserts.ts';
|
||||
|
||||
import generateSecret from '../dist/deno/util/generate_secret.ts';
|
||||
import random from '../dist/deno/util/random.ts';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { assertThrowsAsync } from 'https://deno.land/std@0.104.0/testing/asserts.ts';
|
||||
import { assertThrowsAsync } from 'https://deno.land/std@0.109.0/testing/asserts.ts';
|
||||
|
||||
import createRemoteJWKSet from '../dist/deno/jwks/remote.ts';
|
||||
import { JWKSNoMatchingKey, JWKSMultipleMatchingKeys } from '../dist/deno/util/errors.ts';
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import {
|
|||
assert,
|
||||
assertThrowsAsync,
|
||||
unreachable,
|
||||
} from 'https://deno.land/std@0.104.0/testing/asserts.ts';
|
||||
} from 'https://deno.land/std@0.109.0/testing/asserts.ts';
|
||||
|
||||
import generateKeyPair from '../dist/deno/util/generate_key_pair.ts';
|
||||
import generateSecret from '../dist/deno/util/generate_secret.ts';
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { assertEquals, assertThrowsAsync } from 'https://deno.land/std@0.104.0/testing/asserts.ts';
|
||||
import { assertEquals, assertThrowsAsync } from 'https://deno.land/std@0.109.0/testing/asserts.ts';
|
||||
|
||||
import jwkToKey from '../dist/deno/jwk/parse.ts';
|
||||
import keyToJwk from '../dist/deno/jwk/from_key_like.ts';
|
||||
import { importJWK } from '../dist/deno/key/import.ts';
|
||||
import { exportJWK } from '../dist/deno/key/export.ts';
|
||||
import calculateThumbprint from '../dist/deno/jwk/thumbprint.ts';
|
||||
|
||||
async function test(jwk: { [key: string]: unknown }, alg: string) {
|
||||
await calculateThumbprint(jwk);
|
||||
const keyLike = await jwkToKey({ ...jwk, ext: true }, alg);
|
||||
assertEquals(await keyToJwk(keyLike), jwk);
|
||||
const keyLike = await importJWK({ ...jwk, ext: true }, alg);
|
||||
assertEquals(await exportJWK(keyLike), jwk);
|
||||
}
|
||||
|
||||
async function failing(jwk: { [key: string]: unknown }, alg: string) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { assertThrowsAsync } from 'https://deno.land/std@0.104.0/testing/asserts.ts';
|
||||
import { assertThrowsAsync } from 'https://deno.land/std@0.109.0/testing/asserts.ts';
|
||||
|
||||
import * as importKey from '../dist/browser/key/import.js';
|
||||
import * as exportKey from '../dist/browser/key/export.js';
|
||||
|
|
|
|||
|
|
@ -12,26 +12,26 @@ if ('WEBCRYPTO' in process.env) {
|
|||
root = keyRoot = '#dist';
|
||||
}
|
||||
|
||||
Promise.all([import(`${keyRoot}/jwk/parse`), import(`${keyRoot}/jwk/from_key_like`)]).then(
|
||||
([{ default: parseJwk }, { default: fromKeyLike }]) => {
|
||||
Promise.all([import(`${keyRoot}/key/import`), import(`${keyRoot}/key/export`)]).then(
|
||||
([{ importJWK }, { exportJWK }]) => {
|
||||
test('JWK must be an object', async (t) => {
|
||||
await t.throwsAsync(parseJwk(true), {
|
||||
await t.throwsAsync(importJWK(true), {
|
||||
instanceOf: TypeError,
|
||||
message: 'JWK must be an object',
|
||||
});
|
||||
await t.throwsAsync(parseJwk(null), {
|
||||
await t.throwsAsync(importJWK(null), {
|
||||
instanceOf: TypeError,
|
||||
message: 'JWK must be an object',
|
||||
});
|
||||
await t.throwsAsync(parseJwk(Boolean), {
|
||||
await t.throwsAsync(importJWK(Boolean), {
|
||||
instanceOf: TypeError,
|
||||
message: 'JWK must be an object',
|
||||
});
|
||||
await t.throwsAsync(parseJwk([]), {
|
||||
await t.throwsAsync(importJWK([]), {
|
||||
instanceOf: TypeError,
|
||||
message: 'JWK must be an object',
|
||||
});
|
||||
await t.throwsAsync(parseJwk(''), {
|
||||
await t.throwsAsync(importJWK(''), {
|
||||
instanceOf: TypeError,
|
||||
message: 'JWK must be an object',
|
||||
});
|
||||
|
|
@ -40,11 +40,11 @@ Promise.all([import(`${keyRoot}/jwk/parse`), import(`${keyRoot}/jwk/from_key_lik
|
|||
nullPrototype.kty = 'EC';
|
||||
nullPrototype.x = 'q3zAwR_kUwtdLEwtB2oVfucXiLHmEhu9bJUFYjJxYGs';
|
||||
nullPrototype.y = '8h0D-ONoU-iZqrq28TyUxEULxuGwJZGMJYTMbeMshvI';
|
||||
await t.notThrowsAsync(parseJwk(nullPrototype, 'ES256'));
|
||||
await t.notThrowsAsync(importJWK(nullPrototype, 'ES256'));
|
||||
});
|
||||
|
||||
test('JWK kty must be recognized', async (t) => {
|
||||
await t.throwsAsync(parseJwk({ kty: 'unrecognized' }, 'HS256'), {
|
||||
await t.throwsAsync(importJWK({ kty: 'unrecognized' }, 'HS256'), {
|
||||
code: 'ERR_JOSE_NOT_SUPPORTED',
|
||||
message: 'Unsupported "kty" (Key Type) Parameter value',
|
||||
});
|
||||
|
|
@ -55,23 +55,23 @@ Promise.all([import(`${keyRoot}/jwk/parse`), import(`${keyRoot}/jwk/from_key_lik
|
|||
k: 'FyCq1CKBflh3I5gikEjpYrdOXllzxB_yc02za8ERknI',
|
||||
kty: 'oct',
|
||||
};
|
||||
await t.throwsAsync(parseJwk(oct), {
|
||||
await t.throwsAsync(importJWK(oct), {
|
||||
instanceOf: TypeError,
|
||||
message: '"alg" argument is required when "jwk.alg" is not present',
|
||||
});
|
||||
await t.notThrowsAsync(parseJwk(oct, 'HS256'));
|
||||
await t.notThrowsAsync(parseJwk({ ...oct, alg: 'HS256' }));
|
||||
await t.notThrowsAsync(importJWK(oct, 'HS256'));
|
||||
await t.notThrowsAsync(importJWK({ ...oct, alg: 'HS256' }));
|
||||
});
|
||||
|
||||
test('oct JWK must have "k"', async (t) => {
|
||||
await t.throwsAsync(parseJwk({ kty: 'oct' }, 'HS256'), {
|
||||
await t.throwsAsync(importJWK({ kty: 'oct' }, 'HS256'), {
|
||||
instanceOf: TypeError,
|
||||
message: 'missing "k" (Key Value) Parameter value',
|
||||
});
|
||||
});
|
||||
|
||||
test('RSA JWK with oth is not supported', async (t) => {
|
||||
await t.throwsAsync(parseJwk({ kty: 'RSA', oth: [] }, 'RS256'), {
|
||||
await t.throwsAsync(importJWK({ kty: 'RSA', oth: [] }, 'RS256'), {
|
||||
code: 'ERR_JOSE_NOT_SUPPORTED',
|
||||
message: 'RSA JWK "oth" (Other Primes Info) Parameter value is not supported',
|
||||
});
|
||||
|
|
@ -85,7 +85,7 @@ Promise.all([import(`${keyRoot}/jwk/parse`), import(`${keyRoot}/jwk/from_key_lik
|
|||
};
|
||||
|
||||
t.deepEqual(
|
||||
[...(await parseJwk(oct, 'HS256'))],
|
||||
[...(await importJWK(oct, 'HS256'))],
|
||||
[
|
||||
23, 32, 170, 212, 34, 129, 126, 88, 119, 35, 152, 34, 144, 72, 233, 98, 183, 78, 94, 89,
|
||||
115, 196, 31, 242, 115, 77, 179, 107, 193, 17, 146, 114,
|
||||
|
|
@ -100,7 +100,7 @@ Promise.all([import(`${keyRoot}/jwk/parse`), import(`${keyRoot}/jwk/from_key_lik
|
|||
ext: false,
|
||||
};
|
||||
|
||||
const k = await parseJwk(oct, 'HS256');
|
||||
const k = await importJWK(oct, 'HS256');
|
||||
|
||||
t.true('type' in k);
|
||||
t.is(k.type, 'secret');
|
||||
|
|
@ -112,7 +112,7 @@ Promise.all([import(`${keyRoot}/jwk/parse`), import(`${keyRoot}/jwk/from_key_lik
|
|||
kty: 'oct',
|
||||
};
|
||||
|
||||
const k = await parseJwk(oct, 'HS256');
|
||||
const k = await importJWK(oct, 'HS256');
|
||||
|
||||
t.true('type' in k);
|
||||
t.is(k.type, 'secret');
|
||||
|
|
@ -120,29 +120,29 @@ Promise.all([import(`${keyRoot}/jwk/parse`), import(`${keyRoot}/jwk/from_key_lik
|
|||
|
||||
async function testKeyImportExport(t, jwk) {
|
||||
await t.notThrowsAsync(async () => {
|
||||
let key = await parseJwk({ ...jwk, ext: true });
|
||||
let key = await importJWK({ ...jwk, ext: true });
|
||||
t.is(key.type, 'private');
|
||||
const exportedJwk = await fromKeyLike(key);
|
||||
key = await parseJwk(exportedJwk, jwk.alg);
|
||||
const exportedJwk = await exportJWK(key);
|
||||
key = await importJWK(exportedJwk, jwk.alg);
|
||||
t.is(key.type, 'private');
|
||||
});
|
||||
await t.notThrowsAsync(async () => {
|
||||
const { d, p, q, dp, dq, qi, ...publicJwk } = jwk;
|
||||
const key = await parseJwk(publicJwk);
|
||||
const key = await importJWK(publicJwk);
|
||||
t.is(key.type, 'public');
|
||||
});
|
||||
await t.notThrowsAsync(async () => {
|
||||
const { ext, key_ops, alg, use, ...expectedExport } = jwk;
|
||||
const key = await parseJwk({ ...jwk, ext: true });
|
||||
const key = await importJWK({ ...jwk, ext: true });
|
||||
t.is(key.type, 'private');
|
||||
t.deepEqual(await fromKeyLike(key), expectedExport);
|
||||
t.deepEqual(await exportJWK(key), expectedExport);
|
||||
});
|
||||
await t.notThrowsAsync(async () => {
|
||||
const { d, p, q, dp, dq, qi, ...publicJwk } = jwk;
|
||||
const { ext, key_ops, alg, use, ...expectedExport } = publicJwk;
|
||||
const key = await parseJwk({ ...publicJwk, ext: true });
|
||||
const key = await importJWK({ ...publicJwk, ext: true });
|
||||
t.is(key.type, 'public');
|
||||
t.deepEqual(await fromKeyLike(key), expectedExport);
|
||||
t.deepEqual(await exportJWK(key), expectedExport);
|
||||
});
|
||||
}
|
||||
testKeyImportExport.title = (_, jwk) => `${jwk.kty} ${jwk.crv} JWK (${jwk.alg})`;
|
||||
|
|
@ -191,7 +191,7 @@ Promise.all([import(`${keyRoot}/jwk/parse`), import(`${keyRoot}/jwk/from_key_lik
|
|||
|
||||
test('Uin8tArray can be transformed to a JWK', async (t) => {
|
||||
t.deepEqual(
|
||||
await fromKeyLike(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])),
|
||||
await exportJWK(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])),
|
||||
{
|
||||
k: 'AQIDBAUGBwgJCgsMDQ4P',
|
||||
kty: 'oct',
|
||||
|
|
@ -223,7 +223,7 @@ Promise.all([import(`${keyRoot}/jwk/parse`), import(`${keyRoot}/jwk/from_key_lik
|
|||
}
|
||||
|
||||
conditional({ webcrypto: 0 })('secret key object can be transformed to a JWK', async (t) => {
|
||||
const keylike = await parseJwk(
|
||||
const keylike = await importJWK(
|
||||
{
|
||||
ext: true,
|
||||
k: 'AQIDBAUGBwgJCgsMDQ4P',
|
||||
|
|
@ -232,7 +232,7 @@ Promise.all([import(`${keyRoot}/jwk/parse`), import(`${keyRoot}/jwk/from_key_lik
|
|||
'HS256',
|
||||
true,
|
||||
);
|
||||
t.deepEqual(await fromKeyLike(keylike), {
|
||||
t.deepEqual(await exportJWK(keylike), {
|
||||
k: 'AQIDBAUGBwgJCgsMDQ4P',
|
||||
kty: 'oct',
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue