Skip to content

Commit

Permalink
Disable multipart encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw committed Oct 10, 2023
1 parent 1df7540 commit 37e4121
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
0.6.9 (unreleased)
------------------

- Nothing changed yet.
- Disable multpart encoding in `SyncApiProvider`.


0.6.8 (2023-10-10)
Expand All @@ -16,7 +16,7 @@
0.6.7 (2023-10-09)
------------------

- Adapt call signature of the `fetch_token` callable in `ApiProvicer`.
- Adapt call signature of the `fetch_token` callable in `ApiProvider`.

- Add `clean_python.oauth.client_credentials`.

Expand Down
4 changes: 3 additions & 1 deletion clean_python/api_client/sync_api_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def _request(
elif fields is not None:
request_kwargs["fields"] = fields
headers.update(self._fetch_token())
return self._pool.request(headers=headers, **request_kwargs)
return self._pool.request(
headers=headers, encode_multipart=False, **request_kwargs
)

def request(
self,
Expand Down
20 changes: 16 additions & 4 deletions integration_tests/fastapi_example/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from fastapi import Depends
from fastapi import Form
from fastapi import Request
from fastapi import Response
from fastapi import UploadFile
from fastapi.responses import JSONResponse
Expand Down Expand Up @@ -86,19 +87,30 @@ async def urlencode(self, name: str):
@post("/token")
def token(
self,
request: Request,
grant_type: str = Form(),
scope: str = Form(),
credentials: HTTPBasicCredentials = Depends(basic),
):
"""For testing client credentials grant"""
if request.headers["Content-Type"] != "application/x-www-form-urlencoded":
return Response(status_code=HTTPStatus.METHOD_NOT_ALLOWED)
if grant_type != "client_credentials":
return JSONResponse({"error": "invalid_grant"})
return JSONResponse(
{"error": "invalid_grant"}, status_code=HTTPStatus.BAD_REQUEST
)
if credentials.username != "testclient":
return JSONResponse({"error": "invalid_client"})
return JSONResponse(
{"error": "invalid_client"}, status_code=HTTPStatus.BAD_REQUEST
)
if credentials.password != "supersecret":
return JSONResponse({"error": "invalid_client"})
return JSONResponse(
{"error": "invalid_client"}, status_code=HTTPStatus.BAD_REQUEST
)
if scope != "all":
return JSONResponse({"error": "invalid_grant"})
return JSONResponse(
{"error": "invalid_grant"}, status_code=HTTPStatus.BAD_REQUEST
)
claims = {"user": "foo", "exp": int(time.time()) + 3600}
payload = base64.b64encode(json.dumps(claims).encode()).decode()
return {
Expand Down
2 changes: 2 additions & 0 deletions tests/api_client/test_sync_api_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_get(api_provider: SyncApiProvider, response):
url="http://testserver/foo",
headers={"Authorization": "Bearer tenant-2"},
timeout=5.0,
encode_multipart=False,
)
assert actual == {"foo": 2}

Expand All @@ -69,6 +70,7 @@ def test_post_json(api_provider: SyncApiProvider, response):
"Authorization": "Bearer tenant-2",
},
timeout=5.0,
encode_multipart=False,
)
assert actual == {"foo": 2}

Expand Down

0 comments on commit 37e4121

Please sign in to comment.