diff --git a/SampleService.html b/SampleService.html
index 6eb1f563..3e82f9ee 100644
--- a/SampleService.html
+++ b/SampleService.html
@@ -1 +1 @@
-
SampleServicemoduleSampleService{typedefintboolean;
typedefinttimestamp;
typedefstringuser;
typedefstringnode_id;
typedefstringsamplenode_type;
typedefstringsample_id;
typedefstringlink_id;
typedefstringsample_name;
typedefintversion;
typedefstringmetadata_key;
typedefstringmetadata_value_key;
typedefstringws_upa;
typedefstringdata_id;
typedefstructure{}SampleNode; typedefstructure{}Sample; typedefstructure{}SampleACLs; typedefstructure{}SampleAddress; typedefstructure{intprior_version;
}CreateSampleParams; typedefstructure{}GetSampleParams; typedefstructure{}GetSampleACLsParams; typedefstructure{}ReplaceSampleACLsParams; typedefstructure{intprefix;
}GetMetadataKeyStaticMetadataParams; typedefstructure{}GetMetadataKeyStaticMetadataResults; typedefstructure{}CreateDataLinkParams; typedefstructure{}DataLink; typedefstructure{}CreateDataLinkResults; typedefstructure{}ExpireDataLinkParams; typedefstructure{}GetDataLinksFromSampleParams; typedefstructure{}GetDataLinksFromSampleResults; typedefstructure{}GetDataLinksFromDataParams; typedefstructure{}GetDataLinksFromDataResults; typedefstructure{}GetSampleViaDataParams; typedefstructure{}GetDataLinkParams; };
\ No newline at end of file
+SampleServicemoduleSampleService{typedefintboolean;
typedefinttimestamp;
typedefstringuser;
typedefstringnode_id;
typedefstringsamplenode_type;
typedefstringsample_id;
typedefstringlink_id;
typedefstringsample_name;
typedefintversion;
typedefstringmetadata_key;
typedefstringmetadata_value_key;
typedefstringws_upa;
typedefstringdata_id;
typedefstructure{}SampleNode; typedefstructure{}Sample; typedefstructure{}SampleACLs; typedefstructure{}SampleAddress; typedefstructure{intprior_version;
}CreateSampleParams; typedefstructure{}GetSampleParams; typedefstructure{}GetSampleACLsParams; typedefstructure{}ReplaceSampleACLsParams; typedefstructure{intprefix;
}GetMetadataKeyStaticMetadataParams; typedefstructure{}GetMetadataKeyStaticMetadataResults; typedefstructure{}CreateDataLinkParams; typedefstructure{}DataLink; typedefstructure{}CreateDataLinkResults; typedefstructure{}ExpireDataLinkParams; typedefstructure{}GetDataLinksFromSampleParams; typedefstructure{}GetDataLinksFromSampleResults; typedefstructure{}GetDataLinksFromDataParams; typedefstructure{}GetDataLinksFromDataResults; typedefstructure{}GetSampleViaDataParams; typedefstructure{}GetDataLinkParams; };
\ No newline at end of file
diff --git a/SampleService.spec b/SampleService.spec
index 8d10e11e..f5c49913 100644
--- a/SampleService.spec
+++ b/SampleService.spec
@@ -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.
diff --git a/TODO.md b/TODO.md
index 2bacad8a..d3a4c05f 100644
--- a/TODO.md
+++ b/TODO.md
@@ -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
diff --git a/lib/SampleService/SampleServiceImpl.py b/lib/SampleService/SampleServiceImpl.py
index 9ec38b32..77f3b4a9 100644
--- a/lib/SampleService/SampleServiceImpl.py
+++ b/lib/SampleService/SampleServiceImpl.py
@@ -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
@@ -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
diff --git a/lib/SampleService/SampleServiceServer.py b/lib/SampleService/SampleServiceServer.py
index 67418529..67f3bf4a 100644
--- a/lib/SampleService/SampleServiceServer.py
+++ b/lib/SampleService/SampleServiceServer.py
@@ -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])
diff --git a/test/SampleService_test.py b/test/SampleService_test.py
index d93e9b80..c3c3a16a 100644
--- a/test/SampleService_test.py
+++ b/test/SampleService_test.py
@@ -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):
@@ -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
@@ -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):