Skip to content

Commit

Permalink
Stricter validation of init/unlock arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
vaultah committed Apr 9, 2022
1 parent 622e481 commit 69235b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 10 additions & 0 deletions replicat/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,12 @@ async def init(self, *, password=None, settings=None, key_output_path=None):
json.dumps(key, indent=4, default=self.default_serialization_hook)
)
else:
if password is not None or key_output_path is not None:
raise exceptions.ReplicatError(
'Password and key output path can only be provided to initialise '
'encrypted repositories'
)

key = None

self.display_status('Uploading config')
Expand Down Expand Up @@ -708,6 +714,10 @@ async def unlock(self, *, password=None, key=None):
props,
**self._instantiate_key(key, password=password, cipher=props.cipher),
)
elif password is not None or key is not None:
raise exceptions.ReplicatError(
'Cannot provide password or key to unlock unencrypted repositories'
)

self.props = props

Expand Down
9 changes: 4 additions & 5 deletions replicat/tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ async def test_encrypted_ok(self, local_backend, local_repo, tmp_path):
@pytest.mark.asyncio
async def test_unencrypted_ok(self, local_backend, local_repo):
result = await local_repo.init(
password=b'<password>',
settings={'encryption': None, 'chunking': {'max_length': 128_129}},
)

Expand Down Expand Up @@ -736,7 +735,7 @@ def upldstream(name, contents, length):
async def test_not_locked(self, monkeypatch, local_backend, tmp_path, encryption):
local_repo = Repository(local_backend, concurrent=5)
await local_repo.init(
password=b'<password>',
password=encryption and b'<password>',
settings={'encryption': encryption},
)

Expand Down Expand Up @@ -780,7 +779,7 @@ async def _wait_for_lock(*a, **ka):
async def test_locked(self, monkeypatch, local_backend, tmp_path, encryption):
local_repo = Repository(local_backend, concurrent=5)
await local_repo.init(
password=b'<password>',
password=encryption and b'<password>',
settings={'encryption': encryption},
)

Expand Down Expand Up @@ -1154,7 +1153,7 @@ async def test_unencrypted_unreferenced(self, local_backend, local_repo, tmp_pat
async def test_not_locked(self, monkeypatch, local_backend, encryption):
local_repo = Repository(local_backend, concurrent=5)
await local_repo.init(
password=b'<password>',
password=encryption and b'<password>',
settings={'encryption': encryption},
)

Expand Down Expand Up @@ -1187,7 +1186,7 @@ async def test_not_locked(self, monkeypatch, local_backend, encryption):
async def test_locked(self, monkeypatch, local_backend, encryption):
local_repo = Repository(local_backend, concurrent=5)
await local_repo.init(
password=b'<password>',
password=encryption and b'<password>',
settings={'encryption': encryption},
)

Expand Down

0 comments on commit 69235b2

Please sign in to comment.