Bug 1544244 - fix cookie-checking in test_toolkit_securityreporter.js r=mgoodwin
authorDana Keeler <dkeeler@mozilla.com>
Thu, 18 Apr 2019 07:29:45 +0000
changeset 470068 2091fc58b1314cd0579eb04e2140b3ad563bbb16
parent 470067 9dafc71a1f375a6865521e7e26073394b0c8cd0b
child 470069 6583b10db8d71d9a10024d9e5f2538ca769592a5
push id112843
push useraiakab@mozilla.com
push dateFri, 19 Apr 2019 09:50:22 +0000
treeherdermozilla-inbound@c06f27cbfe40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgoodwin
bugs1544244
milestone68.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 1544244 - fix cookie-checking in test_toolkit_securityreporter.js r=mgoodwin Before this patch, test_toolkit_securityreporter.js would unconditionally try to get the value of the "Cookie" header. If a header isn't available, httpd.js apparently throws an exception. Interestingly, exceptions thrown in httpd.js path handlers aren't reported to the test framework, so we weren't aware of this. Additionally, the test didn't have any way of waiting until the security report it was expecting had arrived, so it just continued on and "succeeded". This patch addresses these issues by using "throws" to make sure no cookies are available and by inserting extra add_test/run_next_test pairs when the test is waiting for a report. Differential Revision: https://phabricator.services.mozilla.com/D27613
security/manager/ssl/tests/unit/test_toolkit_securityreporter.js
--- a/security/manager/ssl/tests/unit/test_toolkit_securityreporter.js
+++ b/security/manager/ssl/tests/unit/test_toolkit_securityreporter.js
@@ -39,20 +39,21 @@ var server;
 // expected.
 function getReportCheck(expectReport, expectedError) {
   return function sendReportWithInfo(transportSecurityInfo) {
     // register a path handler on the server
     server.registerPathHandler("/submit/sslreports",
                               function(request, response) {
       if (expectReport) {
         let report = JSON.parse(readDataFromRequest(request));
-        Assert.equal(request.getHeader("Cookie"), "", "No cookie sent.");
+        throws(() => request.getHeader("Cookie"), /NS_ERROR_NOT_AVAILABLE/);
         Assert.equal(report.errorCode, expectedError);
         response.setStatusLine(null, 201, "Created");
         response.write("Created");
+        run_next_test(); // resolve a "test" waiting on this report to be sent/received
       } else {
         do_throw("No report should have been received");
       }
     });
 
     reporter.reportTLSError(transportSecurityInfo, "example.com", -1);
   };
 }
@@ -128,16 +129,18 @@ function run_test() {
     run_next_test();
   });
 
   // Test sending a report with no error. This allows us to check the case
   // where there is no failed cert chain
   add_connection_test("good.include-subdomains.pinning.example.com",
                       PRErrorCodeSuccess, null,
                       getReportCheck(true, PRErrorCodeSuccess));
+  add_test(() => {}); // add a "test" so we wait for the report to be sent
 
   // Test sending a report where there is an error and a failed cert chain.
   add_connection_test("expired.example.com",
                       SEC_ERROR_EXPIRED_CERTIFICATE, null,
                       getReportCheck(true, SEC_ERROR_EXPIRED_CERTIFICATE));
+  add_test(() => {}); // add a "test" so we wait for the report to be sent
 
   run_next_test();
 }