Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Unified Diff: LayoutTests/crypto/hmac-export-key.html

Issue 298023002: [webcrypto] Import WebKit's webcrypto tests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: remove FIXME for unrecognized jwk usages (supported now) Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/crypto/hmac-export-key.html
diff --git a/LayoutTests/crypto/hmac-export-key.html b/LayoutTests/crypto/hmac-export-key.html
new file mode 100644
index 0000000000000000000000000000000000000000..7b7097d2a9a1cef6d362e9cda38633aaa55fcbdb
--- /dev/null
+++ b/LayoutTests/crypto/hmac-export-key.html
@@ -0,0 +1,91 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../resources/js-test.js"></script>
+<script src="resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test exporting an AES key.");
+
+jsTestIsAsync = true;
+
+var extractable = true;
+var nonExtractable = false;
+
+var jwkKey = {
+ "kty": "oct",
+ "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
+};
+
+var jwkKeyAsArrayBuffer = asciiToUint8Array(JSON.stringify(jwkKey));
+
+debug("Importing a JWK key...");
+crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, { name: "HMAC", hash: {name: "SHA-256"} }, extractable, ["sign", "verify"]).then(function(result) {
+ key = result;
+
+ return crypto.subtle.exportKey(null, key);
+}).then(failAndFinishJSTest, function(result) {
+ logError(result);
+ return crypto.subtle.exportKey(undefined, key);
+}).then(failAndFinishJSTest, function(result) {
+ logError(result);
+ return crypto.subtle.exportKey({}, key);
+}).then(failAndFinishJSTest, function(result) {
+ logError(result);
+ return crypto.subtle.exportKey("", key);
+}).then(failAndFinishJSTest, function(result) {
+ logError(result);
+ return crypto.subtle.exportKey("foobar", key);
+}).then(failAndFinishJSTest, function(result) {
+ logError(result);
+
+ debug("Exporting the key as raw data...");
+ return crypto.subtle.exportKey("raw", key);
+}, failAndFinishJSTest).then(function(result) {
+ exportedData = result;
+ shouldBe("bytesToHexString(new Uint8Array(exportedData))", "'6a18e49feff7f3b7e09ec89b7f6deab2f6a18e49feff7f3b7e09ec89b7f6deab'");
+
+ debug("Exporting the key as JWK...");
+ return crypto.subtle.exportKey("jwk", key);
+}).then(function(result) {
+ exportedJWK = JSON.parse(bytesToASCIIString(result));
+ shouldBe("exportedJWK.kty", "'oct'");
+ shouldBe("exportedJWK.k", "'ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs'");
+ shouldBe("exportedJWK.alg", "'HS256'");
+ shouldBe("exportedJWK.ext", "true");
+ shouldBe("exportedJWK.use", "undefined");
+ shouldBe("exportedJWK.key_ops", "['sign', 'verify']");
+
+ debug("\nImporting a key that's not extractable...");
+ return crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, { name: "HMAC", hash: {name: "SHA-256"} }, nonExtractable, ["sign", "verify"]);
+}, failAndFinishJSTest).then(function(result) {
+ key = result;
+
+ debug("\nTrying to export as raw...");
+ return crypto.subtle.exportKey("raw", key);
+}).then(function(result) {
+ testFailed("Promise wasn't rejected");
+ finishJSTest();
+}, function(result) {
+ logError(result);
+ testPassed("Rejected, as expected");
+
+ debug("Trying to export as jwk...");
+ return crypto.subtle.exportKey("jwk", key);
+}).then(function(result) {
+ testFailed("Promise wasn't rejected");
+ finishJSTest();
+}, function(result) {
+ logError(result);
+ testPassed("Rejected, as expected");
+
+ finishJSTest();
+});
+</script>
+
+</body>
+</html>
« no previous file with comments | « LayoutTests/crypto/array-buffer-view-offset-expected.txt ('k') | LayoutTests/crypto/hmac-export-key-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698