Bug 1169195 - Convert test_bug644006.html mochitest to an xpcshell test. r=keeler
authorCykesiopka <cykesiopka.bmo@gmail.com>
Tue, 02 Jun 2015 22:49:00 -0400
changeset 246999 ce10197e4eb3e638f186e40c81f100e0c4a08b9d
parent 246998 7f533d42cf01eef4a282ec3dea7dd5e4c3d318ee
child 247000 24d30440d9ebf0e1c2bb7e4f65169ec38ea285c5
push id28848
push userryanvm@gmail.com
push dateWed, 03 Jun 2015 20:00:13 +0000
treeherdermozilla-central@0920f2325a6d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskeeler
bugs1169195, 644006
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1169195 - Convert test_bug644006.html mochitest to an xpcshell test. r=keeler
security/manager/ssl/tests/mochitest/bugs/chrome.ini
security/manager/ssl/tests/mochitest/bugs/test_bug644006.html
security/manager/ssl/tests/unit/test_constructX509FromBase64.js
security/manager/ssl/tests/unit/xpcshell.ini
--- a/security/manager/ssl/tests/mochitest/bugs/chrome.ini
+++ b/security/manager/ssl/tests/mochitest/bugs/chrome.ini
@@ -1,9 +1,8 @@
 [DEFAULT]
 tags = psm
 skip-if = buildapp == 'b2g'
 
 [test_bug413909.html]
 skip-if = buildapp == 'mulet'
 [test_bug480619.html]
-[test_bug644006.html]
 [test_certificate_overrides.html]
rename from security/manager/ssl/tests/mochitest/bugs/test_bug644006.html
rename to security/manager/ssl/tests/unit/test_constructX509FromBase64.js
--- a/security/manager/ssl/tests/mochitest/bugs/test_bug644006.html
+++ b/security/manager/ssl/tests/unit/test_constructX509FromBase64.js
@@ -1,75 +1,73 @@
-<!DOCTYPE HTML>
-<html><head>
-  <title>Test bug 644006</title>
-  <script type="text/javascript"
-    src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css"
-    href="chrome://mochikit/content/tests/SimpleTest/test.css" />
-</head><body>
-<script type="application/javascript;version=1.7">
-const FAILURE = Components.results.NS_ERROR_FAILURE;
-const ILLEGAL_VALUE = Components.results.NS_ERROR_ILLEGAL_VALUE;
+// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+"use strict";
+
+// Checks that ConstructX509FromBase64() accepts valid input and rejects invalid
+// input.
 
-var certDB = Components.classes["@mozilla.org/security/x509certdb;1"]
-             .getService(Components.interfaces.nsIX509CertDB);
+do_get_profile(); // Must be called before getting nsIX509CertDB
+const certDB = Cc["@mozilla.org/security/x509certdb;1"]
+                 .getService(Ci.nsIX509CertDB);
 
-function excMessage(e)
-{
-  if ("message" in e && e.message !== null) {
+function excMessage(e) {
+  if (e.message) {
     let msg = e.message;
-    if ("data" in e && e.data !== null)
+    if (e.data) {
       msg = msg + ": " + e.data;
+    }
     return msg;
   } else {
     return e.toString();
   }
 }
 
-function testGood(data)
-{
-  let label = "CN=" + data.cn;
+function testGood(data) {
   try {
     let cert = certDB.constructX509FromBase64(data.cert);
-    is(cert.commonName, data.cn, label + ": constructX509 succeeded");
+    equal(cert.commonName, data.cn,
+          "Actual and expected commonName should match");
   } catch (e) {
-    ok(false, label + ": exception: " + excMessage(e));
+    do_print(`Exception: ${excMessage(e)}`)
+    ok(false, `Should not have gotten an exception for "CN=${data.cn}"`);
   }
 }
 
-function testBad(data)
-{
-  let label = uneval(data.t)
+function testBad(data) {
   try {
-    let cert = certDB.constructX509FromBase64(data.t);
-    ok(false, label + ": constructX509 succeeded");
+    let cert = certDB.constructX509FromBase64(data.input);
+    ok(false, `Should have gotten an exception for "${data.input}"`);
   } catch (e) {
-    is(e.result, data.e, label + ": exception: " + excMessage(e));
+    equal(e.result, data.result,
+          "Actual and expected exception result should match");
   }
 }
 
-const badCases = [
-  // wrong type or too short
-  { t: null, e: ILLEGAL_VALUE },
-  { t: "",   e: ILLEGAL_VALUE },
-  { t: "=",  e: ILLEGAL_VALUE },
-  { t: "==", e: ILLEGAL_VALUE },
-  // not base64
-  { t: "forty-four dead stone lions", e: ILLEGAL_VALUE },
-  // not a cert
-  { t: "Zm9ydHktZm91ciBkZWFkIHN0b25lIGxpb25z", e: FAILURE }
-];
+function run_test() {
+  const badCases = [
+    // Wrong type or too short
+    { input: null, result: Cr.NS_ERROR_ILLEGAL_VALUE },
+    { input: "", result: Cr.NS_ERROR_ILLEGAL_VALUE },
+    { input: "=", result: Cr.NS_ERROR_ILLEGAL_VALUE },
+    { input: "==", result: Cr.NS_ERROR_ILLEGAL_VALUE },
+    // Not base64
+    { input: "forty-four dead stone lions", result: Cr.NS_ERROR_ILLEGAL_VALUE },
+    // Not a cert
+    { input: "Zm9ydHktZm91ciBkZWFkIHN0b25lIGxpb25z", result: Cr.NS_ERROR_FAILURE }
+  ];
 
-// real certs with all three padding levels
-const goodCases = [
-  { cn: "A",   cert: "MIHhMIGcAgEAMA0GCSqGSIb3DQEBBQUAMAwxCjAIBgNVBAMTAUEwHhcNMTEwMzIzMjMyNTE3WhcNMTEwNDIyMjMyNTE3WjAMMQowCAYDVQQDEwFBMEwwDQYJKoZIhvcNAQEBBQADOwAwOAIxANFm7ZCfYNJViaDWTFuMClX3+9u18VFGiyLfM6xJrxir4QVtQC7VUC/WUGoBUs9COQIDAQABMA0GCSqGSIb3DQEBBQUAAzEAx2+gIwmuYjJO5SyabqIm4lB1MandHH1HQc0y0tUFshBOMESTzQRPSVwPn77a6R9t" },
-  { cn: "Bo",  cert: "MIHjMIGeAgEAMA0GCSqGSIb3DQEBBQUAMA0xCzAJBgNVBAMTAkJvMB4XDTExMDMyMzIzMjYwMloXDTExMDQyMjIzMjYwMlowDTELMAkGA1UEAxMCQm8wTDANBgkqhkiG9w0BAQEFAAM7ADA4AjEA1FoSl9w9HqMqVgk2K0J3OTiRsgHeNsQdPUl6S82ME33gH+E56PcWZA3nse+fpS3NAgMBAAEwDQYJKoZIhvcNAQEFBQADMQAo/e3BvQAmygiATljQ68tWPoWcbMwa1xxAvpWTEc1LOvMqeDBinBUqbAbSmPhGWb4=" },
-  { cn: "Cid", cert: "MIHlMIGgAgEAMA0GCSqGSIb3DQEBBQUAMA4xDDAKBgNVBAMTA0NpZDAeFw0xMTAzMjMyMzI2MzJaFw0xMTA0MjIyMzI2MzJaMA4xDDAKBgNVBAMTA0NpZDBMMA0GCSqGSIb3DQEBAQUAAzsAMDgCMQDUUxlF5xKN+8KCSsR83sN+SRwJmZdliXsnBB7PU0OgbmOWN0u8yehRkmu39kN9tzcCAwEAATANBgkqhkiG9w0BAQUFAAMxAJ3UScNqRcjHFrNu4nuwRldZLJlVJvRYXp982V4/kYodQEGN4gJ+Qyj+HTsaXy5x/w==" }
-];
+  // Real certs with all three padding levels
+  const goodCases = [
+    { cn: "A", cert: "MIHhMIGcAgEAMA0GCSqGSIb3DQEBBQUAMAwxCjAIBgNVBAMTAUEwHhcNMTEwMzIzMjMyNTE3WhcNMTEwNDIyMjMyNTE3WjAMMQowCAYDVQQDEwFBMEwwDQYJKoZIhvcNAQEBBQADOwAwOAIxANFm7ZCfYNJViaDWTFuMClX3+9u18VFGiyLfM6xJrxir4QVtQC7VUC/WUGoBUs9COQIDAQABMA0GCSqGSIb3DQEBBQUAAzEAx2+gIwmuYjJO5SyabqIm4lB1MandHH1HQc0y0tUFshBOMESTzQRPSVwPn77a6R9t" },
+    { cn: "Bo", cert: "MIHjMIGeAgEAMA0GCSqGSIb3DQEBBQUAMA0xCzAJBgNVBAMTAkJvMB4XDTExMDMyMzIzMjYwMloXDTExMDQyMjIzMjYwMlowDTELMAkGA1UEAxMCQm8wTDANBgkqhkiG9w0BAQEFAAM7ADA4AjEA1FoSl9w9HqMqVgk2K0J3OTiRsgHeNsQdPUl6S82ME33gH+E56PcWZA3nse+fpS3NAgMBAAEwDQYJKoZIhvcNAQEFBQADMQAo/e3BvQAmygiATljQ68tWPoWcbMwa1xxAvpWTEc1LOvMqeDBinBUqbAbSmPhGWb4=" },
+    { cn: "Cid", cert: "MIHlMIGgAgEAMA0GCSqGSIb3DQEBBQUAMA4xDDAKBgNVBAMTA0NpZDAeFw0xMTAzMjMyMzI2MzJaFw0xMTA0MjIyMzI2MzJaMA4xDDAKBgNVBAMTA0NpZDBMMA0GCSqGSIb3DQEBAQUAAzsAMDgCMQDUUxlF5xKN+8KCSsR83sN+SRwJmZdliXsnBB7PU0OgbmOWN0u8yehRkmu39kN9tzcCAwEAATANBgkqhkiG9w0BAQUFAAMxAJ3UScNqRcjHFrNu4nuwRldZLJlVJvRYXp982V4/kYodQEGN4gJ+Qyj+HTsaXy5x/w==" }
+  ];
 
-var i;
-for (i = 0; i < badCases.length; i++)
-  testBad(badCases[i]);
-for (i = 0; i < goodCases.length; i++)
-  testGood(goodCases[i]);
-</script>
-</body></html>
+  for (let badCase of badCases) {
+    testBad(badCase);
+  }
+  for (let goodCase of goodCases) {
+    testGood(goodCase);
+  }
+}
--- a/security/manager/ssl/tests/unit/xpcshell.ini
+++ b/security/manager/ssl/tests/unit/xpcshell.ini
@@ -123,8 +123,9 @@ skip-if = toolkit == 'gonk' && debug
 run-sequentially = hardcoded ports
 [test_cert_chains.js]
 run-sequentially = hardcoded ports
 [test_client_cert.js]
 run-sequentially = hardcoded ports
 [test_nsCertType.js]
 run-sequentially = hardcoded ports
 [test_nsIX509Cert_utf8.js]
+[test_constructX509FromBase64.js]