PageRenderTime 21ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/security/manager/ssl/tests/mochitest/bugs/test_bug644006.html

http://github.com/zpao/v8monkey
HTML | 75 lines | 68 code | 7 blank | 0 comment | 0 complexity | 4e04276128df3fa25a605787a3de2f07 MD5 | raw file
 1<!DOCTYPE HTML>
 2<html><head>
 3  <title>Test bug 644006</title>
 4  <script type="text/javascript"
 5    src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
 6  <link rel="stylesheet" type="text/css"
 7    href="chrome://mochikit/content/tests/SimpleTest/test.css" />
 8</head><body>
 9<script type="application/javascript;version=1.7">
10const FAILURE = Components.results.NS_ERROR_FAILURE;
11const ILLEGAL_VALUE = Components.results.NS_ERROR_ILLEGAL_VALUE;
12
13var certDB = Components.classes["@mozilla.org/security/x509certdb;1"]
14             .getService(Components.interfaces.nsIX509CertDB);
15
16function excMessage(e)
17{
18  if ("message" in e && e.message !== null) {
19    let msg = e.message;
20    if ("data" in e && e.data !== null)
21      msg = msg + ": " + e.data;
22    return msg;
23  } else {
24    return e.toString();
25  }
26}
27
28function testGood(data)
29{
30  let label = "CN=" + data.cn;
31  try {
32    let cert = certDB.constructX509FromBase64(data.cert);
33    is(cert.commonName, data.cn, label + ": constructX509 succeeded");
34  } catch (e) {
35    ok(false, label + ": exception: " + excMessage(e));
36  }
37}
38
39function testBad(data)
40{
41  let label = uneval(data.t)
42  try {
43    let cert = certDB.constructX509FromBase64(data.t);
44    ok(false, label + ": constructX509 succeeded");
45  } catch (e) {
46    is(e.result, data.e, label + ": exception: " + excMessage(e));
47  }
48}
49
50const badCases = [
51  // wrong type or too short
52  { t: null, e: ILLEGAL_VALUE },
53  { t: "",   e: ILLEGAL_VALUE },
54  { t: "=",  e: ILLEGAL_VALUE },
55  { t: "==", e: ILLEGAL_VALUE },
56  // not base64
57  { t: "forty-four dead stone lions", e: ILLEGAL_VALUE },
58  // not a cert
59  { t: "Zm9ydHktZm91ciBkZWFkIHN0b25lIGxpb25z", e: FAILURE }
60];
61
62// real certs with all three padding levels
63const goodCases = [
64  { cn: "A",   cert: "MIHhMIGcAgEAMA0GCSqGSIb3DQEBBQUAMAwxCjAIBgNVBAMTAUEwHhcNMTEwMzIzMjMyNTE3WhcNMTEwNDIyMjMyNTE3WjAMMQowCAYDVQQDEwFBMEwwDQYJKoZIhvcNAQEBBQADOwAwOAIxANFm7ZCfYNJViaDWTFuMClX3+9u18VFGiyLfM6xJrxir4QVtQC7VUC/WUGoBUs9COQIDAQABMA0GCSqGSIb3DQEBBQUAAzEAx2+gIwmuYjJO5SyabqIm4lB1MandHH1HQc0y0tUFshBOMESTzQRPSVwPn77a6R9t" },
65  { cn: "Bo",  cert: "MIHjMIGeAgEAMA0GCSqGSIb3DQEBBQUAMA0xCzAJBgNVBAMTAkJvMB4XDTExMDMyMzIzMjYwMloXDTExMDQyMjIzMjYwMlowDTELMAkGA1UEAxMCQm8wTDANBgkqhkiG9w0BAQEFAAM7ADA4AjEA1FoSl9w9HqMqVgk2K0J3OTiRsgHeNsQdPUl6S82ME33gH+E56PcWZA3nse+fpS3NAgMBAAEwDQYJKoZIhvcNAQEFBQADMQAo/e3BvQAmygiATljQ68tWPoWcbMwa1xxAvpWTEc1LOvMqeDBinBUqbAbSmPhGWb4=" },
66  { cn: "Cid", cert: "MIHlMIGgAgEAMA0GCSqGSIb3DQEBBQUAMA4xDDAKBgNVBAMTA0NpZDAeFw0xMTAzMjMyMzI2MzJaFw0xMTA0MjIyMzI2MzJaMA4xDDAKBgNVBAMTA0NpZDBMMA0GCSqGSIb3DQEBAQUAAzsAMDgCMQDUUxlF5xKN+8KCSsR83sN+SRwJmZdliXsnBB7PU0OgbmOWN0u8yehRkmu39kN9tzcCAwEAATANBgkqhkiG9w0BAQUFAAMxAJ3UScNqRcjHFrNu4nuwRldZLJlVJvRYXp982V4/kYodQEGN4gJ+Qyj+HTsaXy5x/w==" }
67];
68
69var i;
70for (i = 0; i < badCases.length; i++)
71  testBad(badCases[i]);
72for (i = 0; i < goodCases.length; i++)
73  testGood(goodCases[i]);
74</script>
75</body></html>