mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-23 09:16:51 +00:00
test(backups): test local secrets
This commit is contained in:
parent
ebeb76149b
commit
d3f9ce7bf5
|
@ -32,6 +32,10 @@ class LocalBackupSecret:
|
||||||
new_secret = LocalBackupSecret._generate()
|
new_secret = LocalBackupSecret._generate()
|
||||||
LocalBackupSecret.set(new_secret)
|
LocalBackupSecret.set(new_secret)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _full_reset():
|
||||||
|
redis.delete(REDIS_KEY)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def exists() -> bool:
|
def exists() -> bool:
|
||||||
return redis.exists(REDIS_KEY)
|
return redis.exists(REDIS_KEY)
|
||||||
|
|
38
tests/test_graphql/test_localsecret.py
Normal file
38
tests/test_graphql/test_localsecret.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
from selfprivacy_api.backup.local_secret import LocalBackupSecret
|
||||||
|
from pytest import fixture
|
||||||
|
|
||||||
|
|
||||||
|
@fixture()
|
||||||
|
def localsecret():
|
||||||
|
LocalBackupSecret._full_reset()
|
||||||
|
return LocalBackupSecret
|
||||||
|
|
||||||
|
|
||||||
|
def test_local_secret_firstget(localsecret):
|
||||||
|
assert not LocalBackupSecret.exists()
|
||||||
|
secret = LocalBackupSecret.get()
|
||||||
|
assert LocalBackupSecret.exists()
|
||||||
|
assert secret is not None
|
||||||
|
|
||||||
|
# making sure it does not reset again
|
||||||
|
secret2 = LocalBackupSecret.get()
|
||||||
|
assert LocalBackupSecret.exists()
|
||||||
|
assert secret2 == secret
|
||||||
|
|
||||||
|
|
||||||
|
def test_local_secret_reset(localsecret):
|
||||||
|
secret1 = LocalBackupSecret.get()
|
||||||
|
|
||||||
|
LocalBackupSecret.reset()
|
||||||
|
secret2 = LocalBackupSecret.get()
|
||||||
|
assert secret2 is not None
|
||||||
|
assert secret2 != secret1
|
||||||
|
|
||||||
|
|
||||||
|
def test_local_secret_set(localsecret):
|
||||||
|
newsecret = "great and totally safe secret"
|
||||||
|
oldsecret = LocalBackupSecret.get()
|
||||||
|
assert oldsecret != newsecret
|
||||||
|
|
||||||
|
LocalBackupSecret.set(newsecret)
|
||||||
|
assert LocalBackupSecret.get() == newsecret
|
Loading…
Reference in a new issue