Example #1
0
    def test_httponly(self):
        cookie = Cookie('color', 'blue', httponly=True)
        self.assertTrue(cookie.http_return_ok('http://example.com'))
        self.assertTrue(cookie.http_return_ok('https://example.com'))

        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok('ftp://example.com'))
Example #2
0
    def test_httponly(self):
        cookie = Cookie("color", "blue", httponly=True)
        self.assertTrue(cookie.http_return_ok("http://example.com"))
        self.assertTrue(cookie.http_return_ok("https://example.com"))

        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok("ftp://example.com"))
Example #3
0
    def test_httponly(self):
        cookie = Cookie('color', 'blue', httponly=True)
        assert cookie.http_return_ok('http://example.com')
        assert cookie.http_return_ok('https://example.com')

        with pytest.raises(Cookie.URLMismatch):
            assert cookie.http_return_ok('ftp://example.com')
Example #4
0
    def test_httponly(self):
        cookie = Cookie('color', 'blue', httponly=True)
        self.assertTrue(cookie.http_return_ok('http://example.com'))
        self.assertTrue(cookie.http_return_ok('https://example.com'))

        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok('ftp://example.com'))
Example #5
0
    def test_path(self):
        cookie = Cookie('color', 'blue')
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie('color', 'blue', path='/')
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie('color', 'blue', path='/one')
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie('color', 'blue', path='/oneX')
        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok(self.url))
Example #6
0
    def test_path(self):
        cookie = Cookie('color', 'blue')
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie('color', 'blue', path='/')
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie('color', 'blue', path='/one')
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie('color', 'blue', path='/oneX')
        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok(self.url))
Example #7
0
    def test_path(self):
        cookie = Cookie('color', 'blue')
        assert cookie.http_return_ok(self.url)

        cookie = Cookie('color', 'blue', path='/')
        assert cookie.http_return_ok(self.url)

        cookie = Cookie('color', 'blue', path='/one')
        assert cookie.http_return_ok(self.url)

        cookie = Cookie('color', 'blue', path='/oneX')
        with pytest.raises(Cookie.URLMismatch):
            assert cookie.http_return_ok(self.url)
Example #8
0
    def test_path(self):
        cookie = Cookie("color", "blue")
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie("color", "blue", path="/")
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie("color", "blue", path="/one")
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie("color", "blue", path="/oneX")
        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok(self.url))
Example #9
0
    def test_expires(self):
        now = datetime.datetime.utcnow().replace(microsecond=0)

        # expires 1 day from now
        expires = now + datetime.timedelta(days=1)

        cookie = Cookie('color', 'blue', expires=expires)
        self.assertTrue(cookie.http_return_ok(self.url))

        # expired 1 day ago
        expires = now + datetime.timedelta(days=-1)
        cookie = Cookie('color', 'blue', expires=expires)
        with self.assertRaises(Cookie.Expired):
            self.assertTrue(cookie.http_return_ok(self.url))
Example #10
0
    def test_expires(self):
        now = datetime.datetime.utcnow().replace(microsecond=0)

        # expires 1 day from now
        expires = now + datetime.timedelta(days=1)

        cookie = Cookie('color', 'blue', expires=expires)
        assert cookie.http_return_ok(self.url)

        # expired 1 day ago
        expires = now + datetime.timedelta(days=-1)
        cookie = Cookie('color', 'blue', expires=expires)
        with pytest.raises(Cookie.Expired):
            assert cookie.http_return_ok(self.url)
Example #11
0
    def test_domain(self):
        cookie = Cookie('color', 'blue', domain='www.foo.bar.com')
        assert cookie.http_return_ok(self.url)

        cookie = Cookie('color', 'blue', domain='.foo.bar.com')
        assert cookie.http_return_ok(self.url)

        cookie = Cookie('color', 'blue', domain='.bar.com')
        assert cookie.http_return_ok(self.url)

        cookie = Cookie('color', 'blue', domain='bar.com')
        with pytest.raises(Cookie.URLMismatch):
            assert cookie.http_return_ok(self.url)

        cookie = Cookie('color', 'blue', domain='bogus.com')
        with pytest.raises(Cookie.URLMismatch):
            assert cookie.http_return_ok(self.url)

        cookie = Cookie('color', 'blue', domain='www.foo.bar.com')
        with pytest.raises(Cookie.URLMismatch):
            assert cookie.http_return_ok('http://192.168.1.1/one/two')
Example #12
0
    def test_domain(self):
        cookie = Cookie('color', 'blue', domain='www.foo.bar.com')
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie('color', 'blue', domain='.foo.bar.com')
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie('color', 'blue', domain='.bar.com')
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie('color', 'blue', domain='bar.com')
        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie('color', 'blue', domain='bogus.com')
        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie('color', 'blue', domain='www.foo.bar.com')
        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok('http://192.168.1.1/one/two'))
Example #13
0
    def test_domain(self):
        cookie = Cookie("color", "blue", domain="www.foo.bar.com")
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie("color", "blue", domain=".foo.bar.com")
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie("color", "blue", domain=".bar.com")
        self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie("color", "blue", domain="bar.com")
        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie("color", "blue", domain="bogus.com")
        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok(self.url))

        cookie = Cookie("color", "blue", domain="www.foo.bar.com")
        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok("http://192.168.1.1/one/two"))
Example #14
0
    def test_secure(self):
        cookie = Cookie('color', 'blue', secure=True)
        self.assertTrue(cookie.http_return_ok('https://Xexample.com'))

        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok('http://Xexample.com'))
Example #15
0
    def test_secure(self):
        cookie = Cookie("color", "blue", secure=True)
        self.assertTrue(cookie.http_return_ok("https://Xexample.com"))

        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok("http://Xexample.com"))
Example #16
0
 def test_no_attributes(self):
     cookie = Cookie('color', 'blue')
     assert cookie.http_return_ok(self.url)
Example #17
0
    def test_secure(self):
        cookie = Cookie('color', 'blue', secure=True)
        self.assertTrue(cookie.http_return_ok('https://Xexample.com'))

        with self.assertRaises(Cookie.URLMismatch):
            self.assertTrue(cookie.http_return_ok('http://Xexample.com'))
Example #18
0
 def test_no_attributes(self):
     cookie = Cookie('color', 'blue')
     self.assertTrue(cookie.http_return_ok(self.url))
Example #19
0
    def test_secure(self):
        cookie = Cookie('color', 'blue', secure=True)
        assert cookie.http_return_ok('https://Xexample.com')

        with pytest.raises(Cookie.URLMismatch):
            assert cookie.http_return_ok('http://Xexample.com')
Example #20
0
 def test_no_attributes(self):
     cookie = Cookie("color", "blue")
     self.assertTrue(cookie.http_return_ok(self.url))