diff --git a/keystoneauth_websso/plugin.py b/keystoneauth_websso/plugin.py index 5e56ff1..9a89419 100644 --- a/keystoneauth_websso/plugin.py +++ b/keystoneauth_websso/plugin.py @@ -15,7 +15,6 @@ # License for the specific language governing permissions and limitations # under the License. -import cgi import json import os import re @@ -24,6 +23,7 @@ from datetime import datetime from http.server import BaseHTTPRequestHandler, HTTPServer +import multipart from keystoneauth1 import _utils as utils from keystoneauth1.identity.v3 import federation @@ -75,14 +75,13 @@ def do_POST(self): if self.headers: - form = cgi.FieldStorage( - fp=self.rfile, - headers=self.headers, - environ={ - "REQUEST_METHOD": "POST", - "CONTENT_TYPE": self.headers["Content-Type"], - }, - ) + environ = { + "REQUEST_METHOD": "POST", + "CONTENT_LENGTH": self.headers["Content-Length"], + "CONTENT_TYPE": self.headers["Content-Type"], + "wsgi.input": self.rfile, + } + forms, files = multipart.parse_form_data(environ) self.send_response(200) self.send_header("Content-type", "text/html") @@ -95,11 +94,8 @@ def do_POST(self): b"" ) - for field in form.keys(): - field_item = form[field] - if not field_item.filename: - # Regular Form Value - postvars[field] = form[field].value + for field, value in forms.items(): + postvars[field] = value self.server.token = postvars["token"] else: diff --git a/poetry.lock b/poetry.lock index 466e4c6..72076df 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "certifi" @@ -157,6 +157,20 @@ oauth1 = ["oauthlib (>=0.6.2)"] saml2 = ["lxml (>=4.2.0)"] test = ["PyYAML (>=3.12)", "bandit (>=1.7.6,<1.8.0)", "betamax (>=0.7.0)", "coverage (>=4.0,!=4.4)", "fixtures (>=3.0.0)", "flake8-docstrings (>=1.7.0,<1.8.0)", "flake8-import-order (>=0.18.2,<0.19.0)", "hacking (>=6.1.0,<6.2.0)", "lxml (>=4.2.0)", "oauthlib (>=0.6.2)", "oslo.config (>=5.2.0)", "oslo.utils (>=3.33.0)", "oslotest (>=3.2.0)", "reno (>=3.1.0)", "requests-kerberos (>=0.8.0)", "requests-mock (>=1.2.0)", "stestr (>=1.0.0)", "testresources (>=2.0.0)", "testtools (>=2.2.0)"] +[[package]] +name = "multipart" +version = "1.1.0" +description = "Parser for multipart/form-data" +optional = false +python-versions = ">=3.5" +files = [ + {file = "multipart-1.1.0-py3-none-any.whl", hash = "sha256:5a784677de8b49e6409e730dfe018f73c5d7aef360e44750e00f67d669b51e91"}, + {file = "multipart-1.1.0.tar.gz", hash = "sha256:ee32683f5c454740cd9139e1d6057053823da0729c426f156464f81111529ba1"}, +] + +[package.extras] +dev = ["build", "pytest", "pytest-cov", "twine"] + [[package]] name = "os-service-types" version = "1.7.0" @@ -237,4 +251,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "34d783c776ac0004b36fd200cea954183d7269e6eb6bf022a0187af5df994a00" +content-hash = "1e6953215db1cf8cfcdc092f4adb6264454e2352226c66891ffaa68e16821563" diff --git a/pyproject.toml b/pyproject.toml index 597e115..b4728a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,10 +19,11 @@ classifiers = [ [tool.poetry.dependencies] python = "^3.8" keystoneauth1 = ">=5.0.0" +multipart = ">=1.0.0" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" [tool.poetry.plugins."keystoneauth1.plugin"] -v3websso = "keystoneauth_websso.loading:OpenIDConnect" \ No newline at end of file +v3websso = "keystoneauth_websso.loading:OpenIDConnect"