Skip to content

Commit

Permalink
Merge pull request #44 from mdsol/fix/body-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ykitamura-mdsol authored Jun 26, 2023
2 parents cc956ff + 06c5359 commit 6d9ad4e
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 273 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
matrix:
os: [Ubuntu, macOS, Windows]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
include:
- os: Ubuntu
image: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.6.0
- Fix bug with reading request body in `MAuthWSGIMiddleware`.
- Remove Support for EOL Python 3.7

# 1.5.1
- Fix `MAuthWSGIMiddleware` to no longer depend on `werkzeug` data in the request env.

Expand Down
7 changes: 4 additions & 3 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ The framework is licensed under the MIT licensing terms.
What versions of Python are supported?
--------------------------------------
Each release of requests-mauth is tested against:
* Python 3.5
* Python 3.6
* Python 3.7
* Python 3.8
* Python 3.9
* Python 3.10
* Python 3.11
* PyPy3

The values tested can be seen in the `tox.ini` file. We use tox to test the code across Python versions, see the README.md for details.
6 changes: 1 addition & 5 deletions mauth_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Load the version from the project metatdata
try:
import importlib.metadata as importlib_metadata
except ModuleNotFoundError:
# needed for Python < 3.8
import importlib_metadata
import importlib.metadata as importlib_metadata

__version__ = importlib_metadata.version(__name__)
28 changes: 24 additions & 4 deletions mauth_client/middlewares/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import json
import logging

Expand Down Expand Up @@ -57,10 +58,29 @@ def _validate_configs(self):
raise TypeError("MAuthWSGIMiddleware requires MAUTH_URL and MAUTH_API_VERSION")

def _read_body(self, environ):
input = environ["wsgi.input"]
input.seek(0)
body = input.read()
input.seek(0)
try:
size = int(environ.get("CONTENT_LENGTH", 0))
except ValueError:
size = 0

if not size:
return b""

body = environ["wsgi.input"].read(size)

# hack way of "rewinding" body so that downstream can reuse
#
# seek() will not work because production Flask and gunicorn give
# objects without a seek() function and blow up...
# yet humorously Flask in our tests gives a normal BytesIO object
# that does have seek()
#
# NOTE:
# this will not play well with large bodies where this may result in
# blowing out memory, but tbh MAuth is not adequately designed for and
# thus should not be used with large bodies.
environ["wsgi.input"] = io.BytesIO(body)

return body

def _extract_headers(self, environ):
Expand Down
515 changes: 261 additions & 254 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mauth-client"
version = "1.5.1"
version = "1.6.0"
description = "MAuth Client for Python"
repository = "https://github.com/mdsol/mauth-client-python"
authors = ["Medidata Solutions <support@mdsol.com>"]
Expand All @@ -13,7 +13,6 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand All @@ -23,11 +22,10 @@ classifiers = [
]

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.8"
requests = "^2.23"
cachetools = "^5.3"
rsa = "^4.0"
importlib-metadata = {version = ">=3.6", python = "<3.8"}
asgiref = "^3.5.2"
charset-normalizer = "^3.1.0"

Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = clean, flake8-py3, py37, py38, py39, py310, py311, stats
envlist = clean, flake8-py3, py38, py39, py310, py311, stats
skipsdist = True

[testenv]
Expand All @@ -15,7 +15,7 @@ skip_install = true
commands = coverage erase

[testenv:flake8-py3]
basepython = python3.10
basepython = python3.11
allowlist_externals = poetry
skip_install = true
commands =
Expand Down

0 comments on commit 6d9ad4e

Please sign in to comment.