From 2c531eb20a7214b98a2b6324d0a0965adba1c931 Mon Sep 17 00:00:00 2001 From: "R. Martinho Fernandes" Date: Wed, 8 Jul 2020 09:24:06 +0000 Subject: [PATCH] Bug 1286878 - Add test to ensure deriveBits throws the right error when given an invalid hash name r=keeler Differential Revision: https://phabricator.services.mozilla.com/D80009 --- dom/crypto/test/test_WebCrypto_PBKDF2.html | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/dom/crypto/test/test_WebCrypto_PBKDF2.html b/dom/crypto/test/test_WebCrypto_PBKDF2.html index 1f079693bc04..93557b8c5e9e 100644 --- a/dom/crypto/test/test_WebCrypto_PBKDF2.html +++ b/dom/crypto/test/test_WebCrypto_PBKDF2.html @@ -290,6 +290,39 @@ TestArray.addTest( .then( memcmp_complete(that, tv.pbkdf2_sha256_no_salt.derived), fail ); } ); + +// ----------------------------------------------------------------------------- +TestArray.addTest( + "Fail while deriving key with bad hash name", + function() { + var that = this; + var alg = "PBKDF2"; + var key = tv.pbkdf2_sha256.password; + + function doDerive(x) { + if (!hasKeyFields(x)) { + throw new Error("Invalid key; missing field(s)"); + } + + var algo = { + name: "PBKDF2", + hash: "SHA256", + salt: tv.pbkdf2_sha256.salt, + iterations: tv.pbkdf2_sha256.iterations, + }; + return crypto.subtle.deriveBits(algo, x, 32).then( + error(that), + complete(that, function(e) { + return e.name == "NotSupportedError"; + }) + ); + } + function fail(x) { console.log("failing"); error(that)(x); } + + crypto.subtle.importKey("raw", key, alg, false, ["deriveKey", "deriveBits"]) + .then( doDerive, fail ); + } +); /* ]]>*/