Skip to content

Commit

Permalink
🎨 Misc implementation/test improvements
Browse files Browse the repository at this point in the history
* Ensure migration tests use temporary private media root
* Addressed some type checker issues in update_metadata
  management command implementation
  • Loading branch information
sergei-maertens committed Jul 19, 2024
1 parent 41b8f9f commit 0ba2f45
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions digid_eherkenning/management/commands/update_stored_metadata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from django.core.management import BaseCommand

from digid_eherkenning.models.digid import DigidConfiguration
from digid_eherkenning.models.eherkenning import EherkenningConfiguration
from ...models import DigidConfiguration, EherkenningConfiguration

MODEL_MAP = {
"digid": DigidConfiguration,
"eherkenning": EherkenningConfiguration,
}


class Command(BaseCommand):
Expand All @@ -11,15 +15,13 @@ def add_arguments(self, parser):
parser.add_argument(
"config_model",
type=str,
choices=["digid", "eherkenning"],
choices=list(MODEL_MAP.keys()),
help="Update the DigiD or Eherkenning configuration metadata.",
)

def handle(self, **options):
if options["config_model"] == "digid":
config = DigidConfiguration.get_solo()
elif options["config_model"] == "eherkenning":
config = EherkenningConfiguration.get_solo()
config_model = MODEL_MAP[options["config_model"]]
config = config_model.get_solo()

if config.metadata_file_source:
config.save(force_metadata_update=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import pytest
from cryptography.hazmat.primitives.asymmetric import rsa
from simple_certmanager.constants import CertificateTypes
from simple_certmanager.models import Certificate
from simple_certmanager.test.certificate_generation import key_to_pem
from simple_certmanager.utils import load_pem_x509_private_key

Expand Down Expand Up @@ -43,7 +42,7 @@ def test_fixing_misconfigured_eherkenning(migrator):

@pytest.mark.django_db
def test_decrypt_private_keys_with_passphrase(
migrator, encrypted_keypair: tuple[bytes, bytes]
temp_private_root, migrator, encrypted_keypair: tuple[bytes, bytes]
):
old_state = migrator.apply_initial_migration(
("digid_eherkenning", "0008_update_loa_fields")
Expand Down Expand Up @@ -163,6 +162,7 @@ def _decryption_skip_cases_idfn(case):
)
@pytest.mark.django_db
def test_decryption_migration_robustness(
temp_private_root,
migrator,
leaf_keypair: tuple[rsa.RSAPrivateKey, bytes],
encrypted_keypair: tuple[bytes, bytes],
Expand Down

0 comments on commit 0ba2f45

Please sign in to comment.