Beispiel #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)
Beispiel #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')
Beispiel #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')
Beispiel #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
Beispiel #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
Beispiel #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')