summaryrefslogtreecommitdiffstats
path: root/devtools/shared/webconsole/test/xpcshell/test_security-info-certificate.js
blob: be8a5d8381555a94bf98017134ac0b652ab90079 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// Tests that NetworkHelper.parseCertificateInfo parses certificate information
// correctly.

const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");

Object.defineProperty(this, "NetworkHelper", {
  get: function() {
    return require("devtools/shared/webconsole/network-helper");
  },
  configurable: true,
  writeable: false,
  enumerable: true,
});

const DUMMY_CERT = {
  commonName: "cn",
  organization: "o",
  organizationalUnit: "ou",
  issuerCommonName: "issuerCN",
  issuerOrganization: "issuerO",
  issuerOrganizationUnit: "issuerOU",
  sha256Fingerprint: "qwertyuiopoiuytrewq",
  sha1Fingerprint: "qwertyuiop",
  validity: {
    notBeforeLocalDay: "yesterday",
    notAfterLocalDay: "tomorrow",
  },
};

function run_test() {
  info("Testing NetworkHelper.parseCertificateInfo.");

  const result = NetworkHelper.parseCertificateInfo(DUMMY_CERT);

  // Subject
  equal(
    result.subject.commonName,
    DUMMY_CERT.commonName,
    "Common name is correct."
  );
  equal(
    result.subject.organization,
    DUMMY_CERT.organization,
    "Organization is correct."
  );
  equal(
    result.subject.organizationUnit,
    DUMMY_CERT.organizationUnit,
    "Organizational unit is correct."
  );

  // Issuer
  equal(
    result.issuer.commonName,
    DUMMY_CERT.issuerCommonName,
    "Common name of the issuer is correct."
  );
  equal(
    result.issuer.organization,
    DUMMY_CERT.issuerOrganization,
    "Organization of the issuer is correct."
  );
  equal(
    result.issuer.organizationUnit,
    DUMMY_CERT.issuerOrganizationUnit,
    "Organizational unit of the issuer is correct."
  );

  // Validity
  equal(
    result.validity.start,
    DUMMY_CERT.validity.notBeforeLocalDay,
    "Start of the validity period is correct."
  );
  equal(
    result.validity.end,
    DUMMY_CERT.validity.notAfterLocalDay,
    "End of the validity period is correct."
  );

  // Fingerprints
  equal(
    result.fingerprint.sha1,
    DUMMY_CERT.sha1Fingerprint,
    "Certificate SHA1 fingerprint is correct."
  );
  equal(
    result.fingerprint.sha256,
    DUMMY_CERT.sha256Fingerprint,
    "Certificate SHA256 fingerprint is correct."
  );
}