Beispiel #1
0
    def test_timestamp_expired(self):
        """ If the timestamp is more than 31 days old, returns `None`.
        """

        from weblayer.cookie import _generate_cookie_signature

        t = time.time()
        too_old = str(int(t - 32 * 24 * 60 * 60))

        cs = self.settings['cookie_secret']
        sig = _generate_cookie_signature(cs, 'name', 'dmFsdWU=', too_old)
        value = 'dmFsdWU=|%s|%s' % (too_old, sig)

        result = self.cookie_wrapper.get('name', value=value)
        self.assertTrue(result is None)
Beispiel #2
0
    def test_get_value(self):
        """ If the signature matches, the value comes back
          run through `base64.b64decode`.
        """

        from weblayer.cookie import _generate_cookie_signature

        t = time.time()
        ts = str(int(t))

        cs = self.settings['cookie_secret']
        sig = _generate_cookie_signature(cs, 'name', 'dmFsdWU=', ts)
        value = 'dmFsdWU=|%s|%s' % (ts, sig)

        result = self.cookie_wrapper.get('name', value=value)
        self.assertTrue(result == 'value')
Beispiel #3
0
    def test_value_is_base64_decodable(self):
        """ If the signature matches, the value comes back
          run through `base64.b64decode`.  If it can't be
          decoded, it raises a TypeError.
        """

        from weblayer.cookie import _generate_cookie_signature

        t = time.time()
        ts = str(int(t))

        cs = self.settings['cookie_secret']
        sig = _generate_cookie_signature(cs, 'name', 'a', ts)
        value = 'a|%s|%s' % (ts, sig)

        result = self.cookie_wrapper.get('name', value=value)
        self.assertTrue(result is None)