Exemplo n.º 1
0
    def test_read_write_session_token(self):
        # the secret key to use
        secret_key = 'asdf'
        # generate a session token
        session_token = generate_session_token(secret_key, user=1)
        # make sure we got a string back
        assert isinstance(session_token,
                          str), ("Generated session token was not a string.")

        # make sure we can read it back
        assert read_session_token(secret_key, session_token) == {
            'user': 1
        }, ("Read session token did not match expecatations.")

        try:
            # make sure it would fail if we passed an invalid key
            read_session_token(secret_key, session_token)
            # if we got here then something went wrong
            raise AssertionError("Invalid key was able to read session token")
        except:
            pass
Exemplo n.º 2
0
    def test_read_write_session_token(self):
        # the secret key to use
        secret_key = 'asdf'
        # generate a session token
        session_token = generate_session_token(secret_key, user=1)
        # make sure we got a string back
        assert isinstance(session_token, str), (
            "Generated session token was not a string."
        )

        # make sure we can read it back
        assert read_session_token(secret_key, session_token) == {
            'user': 1
        }, (
            "Read session token did not match expecatations."
        )

        try:
            # make sure it would fail if we passed an invalid key
            read_session_token(secret_key, session_token)
            # if we got here then something went wrong
            raise AssertionError("Invalid key was able to read session token")
        except:
            pass
Exemplo n.º 3
0
 def _read_session_token(self, token):
     # make sure the token is valid while we're at it
     return read_session_token(self.secret_key, token)
Exemplo n.º 4
0
 def _read_session_token(self, token):
     # make sure the token is valid while we're at it
     return read_session_token(self.secret_key, token)