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

Unified Diff: chrome/test/data/extensions/api_test/enterprise_platform_keys/basic.js

Issue 336423004: enterprise.platformKeys: Cleanup the API test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comment. 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
« no previous file with comments | « chrome/test/data/extensions/api_test/enterprise_platform_keys.crx ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/api_test/enterprise_platform_keys/basic.js
diff --git a/chrome/test/data/extensions/api_test/enterprise_platform_keys/basic.js b/chrome/test/data/extensions/api_test/enterprise_platform_keys/basic.js
index e4f8995832145c08fb40f37dad4ea431bc7cb9ce..ab3ff6b22cbe043cdebffbea2e27d59dcfa8c073 100644
--- a/chrome/test/data/extensions/api_test/enterprise_platform_keys/basic.js
+++ b/chrome/test/data/extensions/api_test/enterprise_platform_keys/basic.js
@@ -5,6 +5,8 @@
// Must be packed to ../enterprise_platform_keys.crx using the private key
// ../enterprise_platform_keys.pem .
+'use strict';
+
var assertEq = chrome.test.assertEq;
var assertTrue = chrome.test.assertTrue;
var assertThrows = chrome.test.assertThrows;
@@ -250,9 +252,9 @@ function beforeTests(callback) {
getUserToken(function(userToken) {
if (!userToken)
- chrome.test.fail('no user token');
+ fail('no user token');
if (userToken.id != 'user')
- chrome.test.fail('token is not named "user".');
+ fail('token is not named "user".');
callback(userToken);
});
@@ -278,12 +280,19 @@ function runTests(userToken) {
name: "RSASSA-PKCS1-v1_5",
// RsaHashedKeyGenParams
modulusLength: 512,
- publicExponent:
- new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537
+ // Equivalent to 65537
+ publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
hash: {
name: "SHA-1",
}
};
+ // Ensure that this algorithm object is not modified, so that later
+ // comparisons really do the right thing.
+ Object.freeze(algorithm.hash);
+ Object.freeze(algorithm);
+
+ var signParams = {name: 'RSASSA-PKCS1-v1_5'};
+
// Some random data to sign.
var data = new Uint8Array([0, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6]);
var cachedKeyPair;
@@ -296,18 +305,23 @@ function runTests(userToken) {
return userToken.subtleCrypto.exportKey('spki',
keyPair.publicKey);
}),
- function(error) {
- assertTrue(false, "GenerateKey failed: " + error);
- })
+ function(error) { fail("GenerateKey failed: " + error); })
.then(callbackPass(function(publicKeySpki) {
+ // Ensure that the returned key pair has the expected format.
+ // Checks depending on the generateKey arguments:
+ var privateKey = cachedKeyPair.privateKey;
+ assertEq(['sign'], privateKey.usages);
+ assertEq(algorithm, privateKey.algorithm);
+
+ var publicKey = cachedKeyPair.publicKey;
+ assertEq([], publicKey.usages);
+ assertEq(algorithm, publicKey.algorithm);
+
cachedSpki = publicKeySpki;
- var signParams = {name: 'RSASSA-PKCS1-v1_5'};
return userToken.subtleCrypto.sign(
- signParams, cachedKeyPair.privateKey, data);
+ signParams, privateKey, data);
}),
- function(error) {
- assertTrue(false, "Export failed: " + error);
- })
+ function(error) { fail("Export failed: " + error); })
.then(callbackPass(function(signature) {
var importParams = {
name: algorithm.name,
@@ -322,7 +336,7 @@ function runTests(userToken) {
return window.crypto.subtle.importKey(
"spki", cachedSpki, importParams, false, ["verify"]);
}),
- function(error) { assertTrue(false, "Sign failed: " + error); })
+ function(error) { fail("Sign failed: " + error); })
.then(callbackPass(function(webCryptoPublicKey) {
assertTrue(!!webCryptoPublicKey);
assertEq(algorithm.modulusLength,
@@ -332,21 +346,17 @@ function runTests(userToken) {
return window.crypto.subtle.verify(
algorithm, webCryptoPublicKey, cachedSignature, data);
}),
- function(error) {
- assertTrue(false, "Import failed: " + error);
- })
+ function(error) { fail("Import failed: " + error); })
.then(callbackPass(function(success) {
assertEq(true, success, "Signature invalid.");
// Try to sign data with the same key a second time, which
// must fail.
return userToken.subtleCrypto.sign(
- {}, cachedKeyPair.privateKey, data);
+ signParams, cachedKeyPair.privateKey, data);
}),
- function(error) {
- assertTrue(false, "Verification failed: " + error);
- })
+ function(error) { fail("Verification failed: " + error); })
.then(function(signature) {
- assertTrue(false, "Second sign call was expected to fail.");
+ fail("Second sign call was expected to fail.");
}, callbackPass(function(error) {
assertTrue(error instanceof Error);
assertEq(
@@ -392,9 +402,7 @@ function runTests(userToken) {
}
};
userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then(
- function(keyPair) {
- assertTrue(false, 'generateKey was expected to fail');
- },
+ function(keyPair) { fail('generateKey was expected to fail'); },
callbackPass(function(error) {
assertTrue(error instanceof Error);
assertEq('A required parameter was missing or out-of-range',
@@ -411,9 +419,7 @@ function runTests(userToken) {
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
};
userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then(
- function(keyPair) {
- assertTrue(false, 'generateKey was expected to fail');
- },
+ function(keyPair) { fail('generateKey was expected to fail'); },
callbackPass(function(error) {
assertEq(
new Error('Error: A required parameter was missing our out-of-range'),
@@ -431,9 +437,7 @@ function runTests(userToken) {
publicExponent: new Uint8Array([0x01, 0x01]),
};
userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then(
- function(keyPair) {
- assertTrue(false, 'generateKey was expected to fail');
- },
+ function(keyPair) { fail('generateKey was expected to fail'); },
callbackPass(function(error) {
assertTrue(error instanceof Error);
assertEq('A required parameter was missing or out-of-range',
« no previous file with comments | « chrome/test/data/extensions/api_test/enterprise_platform_keys.crx ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698