Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 // -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 "use strict";
7 function run_test() {
8 do_get_profile();
10 add_tls_server_setup("OCSPStaplingServer");
12 let socket = Cc["@mozilla.org/network/server-socket;1"]
13 .createInstance(Ci.nsIServerSocket);
14 socket.init(8080, true, -1);
17 add_tests_in_mode(true, true);
18 add_tests_in_mode(false, true);
19 add_tests_in_mode(true, false);
20 add_tests_in_mode(false, false);
22 add_test(function() { socket.close(); run_next_test(); });
23 run_next_test();
24 }
26 function add_tests_in_mode(useMozillaPKIX, useHardFail) {
27 let startTime;
28 add_test(function () {
29 Services.prefs.setBoolPref("security.use_mozillapkix_verification",
30 useMozillaPKIX);
31 Services.prefs.setBoolPref("security.OCSP.require", useHardFail);
32 startTime = new Date();
33 run_next_test();
34 });
36 add_connection_test("ocsp-stapling-none.example.com", useHardFail
37 ? getXPCOMStatusFromNSS(SEC_ERROR_OCSP_SERVER_ERROR)
38 : Cr.NS_OK, clearSessionCache);
40 // Reset state
41 add_test(function() {
42 let endTime = new Date();
43 // With OCSP hard-fail on, we timeout after 10 seconds.
44 // With OCSP soft-fail, we timeout after 2 seconds.
45 if (useHardFail) {
46 do_check_true((endTime - startTime) > 10000);
47 } else {
48 do_check_true((endTime - startTime) > 2000);
49 }
50 // Make sure we didn't wait too long.
51 // (Unfortunately, we probably can't have a tight upper bound on
52 // how long is too long for this test, because we might be running
53 // on slow hardware.)
54 do_check_true((endTime - startTime) < 60000);
55 clearOCSPCache();
56 run_next_test();
57 });
58 }