1 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 // Checks that ConstructX509FromBase64() accepts valid input and rejects invalid
10 do_get_profile(); // Must be called before getting nsIX509CertDB
11 const certDB = Cc["@mozilla.org/security/x509certdb;1"].getService(
15 function excMessage(e) {
19 msg = msg + ": " + e.data;
27 function testGood(data) {
29 let cert = certDB.constructX509FromBase64(data.cert);
33 "Actual and expected commonName should match"
36 info(`Exception: ${excMessage(e)}`);
37 ok(false, `Should not have gotten an exception for "CN=${data.cn}"`);
41 function testBad(data) {
43 () => certDB.constructX509FromBase64(data.input),
45 `Should get "${data.result}" for "${data.input}"`
51 // Wrong type or too short
52 { input: null, result: /NS_ERROR_ILLEGAL_VALUE/ },
53 { input: "", result: /NS_ERROR_ILLEGAL_VALUE/ },
54 { input: "=", result: /NS_ERROR_ILLEGAL_VALUE/ },
55 { input: "==", result: /NS_ERROR_ILLEGAL_VALUE/ },
57 { input: "forty-four dead stone lions", result: /NS_ERROR_ILLEGAL_VALUE/ },
60 input: "Zm9ydHktZm91ciBkZWFkIHN0b25lIGxpb25z",
61 result: /NS_ERROR_FAILURE/,
65 // Real certs with all three padding levels
69 cert: "MIHhMIGcAgEAMA0GCSqGSIb3DQEBBQUAMAwxCjAIBgNVBAMTAUEwHhcNMTEwMzIzMjMyNTE3WhcNMTEwNDIyMjMyNTE3WjAMMQowCAYDVQQDEwFBMEwwDQYJKoZIhvcNAQEBBQADOwAwOAIxANFm7ZCfYNJViaDWTFuMClX3+9u18VFGiyLfM6xJrxir4QVtQC7VUC/WUGoBUs9COQIDAQABMA0GCSqGSIb3DQEBBQUAAzEAx2+gIwmuYjJO5SyabqIm4lB1MandHH1HQc0y0tUFshBOMESTzQRPSVwPn77a6R9t",
73 cert: "MIHjMIGeAgEAMA0GCSqGSIb3DQEBBQUAMA0xCzAJBgNVBAMTAkJvMB4XDTExMDMyMzIzMjYwMloXDTExMDQyMjIzMjYwMlowDTELMAkGA1UEAxMCQm8wTDANBgkqhkiG9w0BAQEFAAM7ADA4AjEA1FoSl9w9HqMqVgk2K0J3OTiRsgHeNsQdPUl6S82ME33gH+E56PcWZA3nse+fpS3NAgMBAAEwDQYJKoZIhvcNAQEFBQADMQAo/e3BvQAmygiATljQ68tWPoWcbMwa1xxAvpWTEc1LOvMqeDBinBUqbAbSmPhGWb4=",
77 cert: "MIHlMIGgAgEAMA0GCSqGSIb3DQEBBQUAMA4xDDAKBgNVBAMTA0NpZDAeFw0xMTAzMjMyMzI2MzJaFw0xMTA0MjIyMzI2MzJaMA4xDDAKBgNVBAMTA0NpZDBMMA0GCSqGSIb3DQEBAQUAAzsAMDgCMQDUUxlF5xKN+8KCSsR83sN+SRwJmZdliXsnBB7PU0OgbmOWN0u8yehRkmu39kN9tzcCAwEAATANBgkqhkiG9w0BAQUFAAMxAJ3UScNqRcjHFrNu4nuwRldZLJlVJvRYXp982V4/kYodQEGN4gJ+Qyj+HTsaXy5x/w==",
81 for (let badCase of badCases) {
84 for (let goodCase of goodCases) {