Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SampleService.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SampleService.spec
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module SampleService {

/* Get a sample's ACLs. */
funcdef get_sample_acls(GetSampleACLsParams params) returns (SampleACLs acls)
authentication required;
authentication optional;

/* replace_sample_acls parameters.

Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* cache known good users
* cache user roles
* support anonymous users
* get sample acls
* get links from sample
* get links from data
* get sample via data
Expand Down
7 changes: 4 additions & 3 deletions lib/SampleService/SampleServiceImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SampleService:
######################################### noqa
VERSION = "0.1.0-alpha18"
GIT_URL = "https://github.com/mrcreosote/sample_service.git"
GIT_COMMIT_HASH = "a1e16589e20404b119283c8bc42a0dcc97982dfc"
GIT_COMMIT_HASH = "5cb8e3652fdb244ee25998a3d96fa048fc6d7d81"

#BEGIN_CLASS_HEADER
#END_CLASS_HEADER
Expand Down Expand Up @@ -266,10 +266,11 @@ def get_sample_acls(self, ctx, params):
#BEGIN get_sample_acls
id_ = _get_id_from_object(params, 'id', required=True)
admin = _check_admin(
self._user_lookup, ctx[_CTX_TOKEN], _AdminPermission.READ,
self._user_lookup, ctx.get(_CTX_TOKEN), _AdminPermission.READ,
# pretty annoying to test ctx.log_info is working, do it manually
'get_sample_acls', ctx.log_info, skip_check=not params.get('as_admin'))
acls_ret = self._samples.get_sample_acls(id_, _UserID(ctx[_CTX_USER]), as_admin=admin)
acls_ret = self._samples.get_sample_acls(
id_, _get_user_from_object(ctx, _CTX_USER), as_admin=admin)
acls = _acls_to_dict(acls_ret)
#END get_sample_acls

Expand Down
2 changes: 1 addition & 1 deletion lib/SampleService/SampleServiceServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def __init__(self):
self.rpc_service.add(impl_SampleService.get_sample_acls,
name='SampleService.get_sample_acls',
types=[dict])
self.method_authentication['SampleService.get_sample_acls'] = 'required' # noqa
self.method_authentication['SampleService.get_sample_acls'] = 'optional' # noqa
self.rpc_service.add(impl_SampleService.replace_sample_acls,
name='SampleService.replace_sample_acls',
types=[dict])
Expand Down
42 changes: 29 additions & 13 deletions test/SampleService_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,13 +1256,14 @@ def test_get_acls_public_read(sample_port):

_replace_acls(url, id_, TOKEN1, {'public_read': 1})

_assert_acl_contents(url, id_, TOKEN4, {
'owner': USER1,
'admin': [],
'write': [],
'read': [],
'public_read': 1
})
for token in [TOKEN4, None]: # user with no explicit perms and anon user
_assert_acl_contents(url, id_, token, {
'owner': USER1,
'admin': [],
'write': [],
'read': [],
'public_read': 1
})


def test_get_acls_as_admin(sample_port):
Expand Down Expand Up @@ -1340,14 +1341,15 @@ def _replace_acls(url, id_, token, acls, as_admin=0, print_resp=False):
assert ret.json() == {'version': '1.1', 'id': '67', 'result': None}


def _assert_acl_contents(url, id_, token, expected, as_admin=0):
def _assert_acl_contents(url, id_, token, expected, as_admin=0, print_resp=False):
ret = requests.post(url, headers=get_authorized_headers(token), json={
'method': 'SampleService.get_sample_acls',
'version': '1.1',
'id': '47',
'params': [{'id': id_, 'as_admin': as_admin}]
})
# print(ret.text)
if print_resp:
print(ret.text)
assert ret.ok is True
assert ret.json()['result'][0] == expected

Expand Down Expand Up @@ -1391,15 +1393,29 @@ def test_get_acls_fail_permissions(sample_port):

id_ = _create_generic_sample(url, TOKEN1)

ret = requests.post(url, headers=get_authorized_headers(TOKEN2), json={
_get_acls_fail_permissions(
url, TOKEN2, {'id': id_},
f'Sample service error code 20000 Unauthorized: User user2 cannot read sample {id_}')

_get_acls_fail_permissions(
url, None, {'id': id_},
f'Sample service error code 20000 Unauthorized: Anonymous users cannot read sample {id_}')

_get_acls_fail_permissions(
url, None, {'id': id_, 'as_admin': 1},
'Sample service error code 20000 Unauthorized: Anonymous users ' +
'may not act as service administrators.')


def _get_acls_fail_permissions(url, token, params, expected):
ret = requests.post(url, headers=get_authorized_headers(token), json={
'method': 'SampleService.get_sample_acls',
'version': '1.1',
'id': '42',
'params': [{'id': id_}]
'params': [params]
})
assert ret.status_code == 500
assert ret.json()['error']['message'] == (
f'Sample service error code 20000 Unauthorized: User user2 cannot read sample {id_}')
assert ret.json()['error']['message'] == expected


def test_get_acls_fail_admin_permissions(sample_port):
Expand Down