1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_bug368702.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,150 @@ 1.4 +function run_test() { 1.5 + var tld = 1.6 + Cc["@mozilla.org/network/effective-tld-service;1"]. 1.7 + getService(Ci.nsIEffectiveTLDService); 1.8 + 1.9 + var etld; 1.10 + 1.11 + do_check_eq(tld.getPublicSuffixFromHost("localhost"), "localhost"); 1.12 + do_check_eq(tld.getPublicSuffixFromHost("localhost."), "localhost."); 1.13 + do_check_eq(tld.getPublicSuffixFromHost("domain.com"), "com"); 1.14 + do_check_eq(tld.getPublicSuffixFromHost("domain.com."), "com."); 1.15 + do_check_eq(tld.getPublicSuffixFromHost("domain.co.uk"), "co.uk"); 1.16 + do_check_eq(tld.getPublicSuffixFromHost("domain.co.uk."), "co.uk."); 1.17 + do_check_eq(tld.getPublicSuffixFromHost("co.uk"), "co.uk"); 1.18 + do_check_eq(tld.getBaseDomainFromHost("domain.co.uk"), "domain.co.uk"); 1.19 + do_check_eq(tld.getBaseDomainFromHost("domain.co.uk."), "domain.co.uk."); 1.20 + 1.21 + try { 1.22 + etld = tld.getPublicSuffixFromHost(""); 1.23 + do_throw("this should fail"); 1.24 + } catch(e) { 1.25 + do_check_eq(e.result, Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS); 1.26 + } 1.27 + 1.28 + try { 1.29 + etld = tld.getBaseDomainFromHost("domain.co.uk", 1); 1.30 + do_throw("this should fail"); 1.31 + } catch(e) { 1.32 + do_check_eq(e.result, Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS); 1.33 + } 1.34 + 1.35 + try { 1.36 + etld = tld.getBaseDomainFromHost("co.uk"); 1.37 + do_throw("this should fail"); 1.38 + } catch(e) { 1.39 + do_check_eq(e.result, Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS); 1.40 + } 1.41 + 1.42 + try { 1.43 + etld = tld.getBaseDomainFromHost(""); 1.44 + do_throw("this should fail"); 1.45 + } catch(e) { 1.46 + do_check_eq(e.result, Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS); 1.47 + } 1.48 + 1.49 + try { 1.50 + etld = tld.getPublicSuffixFromHost("1.2.3.4"); 1.51 + do_throw("this should fail"); 1.52 + } catch(e) { 1.53 + do_check_eq(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS); 1.54 + } 1.55 + 1.56 + try { 1.57 + etld = tld.getPublicSuffixFromHost("2010:836B:4179::836B:4179"); 1.58 + do_throw("this should fail"); 1.59 + } catch(e) { 1.60 + do_check_eq(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS); 1.61 + } 1.62 + 1.63 + try { 1.64 + etld = tld.getPublicSuffixFromHost("3232235878"); 1.65 + do_throw("this should fail"); 1.66 + } catch(e) { 1.67 + do_check_eq(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS); 1.68 + } 1.69 + 1.70 + try { 1.71 + etld = tld.getPublicSuffixFromHost("::ffff:192.9.5.5"); 1.72 + do_throw("this should fail"); 1.73 + } catch(e) { 1.74 + do_check_eq(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS); 1.75 + } 1.76 + 1.77 + try { 1.78 + etld = tld.getPublicSuffixFromHost("::1"); 1.79 + do_throw("this should fail"); 1.80 + } catch(e) { 1.81 + do_check_eq(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS); 1.82 + } 1.83 + 1.84 + // Check IP addresses with trailing dot as well, Necko sometimes accepts 1.85 + // those (depending on operating system, see bug 380543) 1.86 + try { 1.87 + etld = tld.getPublicSuffixFromHost("127.0.0.1."); 1.88 + do_throw("this should fail"); 1.89 + } catch(e) { 1.90 + do_check_eq(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS); 1.91 + } 1.92 + 1.93 + try { 1.94 + etld = tld.getPublicSuffixFromHost("::ffff:127.0.0.1."); 1.95 + do_throw("this should fail"); 1.96 + } catch(e) { 1.97 + do_check_eq(e.result, Cr.NS_ERROR_HOST_IS_IP_ADDRESS); 1.98 + } 1.99 + 1.100 + // check normalization: output should be consistent with 1.101 + // nsIURI::GetAsciiHost(), i.e. lowercased and ASCII/ACE encoded 1.102 + var ioService = Components.classes["@mozilla.org/network/io-service;1"] 1.103 + .getService(Components.interfaces.nsIIOService); 1.104 + 1.105 + var uri = ioService.newURI("http://b\u00FCcher.co.uk", null, null); 1.106 + do_check_eq(tld.getBaseDomain(uri), "xn--bcher-kva.co.uk"); 1.107 + do_check_eq(tld.getBaseDomainFromHost("b\u00FCcher.co.uk"), "xn--bcher-kva.co.uk"); 1.108 + do_check_eq(tld.getPublicSuffix(uri), "co.uk"); 1.109 + do_check_eq(tld.getPublicSuffixFromHost("b\u00FCcher.co.uk"), "co.uk"); 1.110 + 1.111 + // check that malformed hosts are rejected as invalid args 1.112 + try { 1.113 + etld = tld.getBaseDomainFromHost("domain.co.uk.."); 1.114 + do_throw("this should fail"); 1.115 + } catch(e) { 1.116 + do_check_eq(e.result, Cr.NS_ERROR_ILLEGAL_VALUE); 1.117 + } 1.118 + 1.119 + try { 1.120 + etld = tld.getBaseDomainFromHost("domain.co..uk"); 1.121 + do_throw("this should fail"); 1.122 + } catch(e) { 1.123 + do_check_eq(e.result, Cr.NS_ERROR_ILLEGAL_VALUE); 1.124 + } 1.125 + 1.126 + try { 1.127 + etld = tld.getBaseDomainFromHost(".domain.co.uk"); 1.128 + do_throw("this should fail"); 1.129 + } catch(e) { 1.130 + do_check_eq(e.result, Cr.NS_ERROR_ILLEGAL_VALUE); 1.131 + } 1.132 + 1.133 + try { 1.134 + etld = tld.getBaseDomainFromHost(".domain.co.uk"); 1.135 + do_throw("this should fail"); 1.136 + } catch(e) { 1.137 + do_check_eq(e.result, Cr.NS_ERROR_ILLEGAL_VALUE); 1.138 + } 1.139 + 1.140 + try { 1.141 + etld = tld.getBaseDomainFromHost("."); 1.142 + do_throw("this should fail"); 1.143 + } catch(e) { 1.144 + do_check_eq(e.result, Cr.NS_ERROR_ILLEGAL_VALUE); 1.145 + } 1.146 + 1.147 + try { 1.148 + etld = tld.getBaseDomainFromHost(".."); 1.149 + do_throw("this should fail"); 1.150 + } catch(e) { 1.151 + do_check_eq(e.result, Cr.NS_ERROR_ILLEGAL_VALUE); 1.152 + } 1.153 +}