def test_incorrect_key_encrypt(): value = b'some-text' key = b'incorrect-key' with pytest.raises(ValueError) as exc: encrypt_string(value, key=key) assert 'Wrong secret key' in str(exc)
def test_encrypt_string_transforms_to_bytes(): value = 'some-text' key = Fernet.generate_key() f = Fernet(key) token = encrypt_string(value, key=key) assert f.decrypt(token.encode('utf-8')) == value.encode('utf-8')
def test_encrypt_string_uses_key_in_settings_by_default(): value = b'some-text' key = settings.GTIO_SECRET_KEY f = Fernet(key) token = encrypt_string(value) assert f.decrypt(token.encode('utf-8')) == value
def test_encrypt_string(): value = b'some-text' key = Fernet.generate_key() f = Fernet(key) token = encrypt_string(value, key=key) assert isinstance(token, str) assert f.decrypt(token.encode('utf-8')) == value
def _set_encrypted(self, key, value): if not self.conf: self.conf = {} self.conf[key] = encrypt_string(value)
def set_token(self, value): if not self.conf: self.conf = {} self.conf['github_oauth_token'] = encrypt_string(value)