chore(gpg_secretstore): assert existence of user supplied secret

This commit is contained in:
Jan Christian Grünhage 2022-09-21 16:42:29 +02:00
parent 1bd01fc376
commit 265036be47
No known key found for this signature in database
GPG key ID: EEC1170CE56FA2ED
2 changed files with 13 additions and 0 deletions

View file

@ -245,6 +245,10 @@ def check_module_import_errors():
return errors
class UserSuppliedSecretMissingError(Exception):
pass
class SecretGenerator:
ALLOWED_SECRET_TYPES = ["random", "binary", "user_supplied"]
@ -294,6 +298,10 @@ class SecretGenerator:
@staticmethod
def __userSuppliedSecret(user_supplied_secret: str, **kwargs):
if user_supplied_secret is None:
raise UserSuppliedSecretMissingError(
"User supplied secret configured, but it's neither in the store nor supplied"
)
return user_supplied_secret

View file

@ -135,6 +135,11 @@ class TestSecretGenerator:
secret = generator.getSecret()
assert len(secret) == 30
def test_missing_user_supplied_secret(self, monkeypatch):
generator = gpg_secretstore.SecretGenerator(secret_type="user_supplied")
with pytest.raises(Exception):
generator.getSecret()
def test_plain_user_supplied_secret(self, monkeypatch):
generator = gpg_secretstore.SecretGenerator(
secret_type="user_supplied", user_supplied_secret="secretdata"