move content-type check to base APIHandler

so it can be applied to all cookie-authenticated POST requests

also parse the content-type header to handle e.g. `Content-Type: application/json; charset`
This commit is contained in:
Min RK
2021-09-01 09:51:23 +02:00
parent e59556f020
commit 44988b626e
3 changed files with 56 additions and 19 deletions

View File

@@ -61,7 +61,7 @@ async def test_auth_api(app):
assert r.status_code == 403
async def test_referer_check(app):
async def test_cors_checks(app):
url = ujoin(public_host(app), app.hub.base_url)
host = urlparse(url).netloc
# add admin user
@@ -106,6 +106,32 @@ async def test_referer_check(app):
)
assert r.status_code == 200
r = await api_request(
app,
'users',
method='post',
data='{}',
headers={
"Authorization": "",
"Content-Type": "text/plain",
},
cookies=cookies,
)
assert r.status_code == 403
r = await api_request(
app,
'users',
method='post',
data='{}',
headers={
"Authorization": "",
"Content-Type": "application/json; charset=UTF-8",
},
cookies=cookies,
)
assert r.status_code == 400 # accepted, but invalid
# --------------
# User API tests
@@ -409,10 +435,6 @@ async def test_add_multi_user_bad(app):
assert r.status_code == 400
r = await api_request(app, 'users', method='post', data='[]')
assert r.status_code == 400
r = await api_request(
app, 'users', method='post', data='{}', headers={"Content-Type": "text/plain"}
)
assert r.status_code == 403
@mark.user