test_sts_ipv4_ipv6.js (1524B)
1 // -*- indent-tabs-mode: nil; js-indent-level: 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"; 6 7 function check_ip(s, v, ip) { 8 let str = "https://"; 9 if (v == 6) { 10 str += "["; 11 } 12 str += ip; 13 if (v == 6) { 14 str += "]"; 15 } 16 str += "/"; 17 18 let uri = Services.io.newURI(str); 19 ok(!s.isSecureURI(uri)); 20 21 let parsedMaxAge = {}; 22 let parsedIncludeSubdomains = {}; 23 s.processHeader( 24 uri, 25 "max-age=1000;includeSubdomains", 26 {}, 27 parsedMaxAge, 28 parsedIncludeSubdomains 29 ); 30 ok( 31 !s.isSecureURI(uri), 32 "URI should not be secure if it contains an IP address" 33 ); 34 35 /* Test that processHeader will ignore headers for an uri, if the uri 36 * contains an IP address not a hostname. 37 * If processHeader indeed ignore the header, then the output parameters will 38 * remain empty, and we shouldn't see the values passed as the header. 39 */ 40 notEqual(parsedMaxAge.value, 1000); 41 notEqual(parsedIncludeSubdomains.value, true); 42 notEqual(parsedMaxAge.value, undefined); 43 notEqual(parsedIncludeSubdomains.value, undefined); 44 } 45 46 function run_test() { 47 let SSService = Cc["@mozilla.org/ssservice;1"].getService( 48 Ci.nsISiteSecurityService 49 ); 50 51 check_ip(SSService, 4, "127.0.0.1"); 52 check_ip(SSService, 4, "10.0.0.1"); 53 check_ip(SSService, 6, "2001:db8::1"); 54 check_ip(SSService, 6, "1080::8:800:200C:417A"); 55 }