Skip to content

Commit

Permalink
issue 2551353 - add roundup-classhelper
Browse files Browse the repository at this point in the history
Add test for rest/data/user/roles endpoint. Fix allow header returned
from endpoint to allow GET only.
  • Loading branch information
rouilj committed May 22, 2024
1 parent 5c005b1 commit 7ba1cb9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions roundup/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,11 @@ def get_roles(self, input):
raise Unauthorised(
'User does not have permission on "user.roles"')

self.client.setHeader(
"Allow",
"GET"
)

return 200, {"collection":
[{"id": rolename,"name": rolename}
for rolename in list(self.db.security.role.keys())]}
Expand Down
24 changes: 24 additions & 0 deletions test/test_liveserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,30 @@ def test_rest_endpoint_attribute_options(self):

self.assertEqual(f.status_code, 404)

def test_rest_endpoint_user_roles(self):
# use basic auth for rest endpoint
f = requests.get(self.url_base() + '/rest/data/user/roles',
auth=('admin', 'sekrit'),
headers = {'content-type': "",
'Origin': "http://localhost:9001",
})
print(f.status_code)
print(f.headers)

self.assertEqual(f.status_code, 200)
expected = { 'Access-Control-Expose-Headers': 'X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-RateLimit-Limit-Period, Retry-After, Sunset, Allow',
'Access-Control-Allow-Credentials': 'true',
'Allow': 'GET',
}
# use dict comprehension to remove fields like date,
# content-length etc. from f.headers.
self.assertDictEqual({ key: value for (key, value) in f.headers.items() if key in expected }, expected)

content = json.loads(f.content)

self.assertEqual(3, len(json.loads(f.content)['data']['collection']))


def test_ims(self):
''' retreive the user_utils.js file with old and new
if-modified-since timestamps.
Expand Down

0 comments on commit 7ba1cb9

Please sign in to comment.