From 370c5013c5df3db2c7eddc9fb434dbc06af35ddf Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sat, 14 Aug 2021 19:53:11 +0530 Subject: [PATCH] chore: move importKey tests to webcrypto_unit.ts (#11706) --- cli/tests/unit/crypto_test.ts | 32 -------------------------------- cli/tests/unit/webcrypto_test.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 32 deletions(-) delete mode 100644 cli/tests/unit/crypto_test.ts diff --git a/cli/tests/unit/crypto_test.ts b/cli/tests/unit/crypto_test.ts deleted file mode 100644 index d88accbae3..0000000000 --- a/cli/tests/unit/crypto_test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { assertEquals, unitTest } from "./test_util.ts"; - -unitTest(async function subtleCryptoHmacImport() { - // deno-fmt-ignore - const rawKey = new Uint8Array([ - 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16 - ]); - const key = await crypto.subtle.importKey( - "raw", - rawKey, - { name: "HMAC", hash: "SHA-256" }, - true, - ["sign"], - ); - const actual = await crypto.subtle.sign( - { name: "HMAC" }, - key, - new Uint8Array([1, 2, 3, 4]), - ); - // deno-fmt-ignore - const expected = new Uint8Array([ - 59, 170, 255, 216, 51, 141, 51, 194, - 213, 48, 41, 191, 184, 40, 216, 47, - 130, 165, 203, 26, 163, 43, 38, 71, - 23, 122, 222, 1, 146, 46, 182, 87, - ]); - assertEquals( - new Uint8Array(actual), - expected, - ); -}); diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 988cd61f67..23a4e0c578 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -159,3 +159,34 @@ unitTest(async function testSignRSASSAKey() { assert(signature); }); + +unitTest(async function subtleCryptoHmacImport() { + // deno-fmt-ignore + const rawKey = new Uint8Array([ + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 + ]); + const key = await crypto.subtle.importKey( + "raw", + rawKey, + { name: "HMAC", hash: "SHA-256" }, + true, + ["sign"], + ); + const actual = await crypto.subtle.sign( + { name: "HMAC" }, + key, + new Uint8Array([1, 2, 3, 4]), + ); + // deno-fmt-ignore + const expected = new Uint8Array([ + 59, 170, 255, 216, 51, 141, 51, 194, + 213, 48, 41, 191, 184, 40, 216, 47, + 130, 165, 203, 26, 163, 43, 38, 71, + 23, 122, 222, 1, 146, 46, 182, 87, + ]); + assertEquals( + new Uint8Array(actual), + expected, + ); +});