security/manager/ssl/tests/unit/test_ocsp_timeout.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/manager/ssl/tests/unit/test_ocsp_timeout.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +// -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 +// This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +// License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +// file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 +"use strict";
     1.9 +
    1.10 +function run_test() {
    1.11 +  do_get_profile();
    1.12 +
    1.13 +  add_tls_server_setup("OCSPStaplingServer");
    1.14 +
    1.15 +  let socket = Cc["@mozilla.org/network/server-socket;1"]
    1.16 +                 .createInstance(Ci.nsIServerSocket);
    1.17 +  socket.init(8080, true, -1);
    1.18 +
    1.19 +
    1.20 +  add_tests_in_mode(true, true);
    1.21 +  add_tests_in_mode(false, true);
    1.22 +  add_tests_in_mode(true, false);
    1.23 +  add_tests_in_mode(false, false);
    1.24 +
    1.25 +  add_test(function() { socket.close(); run_next_test(); });
    1.26 +  run_next_test();
    1.27 +}
    1.28 +
    1.29 +function add_tests_in_mode(useMozillaPKIX, useHardFail) {
    1.30 +  let startTime;
    1.31 +  add_test(function () {
    1.32 +    Services.prefs.setBoolPref("security.use_mozillapkix_verification",
    1.33 +                               useMozillaPKIX);
    1.34 +    Services.prefs.setBoolPref("security.OCSP.require", useHardFail);
    1.35 +    startTime = new Date();
    1.36 +    run_next_test();
    1.37 +  });
    1.38 +
    1.39 +  add_connection_test("ocsp-stapling-none.example.com", useHardFail
    1.40 +                      ? getXPCOMStatusFromNSS(SEC_ERROR_OCSP_SERVER_ERROR)
    1.41 +                      : Cr.NS_OK, clearSessionCache);
    1.42 +
    1.43 +  // Reset state
    1.44 +  add_test(function() {
    1.45 +    let endTime = new Date();
    1.46 +    // With OCSP hard-fail on, we timeout after 10 seconds.
    1.47 +    // With OCSP soft-fail, we timeout after 2 seconds.
    1.48 +    if (useHardFail) {
    1.49 +      do_check_true((endTime - startTime) > 10000);
    1.50 +    } else {
    1.51 +      do_check_true((endTime - startTime) > 2000);
    1.52 +    }
    1.53 +    // Make sure we didn't wait too long.
    1.54 +    // (Unfortunately, we probably can't have a tight upper bound on
    1.55 +    // how long is too long for this test, because we might be running
    1.56 +    // on slow hardware.)
    1.57 +    do_check_true((endTime - startTime) < 60000);
    1.58 +    clearOCSPCache();
    1.59 +    run_next_test();
    1.60 +  });
    1.61 +}

mercurial