1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/manager/ssl/tests/unit/test_ocsp_stapling_with_intermediate.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 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 +// In which we connect to a server that staples an OCSP response for a 1.11 +// certificate signed by an intermediate that has an OCSP AIA to ensure 1.12 +// that an OCSP request is not made for the intermediate. 1.13 + 1.14 +let gOCSPRequestCount = 0; 1.15 + 1.16 +function add_ocsp_test(aHost, aExpectedResult) { 1.17 + add_connection_test(aHost, aExpectedResult, 1.18 + function() { 1.19 + clearOCSPCache(); 1.20 + clearSessionCache(); 1.21 + }); 1.22 +} 1.23 + 1.24 +function run_test() { 1.25 + do_get_profile(); 1.26 + Services.prefs.setBoolPref("security.ssl.enable_ocsp_stapling", true); 1.27 + 1.28 + let ocspResponder = new HttpServer(); 1.29 + ocspResponder.registerPrefixHandler("/", function(request, response) { 1.30 + gOCSPRequestCount++; 1.31 + response.setStatusLine(request.httpVersion, 500, "Internal Server Error"); 1.32 + let body = "Refusing to return a response"; 1.33 + response.bodyOutputStream.write(body, body.length); 1.34 + }); 1.35 + ocspResponder.start(8080); 1.36 + 1.37 + add_tls_server_setup("OCSPStaplingServer"); 1.38 + 1.39 + add_tests_in_mode(true); 1.40 + add_tests_in_mode(false); 1.41 + 1.42 + add_test(function () { ocspResponder.stop(run_next_test); }); 1.43 + add_test(function() { 1.44 + do_check_eq(gOCSPRequestCount, 0); 1.45 + run_next_test(); 1.46 + }); 1.47 + run_next_test(); 1.48 +} 1.49 + 1.50 +function add_tests_in_mode(useMozillaPKIX) { 1.51 + add_test(function () { 1.52 + Services.prefs.setBoolPref("security.use_mozillapkix_verification", 1.53 + useMozillaPKIX); 1.54 + run_next_test(); 1.55 + }); 1.56 + 1.57 + add_ocsp_test("ocsp-stapling-with-intermediate.example.com", Cr.NS_OK); 1.58 +}