OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 'use strict'; | |
6 | |
7 var assertEq = chrome.test.assertEq; | |
8 var assertTrue = chrome.test.assertTrue; | |
9 var callbackPass = chrome.test.callbackPass; | |
10 var succeed = chrome.test.succeed; | |
11 | |
12 var data = { | |
13 // X.509 certificate in DER encoding issued by 'root.pem' which is set to be | |
14 // trusted by the test setup. | |
15 // Generated by create_test_certs.sh . | |
16 l1_leaf_cert: 'l1_leaf.der', | |
17 }; | |
18 | |
19 // Reads the binary file at |path| and passes it as a Uint8Array to |callback|. | |
20 function readFile(path, callback) { | |
21 var oReq = new XMLHttpRequest(); | |
22 oReq.responseType = "arraybuffer"; | |
23 oReq.open("GET", path, true /* asynchronous */); | |
24 oReq.onload = function() { | |
25 var arrayBuffer = oReq.response; | |
26 if (arrayBuffer) { | |
27 callback(new Uint8Array(arrayBuffer)); | |
28 } else { | |
29 callback(null); | |
30 } | |
31 }; | |
32 oReq.send(null); | |
33 } | |
34 | |
35 // For each key in dictionary, replaces the path dictionary[key] by the content | |
36 // of the resource located at that path stored in a Uint8Array. | |
37 function readData(dictionary, callback) { | |
bartfab (slow)
2015/09/04 09:21:57
Nit: Do we really need all this if in the end, we
pneubeck (no reviews)
2015/09/07 17:21:33
If possible I'd like to share this with the same f
| |
38 var keys = Object.keys(dictionary); | |
39 function recurse(index) { | |
40 if (index >= keys.length) { | |
bartfab (slow)
2015/09/04 09:21:57
Nit: How is ">" possible?
pneubeck (no reviews)
2015/09/07 17:21:33
Done.
| |
41 callback(); | |
42 return; | |
43 } | |
44 var key = keys[index]; | |
45 var path = dictionary[key]; | |
46 readFile(path, function(array) { | |
47 assertTrue(!!array); | |
48 dictionary[key] = array; | |
49 recurse(index + 1); | |
50 }); | |
51 } | |
52 | |
53 recurse(0); | |
bartfab (slow)
2015/09/04 09:21:57
Whatever happened to good old for loops?
pneubeck (no reviews)
2015/09/07 17:21:33
If we had an asynchronous for loop, I'd be happy t
| |
54 } | |
55 | |
56 var signDigestRequest; | |
57 var signCallback; | |
58 | |
59 function register() { | |
60 assertTrue(!!chrome.certificateProvider); | |
61 assertTrue(!!chrome.certificateProvider.onCertificatesRequested); | |
62 assertTrue(!!chrome.certificateProvider.onSignDigestRequested); | |
63 | |
64 var validCertInfo = { | |
65 certificate: data.l1_leaf_cert.buffer, | |
66 supportedHashes: ['SHA1'] | |
67 }; | |
68 var invalidCert = new Uint8Array([1, 2, 3, 4, 5]); | |
69 var invalidCertInfo = { | |
70 certificate: invalidCert.buffer, | |
71 supportedHashes: ['SHA256'] | |
72 }; | |
73 | |
74 function checkResult(rejectedCerts) { | |
75 assertEq(1, rejectedCerts.length); | |
76 } | |
bartfab (slow)
2015/09/04 09:21:57
Should this not verify which cert was rejected?
pneubeck (no reviews)
2015/09/07 17:21:33
Requires comparing arrays, which the standard java
| |
77 | |
78 function reportCertificates(reportCallback) { | |
79 reportCallback([validCertInfo, invalidCertInfo], callbackPass(checkResult)); | |
80 } | |
81 | |
82 chrome.certificateProvider.onCertificatesRequested.addListener( | |
83 callbackPass(reportCertificates)); | |
84 | |
85 chrome.certificateProvider.onSignDigestRequested.addListener(function( | |
86 request, callback) { | |
87 signCallback = callback; | |
88 signDigestRequest = request; | |
89 succeed(); | |
90 }); | |
91 | |
92 succeed(); | |
93 } | |
94 | |
95 function replyWithSignature(signature) { | |
96 signCallback(signature.buffer, function() {}); | |
97 } | |
98 | |
99 function replyWithSignatureSecondTime() { | |
100 var signature = new Uint8Array([1,2,3]); | |
101 try { | |
102 signCallback(signature.buffer, function() {}); | |
103 } catch (e) { | |
104 return true; | |
105 } | |
106 return false; | |
107 } | |
108 | |
109 function runTest() { | |
110 chrome.test.runTests([register]); | |
111 } | |
112 | |
113 readData(data, runTest); | |
OLD | NEW |