mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-21 13:47:16 +00:00
Merge pull request #6243 from hexagonrecursion/test-keyfile
Test: borg init refuses to overwrite keyfile
This commit is contained in:
commit
d4eb9bbd35
1 changed files with 20 additions and 0 deletions
|
@ -28,6 +28,7 @@
|
|||
import pytest
|
||||
|
||||
import borg
|
||||
import borg.helpers.errors
|
||||
from .. import xattr, helpers, platform
|
||||
from ..archive import Archive, ChunkBuffer
|
||||
from ..archiver import Archiver, parse_storage_quota, PURE_PYTHON_MSGPACK_WARNING
|
||||
|
@ -2864,6 +2865,25 @@ def test_init_nested_repositories(self):
|
|||
with pytest.raises(Repository.AlreadyExists):
|
||||
self.cmd('init', '--encryption=repokey', self.repository_location + '/nested')
|
||||
|
||||
def test_init_refuse_to_overwrite_keyfile(self):
|
||||
"""BORG_KEY_FILE=something borg init should quit if "something" already exists.
|
||||
|
||||
See https://github.com/borgbackup/borg/pull/6046"""
|
||||
keyfile = os.path.join(self.tmpdir, 'keyfile')
|
||||
with environment_variable(BORG_KEY_FILE=keyfile):
|
||||
self.cmd('init', '--encryption=keyfile', self.repository_location + '0')
|
||||
with open(keyfile) as file:
|
||||
before = file.read()
|
||||
arg = ('init', '--encryption=keyfile', self.repository_location + '1')
|
||||
if self.FORK_DEFAULT:
|
||||
self.cmd(*arg, exit_code=2)
|
||||
else:
|
||||
with pytest.raises(borg.helpers.errors.Error):
|
||||
self.cmd(*arg)
|
||||
with open(keyfile) as file:
|
||||
after = file.read()
|
||||
assert before == after
|
||||
|
||||
def check_cache(self):
|
||||
# First run a regular borg check
|
||||
self.cmd('check', self.repository_location)
|
||||
|
|
Loading…
Reference in a new issue