Skip to content

Commit 7ba1cb9

Browse files
committed
issue 2551353 - add roundup-classhelper
Add test for rest/data/user/roles endpoint. Fix allow header returned from endpoint to allow GET only.
1 parent 5c005b1 commit 7ba1cb9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

roundup/rest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,11 @@ def get_roles(self, input):
10401040
raise Unauthorised(
10411041
'User does not have permission on "user.roles"')
10421042

1043+
self.client.setHeader(
1044+
"Allow",
1045+
"GET"
1046+
)
1047+
10431048
return 200, {"collection":
10441049
[{"id": rolename,"name": rolename}
10451050
for rolename in list(self.db.security.role.keys())]}

test/test_liveserver.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,30 @@ def test_rest_endpoint_attribute_options(self):
684684

685685
self.assertEqual(f.status_code, 404)
686686

687+
def test_rest_endpoint_user_roles(self):
688+
# use basic auth for rest endpoint
689+
f = requests.get(self.url_base() + '/rest/data/user/roles',
690+
auth=('admin', 'sekrit'),
691+
headers = {'content-type': "",
692+
'Origin': "http://localhost:9001",
693+
})
694+
print(f.status_code)
695+
print(f.headers)
696+
697+
self.assertEqual(f.status_code, 200)
698+
expected = { 'Access-Control-Expose-Headers': 'X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-RateLimit-Limit-Period, Retry-After, Sunset, Allow',
699+
'Access-Control-Allow-Credentials': 'true',
700+
'Allow': 'GET',
701+
}
702+
# use dict comprehension to remove fields like date,
703+
# content-length etc. from f.headers.
704+
self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)
705+
706+
content = json.loads(f.content)
707+
708+
self.assertEqual(3, len(json.loads(f.content)['data']['collection']))
709+
710+
687711
def test_ims(self):
688712
''' retreive the user_utils.js file with old and new
689713
if-modified-since timestamps.

0 commit comments

Comments
 (0)