summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorSean Michael Wykes <8363933+SeanWykes@users.noreply.github.com>2022-01-03 09:24:45 -0300
committerGitHub <noreply@github.com>2022-01-03 17:54:45 +0530
commit340764adec4fd613239d8280664361b3c1b9d350 (patch)
treeceb99307f45c2f11f742933e12b7963e258ec374 /cli/tests
parent9a42d65fc73cea9c8c523a2733d0b180bcdd78e7 (diff)
fix(ext/crypto): use forgiving base64 encoding for JWK (#13240)
Implements "forgiving" in JWK decode passing suitable config to base64::decode_config
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/webcrypto_test.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts
index c4958fbdf..2d101e975 100644
--- a/cli/tests/unit/webcrypto_test.ts
+++ b/cli/tests/unit/webcrypto_test.ts
@@ -1419,3 +1419,28 @@ Deno.test(async function testImportEcSpkiPkcs8() {
assertEquals(new Uint8Array(expPrivateKeySPKI), spki);*/
}
});
+
+Deno.test(async function testBase64Forgiving() {
+ const keyData = `{
+ "kty": "oct",
+ "k": "xxx",
+ "alg": "HS512",
+ "key_ops": ["sign", "verify"],
+ "ext": true
+ }`;
+
+ const key = await crypto.subtle.importKey(
+ "jwk",
+ JSON.parse(keyData),
+ { name: "HMAC", hash: "SHA-512" },
+ true,
+ ["sign", "verify"],
+ );
+
+ assert(key instanceof CryptoKey);
+ assertEquals(key.type, "secret");
+ assertEquals((key.algorithm as HmacKeyAlgorithm).length, 16);
+
+ const exportedKey = await crypto.subtle.exportKey("jwk", key);
+ assertEquals(exportedKey.k, "xxw");
+});