Пример #1
0
    def test_cookie_signature(self):
        "Test that secure cookie algorithm is outputting correct signatures."
        auth.install_secure_cookies(["supersecret"])
        value = base64.b64encode("testvalue")
        timestamp = "1360023531"
        expected_signature = ["e90904d67de2fd6e4d4f3c9a736e3b8c457526f9"]

        self.assertEqual(expected_signature,
                         auth._cookie_signature(value, timestamp))
Пример #2
0
 def test_cookie_signature(self):
     "Test that secure cookie algorithm is outputting correct signatures."
     auth.install_secure_cookies(["supersecret"])
     value = base64.b64encode("testvalue")
     timestamp = "1360023531"
     expected_signature = ["e90904d67de2fd6e4d4f3c9a736e3b8c457526f9"]
     
     self.assertEqual(expected_signature,
                      auth._cookie_signature(value, timestamp))
Пример #3
0
 def test_set_secure_cookie(self):
     "Validate setting a secure cookie."
     request = DummyRequest()
     
     auth.install_secure_cookies(["supersecret"])
     auth.set_secure_cookie(request, "testkey", "testvalue")
     
     self.assertEqual(1, len(request.cookies))
     key, value = request.cookies[0].split("=", 1)
     value, expires, path = value.split(";")
     path = path.split("=")[1]
     expires = (datetime.datetime(*email.utils.parsedate(expires.split("=")[1])[:6])-datetime.datetime.utcnow()).days
     value, timestamp, signature = value.split("|")
     
     self.assertEqual("/", path)
     self.assertEqual(29, expires)
     self.assertEqual("testkey", key)
     self.assertEqual(base64.b64encode("testvalue"), value)
     self.assertTrue(timestamp > 0)
     
     expected_signature = auth._cookie_signature(value, timestamp)[0]
     self.assertEqual(expected_signature, signature)
Пример #4
0
    def test_set_secure_cookie(self):
        "Validate setting a secure cookie."
        request = DummyRequest()

        auth.install_secure_cookies(["supersecret"])
        auth.set_secure_cookie(request, "testkey", "testvalue")

        self.assertEqual(1, len(request.cookies))
        key, value = request.cookies[0].split("=", 1)
        value, expires, path = value.split(";")
        path = path.split("=")[1]
        expires = (datetime.datetime(
            *email.utils.parsedate(expires.split("=")[1])[:6]) -
                   datetime.datetime.utcnow()).days
        value, timestamp, signature = value.split("|")

        self.assertEqual("/", path)
        self.assertEqual(29, expires)
        self.assertEqual("testkey", key)
        self.assertEqual(base64.b64encode("testvalue"), value)
        self.assertTrue(timestamp > 0)

        expected_signature = auth._cookie_signature(value, timestamp)[0]
        self.assertEqual(expected_signature, signature)