示例#1
0
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)
示例#2
0
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')
示例#3
0
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
示例#4
0
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
示例#5
0
 def _set_encrypted(self, key, value):
     if not self.conf:
         self.conf = {}
     self.conf[key] = encrypt_string(value)
示例#6
0
def set_token(self, value):
    if not self.conf:
        self.conf = {}
    self.conf['github_oauth_token'] = encrypt_string(value)