Skip to content
Snippets Groups Projects

Remove Ponos from CE

Merged Valentin Rigal requested to merge move-ponos-ee into community
5 files
+ 2
1900
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 0
47
from pathlib import Path
from django.test import TestCase, override_settings
from arkindex.ponos.admin import ClearTextSecretForm, SecretAdmin
from arkindex.ponos.models import Secret, encrypt
PONOS_PRIVATE_KEY = Path(__file__).absolute().parent / "fixtures" / "ponos.key"
class TestAdmin(TestCase):
@override_settings(PONOS_PRIVATE_KEY=PONOS_PRIVATE_KEY)
def test_admin_read_secret(self):
"""
Admin form display the decrypted content of the stored secrets
"""
nonce = b"1337" * 4
encrypted = encrypt(nonce, "Shhhh")
secret = Secret.objects.create(
name="important_secret",
nonce=b"1337" * 4,
content=encrypted,
)
self.assertEqual(secret.content, b"\xa3\xda\x9b\x91#")
form = ClearTextSecretForm(instance=secret)
self.assertEqual(form.initial.get("content"), "Shhhh")
@override_settings(PONOS_PRIVATE_KEY=PONOS_PRIVATE_KEY)
def test_admin_updates_secret(self):
nonce = b"1337" * 4
encrypted = encrypt(nonce, "Shhhh")
secret = Secret.objects.create(
name="important_secret",
nonce=b"1337" * 4,
content=encrypted,
)
secret_admin = SecretAdmin(model=Secret, admin_site=None)
form = ClearTextSecretForm(
data={"id": secret.id, "name": secret.name, "content": "Ah"},
instance=secret,
)
self.assertEqual(secret.content, b"\xa3\xda\x9b\x91#")
secret_admin.save_form(request=None, form=form, change=True)
self.assertEqual(secret.content, b"\xb1\xda")
self.assertEqual(b"\xb1\xda", encrypt(secret.nonce, "Ah"))
Loading