Exemplo n.º 1
0
    def test_cant_decode_token_with_wrong_key(self):
        token = generate_token({
            'key1': 'value1',
            'key2': 'value2'
        },
                               secret_key='1234567890',
                               namespace='1234567890')

        with pytest.raises(fernet.InvalidToken):
            decode_token(token, 'failed', '1234567890')
Exemplo n.º 2
0
    def test_decrypt_token_ok_for_known_good_token(self):
        # encrypted on 2016-01-01T12:00:00.30Z with secret 'Secret' and namespace 'PassSalt'
        token = 'gAAAAABWhmpA1ecLpuzdKiIcJ_drdA1Vf4ip07TH3UqZ_fA-pD9yYlGMqSTi-Mpbd58Z-wlZfa5sXGE6FVHPilTpsZWEiMDRLdCBlccvBPbY9IOO5F3uabjkrk87mrlPxaSbMAza5Nku'  # noqa

        with freeze_time('2016-01-01T12:00:00.30Z'):
            data = decode_token(token, 'Secret', 'PassSalt')

        assert data == ({
            'email': '*****@*****.**',
            'user': 123
        }, datetime(2016, 1, 1, 12, 0, 0))
Exemplo n.º 3
0
def test_can_generate_and_decode_token():

    with freeze_time('2016-01-01T12:00:00Z'):
        encrypted_token = generate_token({
            'key1': 'value1',
            'key2': 'value2'
        },
                                         secret_key='1234567890',
                                         namespace='0987654321')
        token, timestamp = decode_token(encrypted_token, '1234567890',
                                        '0987654321')
    assert token == {'key1': 'value1', 'key2': 'value2'}
    assert timestamp == datetime(2016, 1, 1, 12, 0, 0)