Skip to content

Commit

Permalink
Add test for partial restore
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerklinger committed Jul 31, 2024
1 parent 07ea959 commit a3b230d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_nethsm_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,39 @@ def test_state_restore(nethsm: NetHSM) -> None:
assert decrypt.decode().decode() == C.DATA


def test_factory_reset_provision_state_partial_restore(
container: Container, nethsm: NetHSM
) -> None:
"""Perform a factory reset, provision and partial restore for a NetHSM instance.
This command requires authentication as a user with the Administrator
role."""
nethsm.factory_reset()
container.restart()
provision(nethsm)

system_time = datetime.datetime.now(datetime.timezone.utc)

with open(C.FILENAME_BACKUP, "rb") as f:
nethsm.restore(f, C.BACKUP_PASSPHRASE, system_time)

nethsm.unlock(C.UNLOCK_PASSPHRASE)

assert nethsm.list_keys() == [C.KEY_ID_GENERATED]

with open(C.FILENAME_ENCRYPTED, "rb") as f:
encrypted = f.read()

# see test_decrypt in test_nethsm_keys
with connect(C.OPERATOR_USER) as nethsm:
decrypt = nethsm.decrypt(
C.KEY_ID_GENERATED,
Base64.encode(encrypted),
C.MODE,
)
assert decrypt.decode().decode() == C.DATA


def test_state_provision_update(container: Container, nethsm: NetHSM) -> None:
"""Load an update to a NetHSM instance.
Expand Down

0 comments on commit a3b230d

Please sign in to comment.