Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions tests/test_secret_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,28 +303,29 @@ def test_rotate_secret_cli_requires_offline_ack(app):
import config

data_dir = Path(config.DATA_DIR)
(data_dir / 'secret_key').write_text(
config.SECRET_KEY + '\n',
encoding='utf-8',
)
before = (data_dir / 'secret_key').read_bytes()
secret_path = data_dir / 'secret_key'
assert not secret_path.exists()
Comment on lines +306 to +307

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve an existing secret in the offline-ack test

Keep a fixed test-only secret file here and assert that its contents remain unchanged. With the directory initially empty, this test only proves that omitting --confirm-offline does not create a secret; if a future regression overwrites or deletes an already-persisted production secret before rejecting the command, the test will still pass, whereas the previous assertion covered that important no-side-effects contract.

Useful? React with 👍 / 👎.


result = app.test_cli_runner().invoke(args=['rotate-secret-key'])

assert result.exit_code != 0
assert 'confirm-offline' in result.output
assert (data_dir / 'secret_key').read_bytes() == before
assert not secret_path.exists()


def test_rotate_secret_cli_generates_and_persists_new_secret(app):
def test_rotate_secret_cli_generates_and_persists_new_secret(app, monkeypatch):
import config

data_dir = Path(config.DATA_DIR)
old_secret = config.SECRET_KEY
(data_dir / 'secret_key').write_text(
old_secret + '\n',
'unit-test-cli-rotation-key-material\n',
encoding='utf-8',
)
monkeypatch.setattr(
config,
'SECRET_KEY',
'unit-test-cli-rotation-key-material',
)

result = app.test_cli_runner().invoke(
args=['rotate-secret-key', '--confirm-offline'],
Expand All @@ -335,7 +336,7 @@ def test_rotate_secret_cli_generates_and_persists_new_secret(app):
encoding='utf-8',
).rstrip('\n')
assert new_secret
assert new_secret != old_secret
assert new_secret != 'unit-test-cli-rotation-key-material'
assert 'restart' in result.output.lower()
assert len(list(data_dir.parent.glob(
f'{data_dir.name}-pre-rotation-*.zip'
Expand Down
Loading