mirror of https://github.com/borgbackup/borg.git
Test: borg init refuses to overwrite keyfile
https://github.com/borgbackup/borg/pull/6046 neglected to add a regression test
This commit is contained in:
parent
cde1f491aa
commit
29201a0eb5
|
@ -28,6 +28,7 @@ from unittest.mock import patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import borg
|
import borg
|
||||||
|
import borg.helpers.errors
|
||||||
from .. import xattr, helpers, platform
|
from .. import xattr, helpers, platform
|
||||||
from ..archive import Archive, ChunkBuffer
|
from ..archive import Archive, ChunkBuffer
|
||||||
from ..archiver import Archiver, parse_storage_quota, PURE_PYTHON_MSGPACK_WARNING
|
from ..archiver import Archiver, parse_storage_quota, PURE_PYTHON_MSGPACK_WARNING
|
||||||
|
@ -2864,6 +2865,21 @@ class ArchiverTestCase(ArchiverTestCaseBase):
|
||||||
with pytest.raises(Repository.AlreadyExists):
|
with pytest.raises(Repository.AlreadyExists):
|
||||||
self.cmd('init', '--encryption=repokey', self.repository_location + '/nested')
|
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()
|
||||||
|
with pytest.raises(borg.helpers.errors.Error):
|
||||||
|
self.cmd('init', '--encryption=keyfile', self.repository_location + '1')
|
||||||
|
with open(keyfile) as file:
|
||||||
|
after = file.read()
|
||||||
|
assert before == after
|
||||||
|
|
||||||
def check_cache(self):
|
def check_cache(self):
|
||||||
# First run a regular borg check
|
# First run a regular borg check
|
||||||
self.cmd('check', self.repository_location)
|
self.cmd('check', self.repository_location)
|
||||||
|
|
Loading…
Reference in New Issue