(self)
| 937 | self.assertEqual(len(cj), 2) |
| 938 | |
| 939 | def test_two_component_domain_ns(self): |
| 940 | # Netscape: .www.bar.com, www.bar.com, .bar.com, bar.com, no domain |
| 941 | # should all get accepted, as should .acme.com, acme.com and no domain |
| 942 | # for 2-component domains like acme.com. |
| 943 | c = CookieJar() |
| 944 | |
| 945 | # two-component V0 domain is OK |
| 946 | interact_netscape(c, "http://foo.net/", 'ns=bar') |
| 947 | self.assertEqual(len(c), 1) |
| 948 | self.assertEqual(c._cookies["foo.net"]["/"]["ns"].value, "bar") |
| 949 | self.assertEqual(interact_netscape(c, "http://foo.net/"), "ns=bar") |
| 950 | # *will* be returned to any other domain (unlike RFC 2965)... |
| 951 | self.assertEqual(interact_netscape(c, "http://www.foo.net/"), |
| 952 | "ns=bar") |
| 953 | # ...unless requested otherwise |
| 954 | pol = DefaultCookiePolicy( |
| 955 | strict_ns_domain=DefaultCookiePolicy.DomainStrictNonDomain) |
| 956 | c.set_policy(pol) |
| 957 | self.assertEqual(interact_netscape(c, "http://www.foo.net/"), "") |
| 958 | |
| 959 | # unlike RFC 2965, even explicit two-component domain is OK, |
| 960 | # because .foo.net matches foo.net |
| 961 | interact_netscape(c, "http://foo.net/foo/", |
| 962 | 'spam1=eggs; domain=foo.net') |
| 963 | # even if starts with a dot -- in NS rules, .foo.net matches foo.net! |
| 964 | interact_netscape(c, "http://foo.net/foo/bar/", |
| 965 | 'spam2=eggs; domain=.foo.net') |
| 966 | self.assertEqual(len(c), 3) |
| 967 | self.assertEqual(c._cookies[".foo.net"]["/foo"]["spam1"].value, |
| 968 | "eggs") |
| 969 | self.assertEqual(c._cookies[".foo.net"]["/foo/bar"]["spam2"].value, |
| 970 | "eggs") |
| 971 | self.assertEqual(interact_netscape(c, "http://foo.net/foo/bar/"), |
| 972 | "spam2=eggs; spam1=eggs; ns=bar") |
| 973 | |
| 974 | # top-level domain is too general |
| 975 | interact_netscape(c, "http://foo.net/", 'nini="ni"; domain=.net') |
| 976 | self.assertEqual(len(c), 3) |
| 977 | |
| 978 | ## # Netscape protocol doesn't allow non-special top level domains (such |
| 979 | ## # as co.uk) in the domain attribute unless there are at least three |
| 980 | ## # dots in it. |
| 981 | # Oh yes it does! Real implementations don't check this, and real |
| 982 | # cookies (of course) rely on that behaviour. |
| 983 | interact_netscape(c, "http://foo.co.uk", 'nasty=trick; domain=.co.uk') |
| 984 | ## self.assertEqual(len(c), 2) |
| 985 | self.assertEqual(len(c), 4) |
| 986 | |
| 987 | def test_localhost_domain(self): |
| 988 | c = CookieJar() |
nothing calls this directly
no test coverage detected