archiver.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. import os
  2. from io import StringIO
  3. import stat
  4. import subprocess
  5. import sys
  6. import shutil
  7. import tempfile
  8. import time
  9. import unittest
  10. from hashlib import sha256
  11. from attic import xattr
  12. from attic.archive import Archive, ChunkBuffer
  13. from attic.archiver import Archiver
  14. from attic.crypto import bytes16_to_int, num_aes_blocks
  15. from attic.helpers import Manifest
  16. from attic.key import parser
  17. from attic.remote import RemoteRepository, PathNotAllowed
  18. from attic.repository import Repository
  19. from attic.testsuite import AtticTestCase
  20. from attic.testsuite.mock import patch
  21. try:
  22. import llfuse
  23. has_llfuse = True
  24. except ImportError:
  25. has_llfuse = False
  26. has_lchflags = hasattr(os, 'lchflags')
  27. src_dir = os.path.join(os.getcwd(), os.path.dirname(__file__), '..')
  28. class changedir:
  29. def __init__(self, dir):
  30. self.dir = dir
  31. def __enter__(self):
  32. self.old = os.getcwd()
  33. os.chdir(self.dir)
  34. def __exit__(self, *args, **kw):
  35. os.chdir(self.old)
  36. class ArchiverTestCaseBase(AtticTestCase):
  37. prefix = ''
  38. def setUp(self):
  39. os.environ['ATTIC_CHECK_I_KNOW_WHAT_I_AM_DOING'] = '1'
  40. self.archiver = Archiver()
  41. self.tmpdir = tempfile.mkdtemp()
  42. self.repository_path = os.path.join(self.tmpdir, 'repository')
  43. self.repository_location = self.prefix + self.repository_path
  44. self.input_path = os.path.join(self.tmpdir, 'input')
  45. self.output_path = os.path.join(self.tmpdir, 'output')
  46. self.keys_path = os.path.join(self.tmpdir, 'keys')
  47. self.cache_path = os.path.join(self.tmpdir, 'cache')
  48. self.exclude_file_path = os.path.join(self.tmpdir, 'excludes')
  49. os.environ['ATTIC_KEYS_DIR'] = self.keys_path
  50. os.environ['ATTIC_CACHE_DIR'] = self.cache_path
  51. os.mkdir(self.input_path)
  52. os.mkdir(self.output_path)
  53. os.mkdir(self.keys_path)
  54. os.mkdir(self.cache_path)
  55. with open(self.exclude_file_path, 'wb') as fd:
  56. fd.write(b'input/file2\n# A commment line, then a blank line\n\n')
  57. self._old_wd = os.getcwd()
  58. os.chdir(self.tmpdir)
  59. def tearDown(self):
  60. shutil.rmtree(self.tmpdir)
  61. os.chdir(self._old_wd)
  62. def attic(self, *args, **kw):
  63. exit_code = kw.get('exit_code', 0)
  64. fork = kw.get('fork', False)
  65. if fork:
  66. try:
  67. output = subprocess.check_output((sys.executable, '-m', 'attic.archiver') + args)
  68. ret = 0
  69. except subprocess.CalledProcessError as e:
  70. output = e.output
  71. ret = e.returncode
  72. output = os.fsdecode(output)
  73. if ret != exit_code:
  74. print(output)
  75. self.assert_equal(exit_code, ret)
  76. return output
  77. args = list(args)
  78. stdout, stderr = sys.stdout, sys.stderr
  79. try:
  80. output = StringIO()
  81. sys.stdout = sys.stderr = output
  82. ret = self.archiver.run(args)
  83. sys.stdout, sys.stderr = stdout, stderr
  84. if ret != exit_code:
  85. print(output.getvalue())
  86. self.assert_equal(exit_code, ret)
  87. return output.getvalue()
  88. finally:
  89. sys.stdout, sys.stderr = stdout, stderr
  90. def create_src_archive(self, name):
  91. self.attic('create', self.repository_location + '::' + name, src_dir)
  92. class ArchiverTestCase(ArchiverTestCaseBase):
  93. def create_regular_file(self, name, size=0, contents=None):
  94. filename = os.path.join(self.input_path, name)
  95. if not os.path.exists(os.path.dirname(filename)):
  96. os.makedirs(os.path.dirname(filename))
  97. with open(filename, 'wb') as fd:
  98. if contents is None:
  99. contents = b'X' * size
  100. fd.write(contents)
  101. def create_test_files(self):
  102. """Create a minimal test case including all supported file types
  103. """
  104. # File
  105. self.create_regular_file('empty', size=0)
  106. # next code line raises OverflowError on 32bit cpu (raspberry pi 2):
  107. # 2600-01-01 > 2**64 ns
  108. #os.utime('input/empty', (19880895600, 19880895600))
  109. # thus, we better test with something not that far in future:
  110. # 2038-01-19 (1970 + 2^31 - 1 seconds) is the 32bit "deadline":
  111. os.utime('input/empty', (2**31 - 1, 2**31 - 1))
  112. self.create_regular_file('file1', size=1024 * 80)
  113. self.create_regular_file('flagfile', size=1024)
  114. # Directory
  115. self.create_regular_file('dir2/file2', size=1024 * 80)
  116. # File owner
  117. os.chown('input/file1', 100, 200)
  118. # File mode
  119. os.chmod('input/file1', 0o7755)
  120. os.chmod('input/dir2', 0o555)
  121. # Block device
  122. os.mknod('input/bdev', 0o600 | stat.S_IFBLK, os.makedev(10, 20))
  123. # Char device
  124. os.mknod('input/cdev', 0o600 | stat.S_IFCHR, os.makedev(30, 40))
  125. # Hard link
  126. os.link(os.path.join(self.input_path, 'file1'),
  127. os.path.join(self.input_path, 'hardlink'))
  128. # Symlink
  129. os.symlink('somewhere', os.path.join(self.input_path, 'link1'))
  130. if xattr.is_enabled(self.input_path):
  131. xattr.setxattr(os.path.join(self.input_path, 'file1'), 'user.foo', b'bar')
  132. # XXX this always fails for me
  133. # ubuntu 14.04, on a TMP dir filesystem with user_xattr, using fakeroot
  134. # same for newer ubuntu and centos.
  135. # if this is supported just on specific platform, platform should be checked first,
  136. # so that the test setup for all tests using it does not fail here always for others.
  137. #xattr.setxattr(os.path.join(self.input_path, 'link1'), 'user.foo_symlink', b'bar_symlink', follow_symlinks=False)
  138. # FIFO node
  139. os.mkfifo(os.path.join(self.input_path, 'fifo1'))
  140. if has_lchflags:
  141. os.lchflags(os.path.join(self.input_path, 'flagfile'), stat.UF_NODUMP)
  142. def test_basic_functionality(self):
  143. self.create_test_files()
  144. self.attic('init', self.repository_location)
  145. self.attic('create', self.repository_location + '::test', 'input')
  146. self.attic('create', self.repository_location + '::test.2', 'input')
  147. with changedir('output'):
  148. self.attic('extract', self.repository_location + '::test')
  149. self.assert_equal(len(self.attic('list', self.repository_location).splitlines()), 2)
  150. self.assert_equal(len(self.attic('list', self.repository_location + '::test').splitlines()), 11)
  151. self.assert_dirs_equal('input', 'output/input')
  152. info_output = self.attic('info', self.repository_location + '::test')
  153. self.assert_in('Number of files: 4', info_output)
  154. shutil.rmtree(self.cache_path)
  155. info_output2 = self.attic('info', self.repository_location + '::test')
  156. # info_output2 starts with some "initializing cache" text but should
  157. # end the same way as info_output
  158. assert info_output2.endswith(info_output)
  159. def test_strip_components(self):
  160. self.attic('init', self.repository_location)
  161. self.create_regular_file('dir/file')
  162. self.attic('create', self.repository_location + '::test', 'input')
  163. with changedir('output'):
  164. self.attic('extract', self.repository_location + '::test', '--strip-components', '3')
  165. self.assert_true(not os.path.exists('file'))
  166. with self.assert_creates_file('file'):
  167. self.attic('extract', self.repository_location + '::test', '--strip-components', '2')
  168. with self.assert_creates_file('dir/file'):
  169. self.attic('extract', self.repository_location + '::test', '--strip-components', '1')
  170. with self.assert_creates_file('input/dir/file'):
  171. self.attic('extract', self.repository_location + '::test', '--strip-components', '0')
  172. def test_extract_include_exclude(self):
  173. self.attic('init', self.repository_location)
  174. self.create_regular_file('file1', size=1024 * 80)
  175. self.create_regular_file('file2', size=1024 * 80)
  176. self.create_regular_file('file3', size=1024 * 80)
  177. self.create_regular_file('file4', size=1024 * 80)
  178. self.attic('create', '--exclude=input/file4', self.repository_location + '::test', 'input')
  179. with changedir('output'):
  180. self.attic('extract', self.repository_location + '::test', 'input/file1', )
  181. self.assert_equal(sorted(os.listdir('output/input')), ['file1'])
  182. with changedir('output'):
  183. self.attic('extract', '--exclude=input/file2', self.repository_location + '::test')
  184. self.assert_equal(sorted(os.listdir('output/input')), ['file1', 'file3'])
  185. with changedir('output'):
  186. self.attic('extract', '--exclude-from=' + self.exclude_file_path, self.repository_location + '::test')
  187. self.assert_equal(sorted(os.listdir('output/input')), ['file1', 'file3'])
  188. def test_exclude_caches(self):
  189. self.attic('init', self.repository_location)
  190. self.create_regular_file('file1', size=1024 * 80)
  191. self.create_regular_file('cache1/CACHEDIR.TAG', contents=b'Signature: 8a477f597d28d172789f06886806bc55 extra stuff')
  192. self.create_regular_file('cache2/CACHEDIR.TAG', contents=b'invalid signature')
  193. self.attic('create', '--exclude-caches', self.repository_location + '::test', 'input')
  194. with changedir('output'):
  195. self.attic('extract', self.repository_location + '::test')
  196. self.assert_equal(sorted(os.listdir('output/input')), ['cache2', 'file1'])
  197. self.assert_equal(sorted(os.listdir('output/input/cache2')), ['CACHEDIR.TAG'])
  198. def test_path_normalization(self):
  199. self.attic('init', self.repository_location)
  200. self.create_regular_file('dir1/dir2/file', size=1024 * 80)
  201. with changedir('input/dir1/dir2'):
  202. self.attic('create', self.repository_location + '::test', '../../../input/dir1/../dir1/dir2/..')
  203. output = self.attic('list', self.repository_location + '::test')
  204. self.assert_not_in('..', output)
  205. self.assert_in(' input/dir1/dir2/file', output)
  206. def test_exclude_normalization(self):
  207. self.attic('init', self.repository_location)
  208. self.create_regular_file('file1', size=1024 * 80)
  209. self.create_regular_file('file2', size=1024 * 80)
  210. with changedir('input'):
  211. self.attic('create', '--exclude=file1', self.repository_location + '::test1', '.')
  212. with changedir('output'):
  213. self.attic('extract', self.repository_location + '::test1')
  214. self.assert_equal(sorted(os.listdir('output')), ['file2'])
  215. with changedir('input'):
  216. self.attic('create', '--exclude=./file1', self.repository_location + '::test2', '.')
  217. with changedir('output'):
  218. self.attic('extract', self.repository_location + '::test2')
  219. self.assert_equal(sorted(os.listdir('output')), ['file2'])
  220. self.attic('create', '--exclude=input/./file1', self.repository_location + '::test3', 'input')
  221. with changedir('output'):
  222. self.attic('extract', self.repository_location + '::test3')
  223. self.assert_equal(sorted(os.listdir('output/input')), ['file2'])
  224. def test_repeated_files(self):
  225. self.create_regular_file('file1', size=1024 * 80)
  226. self.attic('init', self.repository_location)
  227. self.attic('create', self.repository_location + '::test', 'input', 'input')
  228. def test_overwrite(self):
  229. self.create_regular_file('file1', size=1024 * 80)
  230. self.create_regular_file('dir2/file2', size=1024 * 80)
  231. self.attic('init', self.repository_location)
  232. self.attic('create', self.repository_location + '::test', 'input')
  233. # Overwriting regular files and directories should be supported
  234. os.mkdir('output/input')
  235. os.mkdir('output/input/file1')
  236. os.mkdir('output/input/dir2')
  237. with changedir('output'):
  238. self.attic('extract', self.repository_location + '::test')
  239. self.assert_dirs_equal('input', 'output/input')
  240. # But non-empty dirs should fail
  241. os.unlink('output/input/file1')
  242. os.mkdir('output/input/file1')
  243. os.mkdir('output/input/file1/dir')
  244. with changedir('output'):
  245. self.attic('extract', self.repository_location + '::test', exit_code=1)
  246. def test_rename(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. self.attic('create', self.repository_location + '::test.2', 'input')
  252. self.attic('extract', '--dry-run', self.repository_location + '::test')
  253. self.attic('extract', '--dry-run', self.repository_location + '::test.2')
  254. self.attic('rename', self.repository_location + '::test', 'test.3')
  255. self.attic('extract', '--dry-run', self.repository_location + '::test.2')
  256. self.attic('rename', self.repository_location + '::test.2', 'test.4')
  257. self.attic('extract', '--dry-run', self.repository_location + '::test.3')
  258. self.attic('extract', '--dry-run', self.repository_location + '::test.4')
  259. # Make sure both archives have been renamed
  260. repository = Repository(self.repository_path)
  261. manifest, key = Manifest.load(repository)
  262. self.assert_equal(len(manifest.archives), 2)
  263. self.assert_in('test.3', manifest.archives)
  264. self.assert_in('test.4', manifest.archives)
  265. def test_delete(self):
  266. self.create_regular_file('file1', size=1024 * 80)
  267. self.create_regular_file('dir2/file2', size=1024 * 80)
  268. self.attic('init', self.repository_location)
  269. self.attic('create', self.repository_location + '::test', 'input')
  270. self.attic('create', self.repository_location + '::test.2', 'input')
  271. self.attic('extract', '--dry-run', self.repository_location + '::test')
  272. self.attic('extract', '--dry-run', self.repository_location + '::test.2')
  273. self.attic('delete', self.repository_location + '::test')
  274. self.attic('extract', '--dry-run', self.repository_location + '::test.2')
  275. self.attic('delete', self.repository_location + '::test.2')
  276. # Make sure all data except the manifest has been deleted
  277. repository = Repository(self.repository_path)
  278. self.assert_equal(len(repository), 1)
  279. def test_corrupted_repository(self):
  280. self.attic('init', self.repository_location)
  281. self.create_src_archive('test')
  282. self.attic('extract', '--dry-run', self.repository_location + '::test')
  283. self.attic('check', self.repository_location)
  284. name = sorted(os.listdir(os.path.join(self.tmpdir, 'repository', 'data', '0')), reverse=True)[0]
  285. with open(os.path.join(self.tmpdir, 'repository', 'data', '0', name), 'r+') as fd:
  286. fd.seek(100)
  287. fd.write('XXXX')
  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 hash not in seen:
  372. seen.add(hash)
  373. mac, meta, data = parser(data)
  374. num_blocks = num_aes_blocks(len(data))
  375. nonce = bytes16_to_int(meta.iv)
  376. for counter in range(nonce, nonce + num_blocks):
  377. self.assert_not_in(counter, used)
  378. used.add(counter)
  379. self.create_test_files()
  380. os.environ['ATTIC_PASSPHRASE'] = 'passphrase'
  381. self.attic('init', '--encryption=' + method, self.repository_location)
  382. verify_uniqueness()
  383. self.attic('create', self.repository_location + '::test', 'input')
  384. verify_uniqueness()
  385. self.attic('create', self.repository_location + '::test.2', 'input')
  386. verify_uniqueness()
  387. self.attic('delete', self.repository_location + '::test.2')
  388. verify_uniqueness()
  389. self.assert_equal(used, set(range(len(used))))
  390. def test_aes_counter_uniqueness_keyfile(self):
  391. self.verify_aes_counter_uniqueness('keyfile')
  392. def test_aes_counter_uniqueness_passphrase(self):
  393. self.verify_aes_counter_uniqueness('passphrase')
  394. class ArchiverCheckTestCase(ArchiverTestCaseBase):
  395. def setUp(self):
  396. super(ArchiverCheckTestCase, self).setUp()
  397. with patch.object(ChunkBuffer, 'BUFFER_SIZE', 10):
  398. self.attic('init', self.repository_location)
  399. self.create_src_archive('archive1')
  400. self.create_src_archive('archive2')
  401. def open_archive(self, name):
  402. repository = Repository(self.repository_path)
  403. manifest, key = Manifest.load(repository)
  404. archive = Archive(repository, key, manifest, name)
  405. return archive, repository
  406. def test_check_usage(self):
  407. output = self.attic('check', self.repository_location, exit_code=0)
  408. self.assert_in('Starting repository check', output)
  409. self.assert_in('Starting archive consistency check', output)
  410. output = self.attic('check', '--repository-only', self.repository_location, exit_code=0)
  411. self.assert_in('Starting repository check', output)
  412. self.assert_not_in('Starting archive consistency check', output)
  413. output = self.attic('check', '--archives-only', self.repository_location, exit_code=0)
  414. self.assert_not_in('Starting repository check', output)
  415. self.assert_in('Starting archive consistency check', output)
  416. def test_missing_file_chunk(self):
  417. archive, repository = self.open_archive('archive1')
  418. for item in archive.iter_items():
  419. if item[b'path'].endswith('testsuite/archiver.py'):
  420. repository.delete(item[b'chunks'][-1][0])
  421. break
  422. repository.commit()
  423. self.attic('check', self.repository_location, exit_code=1)
  424. self.attic('check', '--repair', self.repository_location, exit_code=0)
  425. self.attic('check', self.repository_location, exit_code=0)
  426. def test_missing_archive_item_chunk(self):
  427. archive, repository = self.open_archive('archive1')
  428. repository.delete(archive.metadata[b'items'][-5])
  429. repository.commit()
  430. self.attic('check', self.repository_location, exit_code=1)
  431. self.attic('check', '--repair', self.repository_location, exit_code=0)
  432. self.attic('check', self.repository_location, exit_code=0)
  433. def test_missing_archive_metadata(self):
  434. archive, repository = self.open_archive('archive1')
  435. repository.delete(archive.id)
  436. repository.commit()
  437. self.attic('check', self.repository_location, exit_code=1)
  438. self.attic('check', '--repair', self.repository_location, exit_code=0)
  439. self.attic('check', self.repository_location, exit_code=0)
  440. def test_missing_manifest(self):
  441. archive, repository = self.open_archive('archive1')
  442. repository.delete(Manifest.manifest_id(repository))
  443. repository.commit()
  444. self.attic('check', self.repository_location, exit_code=1)
  445. output = self.attic('check', '--repair', self.repository_location, exit_code=0)
  446. self.assert_in('archive1', output)
  447. self.assert_in('archive2', output)
  448. self.attic('check', self.repository_location, exit_code=0)
  449. def test_extra_chunks(self):
  450. self.attic('check', self.repository_location, exit_code=0)
  451. repository = Repository(self.repository_location)
  452. repository.put(b'0123456789012345', b'xxxx')
  453. repository.commit()
  454. repository.close()
  455. self.attic('check', self.repository_location, exit_code=1)
  456. self.attic('check', self.repository_location, exit_code=1)
  457. self.attic('check', '--repair', self.repository_location, exit_code=0)
  458. self.attic('check', self.repository_location, exit_code=0)
  459. self.attic('extract', '--dry-run', self.repository_location + '::archive1', exit_code=0)
  460. class RemoteArchiverTestCase(ArchiverTestCase):
  461. prefix = '__testsuite__:'
  462. def test_remote_repo_restrict_to_path(self):
  463. self.attic('init', self.repository_location)
  464. path_prefix = os.path.dirname(self.repository_path)
  465. with patch.object(RemoteRepository, 'extra_test_args', ['--restrict-to-path', '/foo']):
  466. self.assert_raises(PathNotAllowed, lambda: self.attic('init', self.repository_location + '_1'))
  467. with patch.object(RemoteRepository, 'extra_test_args', ['--restrict-to-path', path_prefix]):
  468. self.attic('init', self.repository_location + '_2')
  469. with patch.object(RemoteRepository, 'extra_test_args', ['--restrict-to-path', '/foo', '--restrict-to-path', path_prefix]):
  470. self.attic('init', self.repository_location + '_3')