2
0

archiver.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. from binascii import hexlify
  2. from configparser import RawConfigParser
  3. import os
  4. from io import StringIO
  5. import stat
  6. import subprocess
  7. import sys
  8. import shutil
  9. import tempfile
  10. import time
  11. import unittest
  12. from hashlib import sha256
  13. from attic import xattr
  14. from attic.archive import Archive, ChunkBuffer
  15. from attic.archiver import Archiver
  16. from attic.cache import Cache
  17. from attic.crypto import bytes_to_long, num_aes_blocks
  18. from attic.helpers import Manifest
  19. from attic.remote import RemoteRepository, PathNotAllowed
  20. from attic.repository import Repository
  21. from attic.testsuite import AtticTestCase
  22. from attic.testsuite.mock import patch
  23. try:
  24. import llfuse
  25. has_llfuse = True
  26. except ImportError:
  27. has_llfuse = False
  28. has_lchflags = hasattr(os, 'lchflags')
  29. src_dir = os.path.join(os.getcwd(), os.path.dirname(__file__), '..')
  30. class changedir:
  31. def __init__(self, dir):
  32. self.dir = dir
  33. def __enter__(self):
  34. self.old = os.getcwd()
  35. os.chdir(self.dir)
  36. def __exit__(self, *args, **kw):
  37. os.chdir(self.old)
  38. class environment_variable:
  39. def __init__(self, **values):
  40. self.values = values
  41. self.old_values = {}
  42. def __enter__(self):
  43. for k, v in self.values.items():
  44. self.old_values[k] = os.environ.get(k)
  45. os.environ[k] = v
  46. def __exit__(self, *args, **kw):
  47. for k, v in self.old_values.items():
  48. if v is not None:
  49. os.environ[k] = v
  50. class ArchiverTestCaseBase(AtticTestCase):
  51. prefix = ''
  52. def setUp(self):
  53. os.environ['ATTIC_CHECK_I_KNOW_WHAT_I_AM_DOING'] = '1'
  54. self.archiver = Archiver()
  55. self.tmpdir = tempfile.mkdtemp()
  56. self.repository_path = os.path.join(self.tmpdir, 'repository')
  57. self.repository_location = self.prefix + self.repository_path
  58. self.input_path = os.path.join(self.tmpdir, 'input')
  59. self.output_path = os.path.join(self.tmpdir, 'output')
  60. self.keys_path = os.path.join(self.tmpdir, 'keys')
  61. self.cache_path = os.path.join(self.tmpdir, 'cache')
  62. self.exclude_file_path = os.path.join(self.tmpdir, 'excludes')
  63. os.environ['ATTIC_KEYS_DIR'] = self.keys_path
  64. os.environ['ATTIC_CACHE_DIR'] = self.cache_path
  65. os.mkdir(self.input_path)
  66. os.mkdir(self.output_path)
  67. os.mkdir(self.keys_path)
  68. os.mkdir(self.cache_path)
  69. with open(self.exclude_file_path, 'wb') as fd:
  70. fd.write(b'input/file2\n# A commment line, then a blank line\n\n')
  71. self._old_wd = os.getcwd()
  72. os.chdir(self.tmpdir)
  73. def tearDown(self):
  74. shutil.rmtree(self.tmpdir)
  75. os.chdir(self._old_wd)
  76. def attic(self, *args, **kw):
  77. exit_code = kw.get('exit_code', 0)
  78. fork = kw.get('fork', False)
  79. if fork:
  80. try:
  81. output = subprocess.check_output((sys.executable, '-m', 'attic.archiver') + args)
  82. ret = 0
  83. except subprocess.CalledProcessError as e:
  84. output = e.output
  85. ret = e.returncode
  86. output = os.fsdecode(output)
  87. if ret != exit_code:
  88. print(output)
  89. self.assert_equal(exit_code, ret)
  90. return output
  91. args = list(args)
  92. stdin, stdout, stderr = sys.stdin, sys.stdout, sys.stderr
  93. try:
  94. sys.stdin = StringIO()
  95. output = StringIO()
  96. sys.stdout = sys.stderr = output
  97. ret = self.archiver.run(args)
  98. sys.stdin, sys.stdout, sys.stderr = stdin, stdout, stderr
  99. if ret != exit_code:
  100. print(output.getvalue())
  101. self.assert_equal(exit_code, ret)
  102. return output.getvalue()
  103. finally:
  104. sys.stdin, sys.stdout, sys.stderr = stdin, stdout, stderr
  105. def create_src_archive(self, name):
  106. self.attic('create', self.repository_location + '::' + name, src_dir)
  107. class ArchiverTestCase(ArchiverTestCaseBase):
  108. def create_regular_file(self, name, size=0, contents=None):
  109. filename = os.path.join(self.input_path, name)
  110. if not os.path.exists(os.path.dirname(filename)):
  111. os.makedirs(os.path.dirname(filename))
  112. with open(filename, 'wb') as fd:
  113. if contents is None:
  114. contents = b'X' * size
  115. fd.write(contents)
  116. def create_test_files(self):
  117. """Create a minimal test case including all supported file types
  118. """
  119. # File
  120. self.create_regular_file('empty', size=0)
  121. # 2600-01-01 > 2**64 ns
  122. os.utime('input/empty', (19880895600, 19880895600))
  123. self.create_regular_file('file1', size=1024 * 80)
  124. self.create_regular_file('flagfile', size=1024)
  125. # Directory
  126. self.create_regular_file('dir2/file2', size=1024 * 80)
  127. # File owner
  128. os.chown('input/file1', 100, 200)
  129. # File mode
  130. os.chmod('input/file1', 0o7755)
  131. os.chmod('input/dir2', 0o555)
  132. # Block device
  133. os.mknod('input/bdev', 0o600 | stat.S_IFBLK, os.makedev(10, 20))
  134. # Char device
  135. os.mknod('input/cdev', 0o600 | stat.S_IFCHR, os.makedev(30, 40))
  136. # Hard link
  137. os.link(os.path.join(self.input_path, 'file1'),
  138. os.path.join(self.input_path, 'hardlink'))
  139. # Symlink
  140. os.symlink('somewhere', os.path.join(self.input_path, 'link1'))
  141. if xattr.is_enabled():
  142. xattr.setxattr(os.path.join(self.input_path, 'file1'), 'user.foo', b'bar')
  143. xattr.setxattr(os.path.join(self.input_path, 'link1'), 'user.foo_symlink', b'bar_symlink', follow_symlinks=False)
  144. # FIFO node
  145. os.mkfifo(os.path.join(self.input_path, 'fifo1'))
  146. if has_lchflags:
  147. os.lchflags(os.path.join(self.input_path, 'flagfile'), stat.UF_NODUMP)
  148. def test_basic_functionality(self):
  149. self.create_test_files()
  150. self.attic('init', self.repository_location)
  151. self.attic('create', self.repository_location + '::test', 'input')
  152. self.attic('create', self.repository_location + '::test.2', 'input')
  153. with changedir('output'):
  154. self.attic('extract', self.repository_location + '::test')
  155. self.assert_equal(len(self.attic('list', self.repository_location).splitlines()), 2)
  156. self.assert_equal(len(self.attic('list', self.repository_location + '::test').splitlines()), 11)
  157. self.assert_dirs_equal('input', 'output/input')
  158. info_output = self.attic('info', self.repository_location + '::test')
  159. self.assert_in('Number of files: 4', info_output)
  160. shutil.rmtree(self.cache_path)
  161. with environment_variable(ATTIC_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK='1'):
  162. info_output2 = self.attic('info', self.repository_location + '::test')
  163. # info_output2 starts with some "initializing cache" text but should
  164. # end the same way as info_output
  165. assert info_output2.endswith(info_output)
  166. def _extract_repository_id(self, path):
  167. return Repository(self.repository_path).id
  168. def _set_repository_id(self, path, id):
  169. config = RawConfigParser()
  170. config.read(os.path.join(path, 'config'))
  171. config.set('repository', 'id', hexlify(id).decode('ascii'))
  172. with open(os.path.join(path, 'config'), 'w') as fd:
  173. config.write(fd)
  174. return Repository(self.repository_path).id
  175. def test_repository_swap_detection(self):
  176. self.create_test_files()
  177. os.environ['ATTIC_PASSPHRASE'] = 'passphrase'
  178. self.attic('init', '--encryption=passphrase', self.repository_location)
  179. repository_id = self._extract_repository_id(self.repository_path)
  180. self.attic('create', self.repository_location + '::test', 'input')
  181. shutil.rmtree(self.repository_path)
  182. self.attic('init', '--encryption=none', self.repository_location)
  183. self._set_repository_id(self.repository_path, repository_id)
  184. self.assert_equal(repository_id, self._extract_repository_id(self.repository_path))
  185. self.assert_raises(Cache.EncryptionMethodMismatch, lambda :self.attic('create', self.repository_location + '::test.2', 'input'))
  186. def test_repository_swap_detection2(self):
  187. self.create_test_files()
  188. self.attic('init', '--encryption=none', self.repository_location + '_unencrypted')
  189. os.environ['ATTIC_PASSPHRASE'] = 'passphrase'
  190. self.attic('init', '--encryption=passphrase', self.repository_location + '_encrypted')
  191. self.attic('create', self.repository_location + '_encrypted::test', 'input')
  192. shutil.rmtree(self.repository_path + '_encrypted')
  193. os.rename(self.repository_path + '_unencrypted', self.repository_path + '_encrypted')
  194. self.assert_raises(Cache.RepositoryAccessAborted, lambda :self.attic('create', self.repository_location + '_encrypted::test.2', 'input'))
  195. def test_strip_components(self):
  196. self.attic('init', self.repository_location)
  197. self.create_regular_file('dir/file')
  198. self.attic('create', self.repository_location + '::test', 'input')
  199. with changedir('output'):
  200. self.attic('extract', self.repository_location + '::test', '--strip-components', '3')
  201. self.assert_true(not os.path.exists('file'))
  202. with self.assert_creates_file('file'):
  203. self.attic('extract', self.repository_location + '::test', '--strip-components', '2')
  204. with self.assert_creates_file('dir/file'):
  205. self.attic('extract', self.repository_location + '::test', '--strip-components', '1')
  206. with self.assert_creates_file('input/dir/file'):
  207. self.attic('extract', self.repository_location + '::test', '--strip-components', '0')
  208. def test_extract_include_exclude(self):
  209. self.attic('init', self.repository_location)
  210. self.create_regular_file('file1', size=1024 * 80)
  211. self.create_regular_file('file2', size=1024 * 80)
  212. self.create_regular_file('file3', size=1024 * 80)
  213. self.create_regular_file('file4', size=1024 * 80)
  214. self.attic('create', '--exclude=input/file4', self.repository_location + '::test', 'input')
  215. with changedir('output'):
  216. self.attic('extract', self.repository_location + '::test', 'input/file1', )
  217. self.assert_equal(sorted(os.listdir('output/input')), ['file1'])
  218. with changedir('output'):
  219. self.attic('extract', '--exclude=input/file2', self.repository_location + '::test')
  220. self.assert_equal(sorted(os.listdir('output/input')), ['file1', 'file3'])
  221. with changedir('output'):
  222. self.attic('extract', '--exclude-from=' + self.exclude_file_path, self.repository_location + '::test')
  223. self.assert_equal(sorted(os.listdir('output/input')), ['file1', 'file3'])
  224. def test_exclude_caches(self):
  225. self.attic('init', self.repository_location)
  226. self.create_regular_file('file1', size=1024 * 80)
  227. self.create_regular_file('cache1/CACHEDIR.TAG', contents = b'Signature: 8a477f597d28d172789f06886806bc55 extra stuff')
  228. self.create_regular_file('cache2/CACHEDIR.TAG', contents = b'invalid signature')
  229. self.attic('create', '--exclude-caches', self.repository_location + '::test', 'input')
  230. with changedir('output'):
  231. self.attic('extract', self.repository_location + '::test')
  232. self.assert_equal(sorted(os.listdir('output/input')), ['cache2', 'file1'])
  233. self.assert_equal(sorted(os.listdir('output/input/cache2')), ['CACHEDIR.TAG'])
  234. def test_path_normalization(self):
  235. self.attic('init', self.repository_location)
  236. self.create_regular_file('dir1/dir2/file', size=1024 * 80)
  237. with changedir('input/dir1/dir2'):
  238. self.attic('create', self.repository_location + '::test', '../../../input/dir1/../dir1/dir2/..')
  239. output = self.attic('list', self.repository_location + '::test')
  240. self.assert_not_in('..', output)
  241. self.assert_in(' input/dir1/dir2/file', output)
  242. def test_repeated_files(self):
  243. self.create_regular_file('file1', size=1024 * 80)
  244. self.attic('init', self.repository_location)
  245. self.attic('create', self.repository_location + '::test', 'input', 'input')
  246. def test_overwrite(self):
  247. self.create_regular_file('file1', size=1024 * 80)
  248. self.create_regular_file('dir2/file2', size=1024 * 80)
  249. self.attic('init', self.repository_location)
  250. self.attic('create', self.repository_location + '::test', 'input')
  251. # Overwriting regular files and directories should be supported
  252. os.mkdir('output/input')
  253. os.mkdir('output/input/file1')
  254. os.mkdir('output/input/dir2')
  255. with changedir('output'):
  256. self.attic('extract', self.repository_location + '::test')
  257. self.assert_dirs_equal('input', 'output/input')
  258. # But non-empty dirs should fail
  259. os.unlink('output/input/file1')
  260. os.mkdir('output/input/file1')
  261. os.mkdir('output/input/file1/dir')
  262. with changedir('output'):
  263. self.attic('extract', self.repository_location + '::test', exit_code=1)
  264. def test_delete(self):
  265. self.create_regular_file('file1', size=1024 * 80)
  266. self.create_regular_file('dir2/file2', size=1024 * 80)
  267. self.attic('init', self.repository_location)
  268. self.attic('create', self.repository_location + '::test', 'input')
  269. self.attic('create', self.repository_location + '::test.2', 'input')
  270. self.attic('extract', '--dry-run', self.repository_location + '::test')
  271. self.attic('extract', '--dry-run', self.repository_location + '::test.2')
  272. self.attic('delete', self.repository_location + '::test')
  273. self.attic('extract', '--dry-run', self.repository_location + '::test.2')
  274. self.attic('delete', self.repository_location + '::test.2')
  275. # Make sure all data except the manifest has been deleted
  276. repository = Repository(self.repository_path)
  277. self.assert_equal(len(repository), 1)
  278. def test_corrupted_repository(self):
  279. self.attic('init', self.repository_location)
  280. self.create_src_archive('test')
  281. self.attic('extract', '--dry-run', self.repository_location + '::test')
  282. self.attic('check', self.repository_location)
  283. name = sorted(os.listdir(os.path.join(self.tmpdir, 'repository', 'data', '0')), reverse=True)[0]
  284. fd = open(os.path.join(self.tmpdir, 'repository', 'data', '0', name), 'r+')
  285. fd.seek(100)
  286. fd.write('XXXX')
  287. fd.close()
  288. self.attic('check', self.repository_location, exit_code=1)
  289. def test_readonly_repository(self):
  290. self.attic('init', self.repository_location)
  291. self.create_src_archive('test')
  292. os.system('chmod -R ugo-w ' + self.repository_path)
  293. try:
  294. self.attic('extract', '--dry-run', self.repository_location + '::test')
  295. finally:
  296. # Restore permissions so shutil.rmtree is able to delete it
  297. os.system('chmod -R u+w ' + self.repository_path)
  298. def test_cmdline_compatibility(self):
  299. self.create_regular_file('file1', size=1024 * 80)
  300. self.attic('init', self.repository_location)
  301. self.attic('create', self.repository_location + '::test', 'input')
  302. output = self.attic('verify', '-v', self.repository_location + '::test')
  303. self.assert_in('"attic verify" has been deprecated', output)
  304. output = self.attic('prune', self.repository_location, '--hourly=1')
  305. self.assert_in('"--hourly" has been deprecated. Use "--keep-hourly" instead', output)
  306. def test_prune_repository(self):
  307. self.attic('init', self.repository_location)
  308. self.attic('create', self.repository_location + '::test1', src_dir)
  309. self.attic('create', self.repository_location + '::test2', src_dir)
  310. output = self.attic('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2')
  311. self.assert_in('Keeping archive: test2', output)
  312. self.assert_in('Would prune: test1', output)
  313. output = self.attic('list', self.repository_location)
  314. self.assert_in('test1', output)
  315. self.assert_in('test2', output)
  316. self.attic('prune', self.repository_location, '--keep-daily=2')
  317. output = self.attic('list', self.repository_location)
  318. self.assert_not_in('test1', output)
  319. self.assert_in('test2', output)
  320. def test_usage(self):
  321. self.assert_raises(SystemExit, lambda: self.attic())
  322. self.assert_raises(SystemExit, lambda: self.attic('-h'))
  323. @unittest.skipUnless(has_llfuse, 'llfuse not installed')
  324. def test_fuse_mount_repository(self):
  325. mountpoint = os.path.join(self.tmpdir, 'mountpoint')
  326. os.mkdir(mountpoint)
  327. self.attic('init', self.repository_location)
  328. self.create_test_files()
  329. self.attic('create', self.repository_location + '::archive', 'input')
  330. self.attic('create', self.repository_location + '::archive2', 'input')
  331. try:
  332. self.attic('mount', self.repository_location, mountpoint, fork=True)
  333. self.wait_for_mount(mountpoint)
  334. self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'archive', 'input'))
  335. self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'archive2', 'input'))
  336. finally:
  337. if sys.platform.startswith('linux'):
  338. os.system('fusermount -u ' + mountpoint)
  339. else:
  340. os.system('umount ' + mountpoint)
  341. os.rmdir(mountpoint)
  342. # Give the daemon some time to exit
  343. time.sleep(.2)
  344. @unittest.skipUnless(has_llfuse, 'llfuse not installed')
  345. def test_fuse_mount_archive(self):
  346. mountpoint = os.path.join(self.tmpdir, 'mountpoint')
  347. os.mkdir(mountpoint)
  348. self.attic('init', self.repository_location)
  349. self.create_test_files()
  350. self.attic('create', self.repository_location + '::archive', 'input')
  351. try:
  352. self.attic('mount', self.repository_location + '::archive', mountpoint, fork=True)
  353. self.wait_for_mount(mountpoint)
  354. self.assert_dirs_equal(self.input_path, os.path.join(mountpoint, 'input'))
  355. finally:
  356. if sys.platform.startswith('linux'):
  357. os.system('fusermount -u ' + mountpoint)
  358. else:
  359. os.system('umount ' + mountpoint)
  360. os.rmdir(mountpoint)
  361. # Give the daemon some time to exit
  362. time.sleep(.2)
  363. def verify_aes_counter_uniqueness(self, method):
  364. seen = set() # Chunks already seen
  365. used = set() # counter values already used
  366. def verify_uniqueness():
  367. repository = Repository(self.repository_path)
  368. for key, _ in repository.open_index(repository.get_transaction_id()).iteritems():
  369. data = repository.get(key)
  370. hash = sha256(data).digest()
  371. if not hash in seen:
  372. seen.add(hash)
  373. num_blocks = num_aes_blocks(len(data) - 41)
  374. nonce = bytes_to_long(data[33:41])
  375. for counter in range(nonce, nonce + num_blocks):
  376. self.assert_not_in(counter, used)
  377. used.add(counter)
  378. self.create_test_files()
  379. os.environ['ATTIC_PASSPHRASE'] = 'passphrase'
  380. self.attic('init', '--encryption=' + method, self.repository_location)
  381. verify_uniqueness()
  382. self.attic('create', self.repository_location + '::test', 'input')
  383. verify_uniqueness()
  384. self.attic('create', self.repository_location + '::test.2', 'input')
  385. verify_uniqueness()
  386. self.attic('delete', self.repository_location + '::test.2')
  387. verify_uniqueness()
  388. self.assert_equal(used, set(range(len(used))))
  389. def test_aes_counter_uniqueness_keyfile(self):
  390. self.verify_aes_counter_uniqueness('keyfile')
  391. def test_aes_counter_uniqueness_passphrase(self):
  392. self.verify_aes_counter_uniqueness('passphrase')
  393. class ArchiverCheckTestCase(ArchiverTestCaseBase):
  394. def setUp(self):
  395. super(ArchiverCheckTestCase, self).setUp()
  396. with patch.object(ChunkBuffer, 'BUFFER_SIZE', 10):
  397. self.attic('init', self.repository_location)
  398. self.create_src_archive('archive1')
  399. self.create_src_archive('archive2')
  400. def open_archive(self, name):
  401. repository = Repository(self.repository_path)
  402. manifest, key = Manifest.load(repository)
  403. archive = Archive(repository, key, manifest, name)
  404. return archive, repository
  405. def test_check_usage(self):
  406. output = self.attic('check', self.repository_location, exit_code=0)
  407. self.assert_in('Starting repository check', output)
  408. self.assert_in('Starting archive consistency check', output)
  409. output = self.attic('check', '--repository-only', self.repository_location, exit_code=0)
  410. self.assert_in('Starting repository check', output)
  411. self.assert_not_in('Starting archive consistency check', output)
  412. output = self.attic('check', '--archives-only', self.repository_location, exit_code=0)
  413. self.assert_not_in('Starting repository check', output)
  414. self.assert_in('Starting archive consistency check', output)
  415. def test_missing_file_chunk(self):
  416. archive, repository = self.open_archive('archive1')
  417. for item in archive.iter_items():
  418. if item[b'path'].endswith('testsuite/archiver.py'):
  419. repository.delete(item[b'chunks'][-1][0])
  420. break
  421. repository.commit()
  422. self.attic('check', self.repository_location, exit_code=1)
  423. self.attic('check', '--repair', self.repository_location, exit_code=0)
  424. self.attic('check', self.repository_location, exit_code=0)
  425. def test_missing_archive_item_chunk(self):
  426. archive, repository = self.open_archive('archive1')
  427. repository.delete(archive.metadata[b'items'][-5])
  428. repository.commit()
  429. self.attic('check', self.repository_location, exit_code=1)
  430. self.attic('check', '--repair', self.repository_location, exit_code=0)
  431. self.attic('check', self.repository_location, exit_code=0)
  432. def test_missing_archive_metadata(self):
  433. archive, repository = self.open_archive('archive1')
  434. repository.delete(archive.id)
  435. repository.commit()
  436. self.attic('check', self.repository_location, exit_code=1)
  437. self.attic('check', '--repair', self.repository_location, exit_code=0)
  438. self.attic('check', self.repository_location, exit_code=0)
  439. def test_missing_manifest(self):
  440. archive, repository = self.open_archive('archive1')
  441. repository.delete(Manifest.MANIFEST_ID)
  442. repository.commit()
  443. self.attic('check', self.repository_location, exit_code=1)
  444. output = self.attic('check', '--repair', self.repository_location, exit_code=0)
  445. self.assert_in('archive1', output)
  446. self.assert_in('archive2', output)
  447. self.attic('check', self.repository_location, exit_code=0)
  448. def test_extra_chunks(self):
  449. self.attic('check', self.repository_location, exit_code=0)
  450. repository = Repository(self.repository_location)
  451. repository.put(b'01234567890123456789012345678901', b'xxxx')
  452. repository.commit()
  453. repository.close()
  454. self.attic('check', self.repository_location, exit_code=1)
  455. self.attic('check', self.repository_location, exit_code=1)
  456. self.attic('check', '--repair', self.repository_location, exit_code=0)
  457. self.attic('check', self.repository_location, exit_code=0)
  458. self.attic('extract', '--dry-run', self.repository_location + '::archive1', exit_code=0)
  459. class RemoteArchiverTestCase(ArchiverTestCase):
  460. prefix = '__testsuite__:'
  461. def test_remote_repo_restrict_to_path(self):
  462. self.attic('init', self.repository_location)
  463. path_prefix = os.path.dirname(self.repository_path)
  464. with patch.object(RemoteRepository, 'extra_test_args', ['--restrict-to-path', '/foo']):
  465. self.assert_raises(PathNotAllowed, lambda: self.attic('init', self.repository_location + '_1'))
  466. with patch.object(RemoteRepository, 'extra_test_args', ['--restrict-to-path', path_prefix]):
  467. self.attic('init', self.repository_location + '_2')
  468. with patch.object(RemoteRepository, 'extra_test_args', ['--restrict-to-path', '/foo', '--restrict-to-path', path_prefix]):
  469. self.attic('init', self.repository_location + '_3')