security/manager/ssl/tests/unit/test_sts_ipv4_ipv6.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_sts_ipv4_ipv6.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,39 @@
     1.4 +function check_ip(s, v, ip) {
     1.5 +  do_check_false(s.isSecureHost(Ci.nsISiteSecurityService.HEADER_HSTS, ip, 0));
     1.6 +
     1.7 +  let str = "https://";
     1.8 +  if (v == 6) {
     1.9 +    str += "[";
    1.10 +  }
    1.11 +  str += ip;
    1.12 +  if (v == 6) {
    1.13 +    str += "]";
    1.14 +  }
    1.15 +  str += "/";
    1.16 +
    1.17 +  let uri = Services.io.newURI(str, null, null);
    1.18 +
    1.19 +  let parsedMaxAge = {};
    1.20 +  let parsedIncludeSubdomains = {};
    1.21 +  s.processHeader(Ci.nsISiteSecurityService.HEADER_HSTS, uri,
    1.22 +                  "max-age=1000;includeSubdomains", 0,
    1.23 +                  parsedMaxAge, parsedIncludeSubdomains);
    1.24 +
    1.25 +  /* Test that processHeader will ignore headers for an uri, if the uri
    1.26 +   * contains an IP address not a hostname.
    1.27 +   * If processHeader indeed ignore the header, then the output parameters will
    1.28 +   * remain empty, and we shouldn't see the values passed as the header.
    1.29 +   */
    1.30 +  do_check_neq(parsedMaxAge.value, 1000);
    1.31 +  do_check_neq(parsedIncludeSubdomains.value, true);
    1.32 +}
    1.33 +
    1.34 +function run_test() {
    1.35 +  let SSService = Cc["@mozilla.org/ssservice;1"]
    1.36 +                    .getService(Ci.nsISiteSecurityService);
    1.37 +
    1.38 +  check_ip(SSService, 4, "127.0.0.1");
    1.39 +  check_ip(SSService, 4, "10.0.0.1");
    1.40 +  check_ip(SSService, 6, "2001:db8::1");
    1.41 +  check_ip(SSService, 6, "1080::8:800:200C:417A");
    1.42 +}

mercurial