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

Side by Side Diff: LayoutTests/crypto/sign-verify.html

Issue 23126008: WebCrypto: refactor layout tests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « LayoutTests/crypto/resources/common.js ('k') | LayoutTests/crypto/sign-verify-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../fast/js/resources/js-test-pre.js"></script> 4 <script src="../fast/js/resources/js-test-pre.js"></script>
5 <script src="resources/common.js"></script> 5 <script src="resources/common.js"></script>
6 </head> 6 </head>
7 <body> 7 <body>
8 <p id="description"></p> 8 <p id="description"></p>
9 <div id="console"></div> 9 <div id="console"></div>
10 10
11 <script> 11 <script>
12 description("Tests cypto.subtle.sign and crypto.subtle.verify"); 12 description("Tests cypto.subtle.sign and crypto.subtle.verify");
13 13
14 jsTestIsAsync = true; 14 jsTestIsAsync = true;
15 15
16 importHmacSha1Key().then(function(key) { 16 importTestKeys().then(function(importedKeys) {
17 hmacSha1Key = key; 17 keys = importedKeys;
18 hmacSha1 = {name: 'hmac', hash: {name: 'Sha-1'}}; 18
19 hmacSha1 = {name: 'hmac', hash: {name: 'sha-1'}};
19 20
20 data = asciiToArrayBuffer("hello"); 21 data = asciiToArrayBuffer("hello");
21 var expectedSignature = asciiToArrayBuffer("signed HMAC:hello");
22 22
23 // Pass invalid signature parameters to verify() 23 // Pass invalid signature parameters to verify()
24 shouldThrow("crypto.subtle.verify(hmacSha1, hmacSha1Key, null, data)"); 24 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, null, data)");
25 shouldThrow("crypto.subtle.verify(hmacSha1, hmacSha1Key, 'a', data)"); 25 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, 'a', data)");
26 shouldThrow("crypto.subtle.verify(hmacSha1, hmacSha1Key, [], data)"); 26 shouldThrow("crypto.subtle.verify(hmacSha1, keys.hmacSha1, [], data)");
27 27
28 var signPromise = crypto.subtle.sign(hmacSha1, hmacSha1Key, data); 28 // Operation does not support signing.
29 var verifyPromise = crypto.subtle.verify(hmacSha1, hmacSha1Key, expectedSign ature, data); 29 shouldThrow("crypto.subtle.sign({name: 'sha-1'}, keys.hmacSha1, data)");
30 var badVerifyPromise = crypto.subtle.verify(hmacSha1, hmacSha1Key, asciiToAr rayBuffer("badsignature"), data);
31 30
32 Promise.every(signPromise, verifyPromise, badVerifyPromise).then(function(re sults) 31 // Key's algorithm must match.
33 { 32 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'sha-256'}}, key s.hmacSha1, data)");
34 signResult = results[0];
35 verifyResult1 = results[1];
36 verifyResult2 = results[2];
37 33
38 shouldBe("signResult.byteLength", "17"); 34 // ---------------------------------------------------
39 shouldBe("verifyResult1", "true"); 35 // HMAC normalization failures (HmacParams)
40 shouldBe("verifyResult2", "false"); 36 // ---------------------------------------------------
37 shouldThrow("crypto.subtle.sign({name: 'hmac'}, keys.hmacSha1, data)");
38 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: 3}, keys.hmacSha1, data )");
39 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: null}, keys.hmacSha1, d ata)");
40 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {}}, keys.hmacSha1, dat a)");
41 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'foo'}}, keys.hm acSha1, data)");
42 shouldThrow("crypto.subtle.sign({name: 'hmac', hash: {name: 'AES-CBC'}}, key s.hmacSha1, data)");
41 43
42 finishJSTest(); 44 // ---------------------------------------------------
43 }); 45 // RSASSA-PKCS1-v1_5 normalization failures (RsaSsaParams)
44 }); 46 // ---------------------------------------------------
47 shouldThrow("crypto.subtle.sign({name: 'RSASSA-PKCS1-v1_5'}, keys.rsaSsaSha1 , data)");
48 shouldThrow("crypto.subtle.sign({name: 'RSASSA-PKCS1-v1_5', hash: 3}, keys.r saSsaSha1, data)");
49 shouldThrow("crypto.subtle.sign({name: 'RSASSA-PKCS1-v1_5', hash: null}, key s.rsaSsaSha1, data)");
50 shouldThrow("crypto.subtle.sign({name: 'RSASSA-PKCS1-v1_5', hash: {}}, keys. rsaSsaSha1, data)");
51 shouldThrow("crypto.subtle.sign({name: 'RSASSA-PKCS1-v1_5', hash: {name: 'fo o'}}, keys.rsaSsaSha1, data)");
52 shouldThrow("crypto.subtle.sign({name: 'RSASSA-PKCS1-v1_5', hash: {name: 'AE S-CBC'}}, keys.rsaSsaSha1, data)");
53
54 return crypto.subtle.sign(hmacSha1, keys.hmacSha1, data);
55 }).then(function(result) {
56 signResult = result;
57 shouldBe("signResult.byteLength", "17");
58
59 expectedSignature = asciiToArrayBuffer("signed HMAC:hello");
60 return crypto.subtle.verify(hmacSha1, keys.hmacSha1, expectedSignature, data );
61 }).then(function(result) {
62 verifyResult = result;
63 shouldBe("verifyResult", "true");
64
65 return crypto.subtle.verify(hmacSha1, keys.hmacSha1, asciiToArrayBuffer("bad signature"), data);
66 }).then(function(result) {
67 verifyResult = result;
68 shouldBe("verifyResult", "false");
69 }).then(finishJSTest, failAndFinishJSTest);
45 70
46 </script> 71 </script>
47 72
48 <script src="../fast/js/resources/js-test-post.js"></script> 73 <script src="../fast/js/resources/js-test-post.js"></script>
49 </body> 74 </body>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/resources/common.js ('k') | LayoutTests/crypto/sign-verify-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698