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 25, 2024
1 parent 07ea959 commit bacfa06
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/test_nethsm_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,34 @@ 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)

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 bacfa06

Please sign in to comment.