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