Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Must be packed to ../enterprise_platform_keys.crx using the private key | 5 // Must be packed to ../enterprise_platform_keys.crx using the private key |
| 6 // ../enterprise_platform_keys.pem . | 6 // ../enterprise_platform_keys.pem . |
| 7 | 7 |
| 8 'use strict'; | 8 'use strict'; |
| 9 | 9 |
| 10 var assertEq = chrome.test.assertEq; | 10 var assertEq = chrome.test.assertEq; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 getUserToken(function(userToken) { | 253 getUserToken(function(userToken) { |
| 254 if (!userToken) | 254 if (!userToken) |
| 255 fail('no user token'); | 255 fail('no user token'); |
| 256 if (userToken.id != 'user') | 256 if (userToken.id != 'user') |
| 257 fail('token is not named "user".'); | 257 fail('token is not named "user".'); |
| 258 | 258 |
| 259 callback(userToken); | 259 callback(userToken); |
| 260 }); | 260 }); |
| 261 } | 261 } |
| 262 | 262 |
| 263 function checkAlgorithmIsCopiedOnRead(key) { | |
| 264 var algorithm = key.algorithm; | |
| 265 var originalAlgorithm = { | |
| 266 name: algorithm.name, | |
| 267 modulusLength: algorithm.modulusLength, | |
| 268 publicExponent: algorithm.publicExponent, | |
| 269 hash: {name: algorithm.hash.name} | |
| 270 }; | |
| 271 var originalModulusLength = algorithm.modulusLength; | |
| 272 algorithm.hash.name = null; | |
| 273 algorithm.hash = null; | |
| 274 algorithm.name = null; | |
| 275 algorithm.modulusLength = null; | |
| 276 algorithm.publicExponent = null; | |
| 277 assertEq(originalAlgorithm, key.algorithm); | |
| 278 } | |
| 279 | |
| 280 function checkPropertyIsReadOnly(object, key) { | |
| 281 var original = object[key]; | |
| 282 try { | |
| 283 object[key] = {}; | |
| 284 fail('Expected that the property is read only and an exception to ' + | |
|
bartfab (slow)
2014/06/18 16:19:06
Nit: Grammar: "Expected the property to be read-on
| |
| 285 'be thrown'); | |
| 286 } catch (error) { | |
| 287 assertEq(original, object[key]); | |
| 288 } | |
| 289 } | |
| 290 | |
| 291 function checkKeyPairCommonFormat(keyPair) { | |
| 292 checkPropertyIsReadOnly(keyPair, 'privateKey'); | |
| 293 var privateKey = keyPair.privateKey; | |
| 294 assertEq('private', privateKey.type); | |
| 295 assertEq(false, privateKey.extractable); | |
| 296 checkPropertyIsReadOnly(privateKey, 'algorithm'); | |
| 297 checkAlgorithmIsCopiedOnRead(privateKey); | |
| 298 | |
| 299 checkPropertyIsReadOnly(keyPair, 'publicKey'); | |
| 300 var publicKey = keyPair.publicKey; | |
| 301 assertEq('public', publicKey.type); | |
| 302 assertEq(true, publicKey.extractable); | |
| 303 checkPropertyIsReadOnly(publicKey, 'algorithm'); | |
| 304 checkAlgorithmIsCopiedOnRead(publicKey); | |
| 305 } | |
| 306 | |
| 263 function runTests(userToken) { | 307 function runTests(userToken) { |
| 264 chrome.test.runTests([ | 308 chrome.test.runTests([ |
| 265 function hasSubtleCryptoMethods() { | 309 function hasSubtleCryptoMethods() { |
| 266 assertTrue(!!userToken.subtleCrypto.generateKey, | 310 assertTrue(!!userToken.subtleCrypto.generateKey, |
| 267 "user token has no generateKey method"); | 311 "user token has no generateKey method"); |
| 268 assertTrue(!!userToken.subtleCrypto.sign, | 312 assertTrue(!!userToken.subtleCrypto.sign, |
| 269 "user token has no sign method"); | 313 "user token has no sign method"); |
| 270 assertTrue(!!userToken.subtleCrypto.exportKey, | 314 assertTrue(!!userToken.subtleCrypto.exportKey, |
| 271 "user token has no exportKey method"); | 315 "user token has no exportKey method"); |
| 272 succeed(); | 316 succeed(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 301 userToken.subtleCrypto.generateKey(algorithm, false, ["sign"]) | 345 userToken.subtleCrypto.generateKey(algorithm, false, ["sign"]) |
| 302 .then(callbackPass(function(keyPair) { | 346 .then(callbackPass(function(keyPair) { |
| 303 assertTrue(!!keyPair, "No key pair."); | 347 assertTrue(!!keyPair, "No key pair."); |
| 304 cachedKeyPair = keyPair; | 348 cachedKeyPair = keyPair; |
| 305 return userToken.subtleCrypto.exportKey('spki', | 349 return userToken.subtleCrypto.exportKey('spki', |
| 306 keyPair.publicKey); | 350 keyPair.publicKey); |
| 307 }), | 351 }), |
| 308 function(error) { fail("GenerateKey failed: " + error); }) | 352 function(error) { fail("GenerateKey failed: " + error); }) |
| 309 .then(callbackPass(function(publicKeySpki) { | 353 .then(callbackPass(function(publicKeySpki) { |
| 310 // Ensure that the returned key pair has the expected format. | 354 // Ensure that the returned key pair has the expected format. |
| 355 // Some parameter independent checks: | |
| 356 checkKeyPairCommonFormat(cachedKeyPair); | |
| 357 | |
| 311 // Checks depending on the generateKey arguments: | 358 // Checks depending on the generateKey arguments: |
| 312 var privateKey = cachedKeyPair.privateKey; | 359 var privateKey = cachedKeyPair.privateKey; |
| 313 assertEq(['sign'], privateKey.usages); | 360 assertEq(['sign'], privateKey.usages); |
| 314 assertEq(algorithm, privateKey.algorithm); | 361 assertEq(algorithm, privateKey.algorithm); |
| 315 | 362 |
| 316 var publicKey = cachedKeyPair.publicKey; | 363 var publicKey = cachedKeyPair.publicKey; |
| 317 assertEq([], publicKey.usages); | 364 assertEq([], publicKey.usages); |
| 318 assertEq(algorithm, publicKey.algorithm); | 365 assertEq(algorithm, publicKey.algorithm); |
| 319 | 366 |
| 320 cachedSpki = publicKeySpki; | 367 cachedSpki = publicKeySpki; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 callbackFail('Certificate is not a valid X.509 certificate.')); | 519 callbackFail('Certificate is not a valid X.509 certificate.')); |
| 473 }, | 520 }, |
| 474 function getCertsInvalidToken() { | 521 function getCertsInvalidToken() { |
| 475 chrome.enterprise.platformKeys.getCertificates( | 522 chrome.enterprise.platformKeys.getCertificates( |
| 476 'invalid token id', callbackFail('The token is not valid.')); | 523 'invalid token id', callbackFail('The token is not valid.')); |
| 477 } | 524 } |
| 478 ]); | 525 ]); |
| 479 } | 526 } |
| 480 | 527 |
| 481 beforeTests(runTests); | 528 beforeTests(runTests); |
| OLD | NEW |