summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_security-details.js
blob: 0dda9badf16a2552957c3cda70d529ecc80e02c1 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Test that Security details tab contains the expected data.
 */

add_task(async function () {
  await pushPref("security.pki.certificate_transparency.mode", 1);

  const { tab, monitor } = await initNetMonitor(CUSTOM_GET_URL, {
    requestCount: 1,
  });
  const { document, store, windowRequire } = monitor.panelWin;
  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");

  store.dispatch(Actions.batchEnable(false));

  info("Performing a secure request.");
  const REQUESTS_URL = "https://example.com" + CORS_SJS_PATH;
  const wait = waitForNetworkEvents(monitor, 1);
  await SpecialPowers.spawn(
    tab.linkedBrowser,
    [REQUESTS_URL],
    async function (url) {
      content.wrappedJSObject.performRequests(1, url);
    }
  );
  await wait;

  store.dispatch(Actions.toggleNetworkDetails());
  clickOnSidebarTab(document, "security");
  await waitUntil(() =>
    document.querySelector("#security-panel .security-info-value")
  );

  const tabpanel = document.querySelector("#security-panel");
  const textboxes = tabpanel.querySelectorAll(".security-info-value");

  // Connection
  // The protocol will be TLS but the exact version depends on which protocol
  // the test server example.com supports.
  const protocol = textboxes[0].textContent;
  ok(protocol.startsWith('"TLS'), "The protocol " + protocol + " seems valid.");

  // The cipher suite used by the test server example.com might change at any
  // moment but all of them should start with "TLS_".
  // http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
  const suite = textboxes[1].textContent;
  ok(suite.startsWith('"TLS_'), "The suite " + suite + " seems valid.");

  // Host
  is(
    tabpanel.querySelectorAll(".treeLabel.objectLabel")[1].textContent,
    "Host example.com:",
    "Label has the expected value."
  );
  // These two values can change. So only check they're not empty.
  ok(textboxes[2].textContent !== "", "Label value is not empty.");
  ok(textboxes[3].textContent !== "", "Label value is not empty.");
  is(textboxes[4].textContent, '"Disabled"', "Label has the expected value.");
  is(textboxes[5].textContent, '"Disabled"', "Label has the expected value.");

  // Cert
  is(
    textboxes[6].textContent,
    '"example.com"',
    "Label has the expected value."
  );
  is(
    textboxes[7].textContent,
    '"<Not Available>"',
    "Label has the expected value."
  );
  is(
    textboxes[8].textContent,
    '"<Not Available>"',
    "Label has the expected value."
  );

  is(
    textboxes[9].textContent,
    '"Temporary Certificate Authority"',
    "Label has the expected value."
  );
  is(
    textboxes[10].textContent,
    '"Mozilla Testing"',
    "Label has the expected value."
  );
  is(
    textboxes[11].textContent,
    '"Profile Guided Optimization"',
    "Label has the expected value."
  );

  // Locale sensitive and varies between timezones. Can't compare equality or
  // the test fails depending on which part of the world the test is executed.

  // cert validity begins
  isnot(textboxes[12].textContent, "", "Label was not empty.");
  // cert validity expires
  isnot(textboxes[13].textContent, "", "Label was not empty.");

  // cert sha1 fingerprint
  isnot(textboxes[14].textContent, "", "Label was not empty.");
  // cert sha256 fingerprint
  isnot(textboxes[15].textContent, "", "Label was not empty.");

  // Certificate transparency
  isnot(textboxes[16].textContent, "", "Label was not empty.");

  await teardown(monitor);
});