| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | #!/usr/bin/env python3 |
| 2 | 2 | import copy |
| 3 | from functools import partial |
| 3 | 4 | import importlib.util |
| 4 | 5 | import json |
| 5 | 6 | import os |
| ... | ... | @@ -88,7 +89,7 @@ class Shares(unittest.TestCase): |
| 88 | 89 | self.assertNotIn('password', state) |
| 89 | 90 | self.assertNotIn(created['password'], (self.cfg / 'manager.json').read_text()) |
| 90 | 91 | self.assertNotIn(created['password'], (self.cfg / 'copyparty.conf').read_text()) |
| 91 | | self.assertIn('w: @acct,-api-' + identifier, (self.cfg / 'copyparty.conf').read_text()) |
| 92 | self.assertIn('g: *,-api-' + identifier, (self.cfg / 'copyparty.conf').read_text()) |
| 92 | 93 | self.call('account.delete', id=identifier) |
| 93 | 94 | self.assertNotIn(key, self.variable['Items']) |
| 94 | 95 | |
| ... | ... | @@ -123,12 +124,12 @@ class Shares(unittest.TestCase): |
| 123 | 124 | self.assertNotIn('rw: @snow-user-' + self.subject, config) |
| 124 | 125 | |
| 125 | 126 | def test_exact_base_mount_is_rendered_once(self): |
| 126 | | (self.root / 'Public').mkdir() |
| 127 | | self.call('grant.save', id=None, subject='user:' + self.subject, path=str(self.root / 'Public'), permissions='d') |
| 127 | self.call('grant.save', id=None, subject='user:' + self.subject, path=str(self.root), permissions='d') |
| 128 | 128 | config = (self.cfg / 'copyparty.conf').read_text() |
| 129 | | self.assertEqual(config.count('[/clover/Public]'), 1) |
| 130 | | self.assertIn('r.: *', config) |
| 131 | | self.assertIn('d: @snow-user-' + self.subject, config) |
| 129 | self.assertEqual(config.count('[/clover]'), 1) |
| 130 | clover = config.split('[/clover]')[1].split('[/media]')[0] |
| 131 | self.assertIn('A: snow', clover) |
| 132 | self.assertIn('d: @snow-user-' + self.subject, clover) |
| 132 | 133 | |
| 133 | 134 | def test_untrusted_boundary_and_symlink_escape_reject_before_nomad(self): |
| 134 | 135 | folder = self.root / 'work' |
| ... | ... | @@ -264,23 +265,31 @@ class Shares(unittest.TestCase): |
| 264 | 265 | self.assertEqual((self.root / 'Share').stat().st_mode & 0o777, 0o775) |
| 265 | 266 | self.assertEqual((self.root / 'Share/Clover - Restricted').stat().st_mode & 0o777, 0o775) |
| 266 | 267 | |
| 267 | | def test_api_scope_excludes_wildcards_but_explicit_child_grant_works(self): |
| 268 | | account = self.call('account.create', name='Scoped')['account'] |
| 269 | | (self.root / 'Public').mkdir() |
| 270 | | self.call('grant.save', id=None, subject=account['subject'], path=str(self.root), permissions='r') |
| 271 | | config = (self.cfg / 'copyparty.conf').read_text() |
| 272 | | public = config.split('[/clover/Public]')[1].split('[/logs]')[0] |
| 273 | | self.assertIn('r: *\n', public) |
| 274 | | self.assertIn('w: @acct,-' + account['username'], public) |
| 275 | | self.assertIn('r: ' + account['username'], public) |
| 276 | | logs = config.split('[/logs]')[1] |
| 277 | | self.assertIn('g: *,-' + account['username'], logs) |
| 278 | | manager = shares.Manager(self.users) |
| 279 | | manager.data = json.loads((self.cfg / 'manager.json').read_text()) |
| 280 | | manager.items = self.variable['Items'] |
| 281 | | manager.owner_permissions(account['username'], self.root / 'Public', 'r') |
| 282 | | with self.assertRaises(shares.Error): |
| 283 | | manager.owner_permissions(account['username'], self.root / 'Public', 'w') |
| 268 | def test_api_scope_excludes_wildcards_until_ancestor_grant(self): |
| 269 | source = Path(self.temporary.name) / 'base.conf' |
| 270 | source.write_text(Path(shares.__file__).with_name('copyparty.conf').read_text() + |
| 271 | '\n[/clover/scoped]\n /w/clover/scoped\n accs:\n r: *\n w: @acct\n') |
| 272 | (self.root / 'scoped').mkdir() |
| 273 | with patch.object(shares, 'configuration', partial(shares.configuration, source=source)): |
| 274 | account = self.call('account.create', name='Scoped')['account'] |
| 275 | config = (self.cfg / 'copyparty.conf').read_text() |
| 276 | scoped = config.split('[/clover/scoped]')[1] |
| 277 | self.assertIn('r: *,-' + account['username'], scoped) |
| 278 | self.assertIn('w: @acct,-' + account['username'], scoped) |
| 279 | self.call('grant.save', id=None, subject=account['subject'], path=str(self.root), permissions='r') |
| 280 | config = (self.cfg / 'copyparty.conf').read_text() |
| 281 | scoped = config.split('[/clover/scoped]')[1] |
| 282 | self.assertIn('r: *\n', scoped) |
| 283 | self.assertIn('w: @acct,-' + account['username'], scoped) |
| 284 | self.assertIn('r: ' + account['username'], scoped) |
| 285 | logs = config.split('[/logs]')[1].split('[/clover/scoped]')[0] |
| 286 | self.assertIn('g: *,-' + account['username'], logs) |
| 287 | manager = shares.Manager(self.users) |
| 288 | manager.data = json.loads((self.cfg / 'manager.json').read_text()) |
| 289 | manager.items = self.variable['Items'] |
| 290 | manager.owner_permissions(account['username'], self.root / 'scoped', 'r') |
| 291 | with self.assertRaises(shares.Error): |
| 292 | manager.owner_permissions(account['username'], self.root / 'scoped', 'w') |
| 284 | 293 | |
| 285 | 294 | def test_admin_can_retarget_other_owner_with_destination_permissions(self): |
| 286 | 295 | destination = self.root / 'other' |