diff options
Diffstat (limited to 'test/test_securecookies.py')
-rw-r--r-- | test/test_securecookies.py | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/test/test_securecookies.py b/test/test_securecookies.py index 4523d36..1ade52c 100644 --- a/test/test_securecookies.py +++ b/test/test_securecookies.py @@ -4,26 +4,10 @@ import unittest import bottle from bottle import tob, touni -class TestSecureCookies(unittest.TestCase): - def setUp(self): - self.data = dict(a=5, b=touni('υηι¢σ∂є'), c=[1,2,3,4,tob('bytestring')]) - self.key = tob('secret') - - def testDeEncode(self): - cookie = bottle.cookie_encode(self.data, self.key) - decoded = bottle.cookie_decode(cookie, self.key) - self.assertEqual(self.data, decoded) - decoded = bottle.cookie_decode(cookie+tob('x'), self.key) - self.assertEqual(None, decoded) - def testIsEncoded(self): - cookie = bottle.cookie_encode(self.data, self.key) - self.assertTrue(bottle.cookie_is_encoded(cookie)) - self.assertFalse(bottle.cookie_is_encoded(tob('some string'))) - -class TestSecureCookiesInBottle(unittest.TestCase): +class TestSignedCookies(unittest.TestCase): def setUp(self): - self.data = dict(a=5, b=touni('υηι¢σ∂є'), c=[1,2,3,4,tob('bytestring')]) + self.data = touni('υηι¢σ∂є') self.secret = tob('secret') bottle.app.push() bottle.response.bind() @@ -36,7 +20,7 @@ class TestSecureCookiesInBottle(unittest.TestCase): if k == 'Set-Cookie': key, value = v.split(';')[0].split('=', 1) yield key.lower().strip(), value.strip() - + def set_pairs(self, pairs): header = ','.join(['%s=%s' % (k, v) for k, v in pairs]) bottle.request.bind({'HTTP_COOKIE': header}) @@ -51,6 +35,12 @@ class TestSecureCookiesInBottle(unittest.TestCase): def testWrongKey(self): bottle.response.set_cookie('key', self.data, secret=self.secret) pairs = self.get_pairs() - self.set_pairs([(k+'xxx', v) for (k, v) in pairs]) + self.set_pairs([(k + 'xxx', v) for (k, v) in pairs]) result = bottle.request.get_cookie('key', secret=self.secret) self.assertEqual(None, result) + + +class TestSignedCookiesWithPickle(TestSignedCookies): + def setUp(self): + super(TestSignedCookiesWithPickle, self).setUp() + self.data = dict(a=5, b=touni('υηι¢σ∂є'), c=[1,2,3,4,tob('bytestring')]) |