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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dana Keeler 2019-04-18 07:29:45 +00:00
Родитель f69345fb1f
Коммит e97d2e6b33
1 изменённых файлов: 4 добавлений и 1 удалений

Просмотреть файл

@ -44,10 +44,11 @@ function getReportCheck(expectReport, expectedError) {
function(request, response) { function(request, response) {
if (expectReport) { if (expectReport) {
let report = JSON.parse(readDataFromRequest(request)); 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); Assert.equal(report.errorCode, expectedError);
response.setStatusLine(null, 201, "Created"); response.setStatusLine(null, 201, "Created");
response.write("Created"); response.write("Created");
run_next_test(); // resolve a "test" waiting on this report to be sent/received
} else { } else {
do_throw("No report should have been received"); do_throw("No report should have been received");
} }
@ -133,11 +134,13 @@ function run_test() {
add_connection_test("good.include-subdomains.pinning.example.com", add_connection_test("good.include-subdomains.pinning.example.com",
PRErrorCodeSuccess, null, PRErrorCodeSuccess, null,
getReportCheck(true, PRErrorCodeSuccess)); 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. // Test sending a report where there is an error and a failed cert chain.
add_connection_test("expired.example.com", add_connection_test("expired.example.com",
SEC_ERROR_EXPIRED_CERTIFICATE, null, SEC_ERROR_EXPIRED_CERTIFICATE, null,
getReportCheck(true, SEC_ERROR_EXPIRED_CERTIFICATE)); getReportCheck(true, SEC_ERROR_EXPIRED_CERTIFICATE));
add_test(() => {}); // add a "test" so we wait for the report to be sent
run_next_test(); run_next_test();
} }