Skip to content

Commit

Permalink
pylint: Replace deprecated cgi module
Browse files Browse the repository at this point in the history
https://docs.python.org/3/library/cgi.html#module-cgi:
> Deprecated since version 3.11, will be removed in version 3.13: The
cgi module is deprecated (see PEP 594 for details and alternatives).

Fixes: https://pagure.io/freeipa/issue/9278
Signed-off-by: Stanislav Levin <[email protected]>
Reviewed-By: Stanislav Levin <[email protected]>
  • Loading branch information
stanislavlevin authored and flo-renaud committed Jan 10, 2023
1 parent b848054 commit 691b5d2
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions install/migration/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""
from __future__ import absolute_import

import cgi # pylint: disable=deprecated-module
from urllib.parse import parse_qs
import errno
import logging
import os.path
Expand Down Expand Up @@ -80,9 +80,27 @@ def application(environ, start_response):
if not content_type.startswith('application/x-www-form-urlencoded'):
return bad_request(start_response)

form_data = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
if 'username' not in form_data or 'password' not in form_data:
try:
length = int(environ.get("CONTENT_LENGTH"))
except (ValueError, TypeError):
return bad_request(start_response)

query_string = environ["wsgi.input"].read(length).decode("utf-8")

try:
query_dict = parse_qs(query_string)
except Exception:
return bad_request(start_response)

user_query = query_dict.get("username", None)
if user_query is None or len(user_query) != 1:
return bad_request(start_response)
username = user_query[0]

password_query = query_dict.get("password", None)
if password_query is None or len(password_query) != 1:
return bad_request(start_response)
password = password_query[0]

status = '200 Success'
response_headers = []
Expand All @@ -93,8 +111,7 @@ def application(environ, start_response):
api = create_api(mode=None)
api.bootstrap(context='server', confdir=paths.ETC_IPA, in_server=True)
try:
bind(api.env.ldap_uri, api.env.basedn,
form_data['username'].value, form_data['password'].value)
bind(api.env.ldap_uri, api.env.basedn, username, password)
except IOError as err:
if err.errno == errno.EPERM:
result = 'invalid-password'
Expand Down

0 comments on commit 691b5d2

Please sign in to comment.