Exemplo n.º 1
0
def test_incorrect_key_decrypt():

    token = b'some-token'
    key = b'incorrect-key'

    with pytest.raises(ValueError) as exc:
        decrypt_string(token, key=key)

        assert 'Wrong secret key' in str(exc)
Exemplo n.º 2
0
def test_decrypt_string_transforms_to_bytes():

    value = b'some-text'
    key = settings.GTIO_SECRET_KEY
    f = Fernet(key)
    token = f.encrypt(value)

    our_value = decrypt_string(token.decode('utf-8'))

    assert our_value == value.decode('utf-8')
Exemplo n.º 3
0
def test_decrypt_string_uses_key_in_settings_by_default():

    value = b'some-text'
    key = settings.GTIO_SECRET_KEY
    f = Fernet(key)
    token = f.encrypt(value)

    our_value = decrypt_string(token)

    assert our_value == value.decode('utf-8')
Exemplo n.º 4
0
    def _get_encrypted(self, key):
        token = self.conf.get(key)
        if token:
            try:
                token = decrypt_string(token)
            except cryptography.fernet.InvalidToken:
                # This happens if someone sets the key directly
                # on the conf property (ie it should never happen)
                token = None

        return token
Exemplo n.º 5
0
def get_token(self):
    token = self.conf.get('github_oauth_token')
    if token:
        try:
            token = decrypt_string(token)
        except cryptography.fernet.InvalidToken:
            # This happens if someone sets the github_oauth_token directly
            # on the conf property (ie it should never happen)
            token = None

    return token
Exemplo n.º 6
0
def test_decrypt_string():

    value = b'some-text'
    key = Fernet.generate_key()
    f = Fernet(key)
    token = f.encrypt(value)

    our_value = decrypt_string(token, key=key)

    assert isinstance(our_value, str)

    assert our_value == value.decode('utf-8')