Skip to content

Commit

Permalink
Add admin check to allow events. (#112)
Browse files Browse the repository at this point in the history
If the user is an admin user the event should be allowed.

Signed-off-by: David Brown <dmlb2000@gmail.com>
  • Loading branch information
dmlb2000 committed Nov 8, 2019
1 parent b32a185 commit 03ea068
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pacifica/policy/events/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def POST(self, username):
userinfo = self._user_info_from_kwds(
network_id=username, recursion_depth=0, recursion_limit=1)
if event_obj.get('eventType', False) != 'org.pacifica.metadata.ingest':
if self._is_admin(userinfo[0]['_id']):
return {'status': 'success'}
raise cherrypy.HTTPError(
412,
text_type('Precondition Failed: Invalid eventType for {0}').format(
Expand Down
12 changes: 11 additions & 1 deletion tests/events_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ def test_events_query(self):
self.assertTrue('status' in ret_data)
self.assertEqual(ret_data['status'], 'success')

def test_admins_events_query(self):
"""Admin get valid events of any type."""
valid_query = loads(open(
join(dirname(realpath(__file__)), 'test_files', 'events_orm.json')
).read())
ret_data = self.get_json_page('/events/dmlb2001', valid_query)
self.assertFalse(ret_data is None)
self.assertTrue('status' in ret_data)
self.assertEqual(ret_data['status'], 'success')

def test_bad_events_query(self):
"""Test posting the queries."""
invalid_query = {'some': {'random': 'data'}, 'in': ['a', 'hash']}
self.getPage('/events/dmlb2001',
self.getPage('/events/dmlb2000',
self.headers +
[('Content-Length', str(len(dumps(invalid_query))))],
'POST',
Expand Down
20 changes: 20 additions & 0 deletions tests/test_files/events_orm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"cloudEventsVersion": "0.1",
"contentType": "application/json",
"data": {
"method": "update",
"obj_primary_keys": [
{
"_id": 1234
}
],
"obj_type": "users"
},
"eventID": "1852d1bf-e308-4cf8-bc94-3ad045a3b8b5",
"eventTime": "2018-04-05T17:31:00Z",
"eventType": "org.pacifica.metadata.orm",
"extensions": {
"comExampleExtension": "value"
},
"source": "/mycontext"
}

0 comments on commit 03ea068

Please sign in to comment.