예제 #1
0
 def test_generate_signed(self) -> None:
     session_id = generate_session_id(signed=True, secret_key="abc")
     token = generate_jwt_token(session_id, signed=True, secret_key="abc")
     assert '.' in token
     decoded = json.loads(_base64_decode(token.split('.')[0], encoding='utf-8'))
     assert "session_id" in decoded
     assert decoded['session_id'] == session_id
     assert check_token_signature(token, secret_key="abc", signed=True)
     assert not check_token_signature(token, secret_key="qrs", signed=True)
예제 #2
0
 def test_payload_signed(self):
     session_id = generate_session_id(signed=True, secret_key="abc")
     token = generate_jwt_token(session_id, signed=True, secret_key="abc", extra_payload=dict(foo=10))
     assert '.' in token
     decoded = json.loads(_base64_decode(token.split('.')[0], encoding='utf-8'))
     assert 'session_id' in decoded
     session_id = get_session_id(token)
     assert check_token_signature(token, secret_key="abc", signed=True)
     assert not check_token_signature(token, secret_key="qrs", signed=True)
     assert decoded['foo'] == 10
예제 #3
0
 def test_payload_signed(self):
     session_id = generate_session_id(signed=True, secret_key="abc")
     token = generate_jwt_token(session_id,
                                signed=True,
                                secret_key="abc",
                                extra_payload=dict(foo=10))
     assert '.' in token
     decoded = json.loads(_b64_to_utf8(token.split('.')[0]))
     assert _TOKEN_ZLIB_KEY in decoded
     assert 'session_id' in decoded
     session_id = get_session_id(token)
     assert check_token_signature(token, secret_key="abc", signed=True)
     assert not check_token_signature(token, secret_key="qrs", signed=True)
     payload = get_token_payload(token)
     assert _TOKEN_ZLIB_KEY not in payload
     assert payload['foo'] == 10