Merge pull request #764 from cjmayo/replace_cgihandler

Replace deprecated http.server.CGIHTTPRequestHandler for TestLoginUrl
This commit is contained in:
Chris Mayo 2023-10-30 19:23:10 +00:00 committed by GitHub
commit 8ae3783c3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 31 deletions

View file

@ -1,11 +0,0 @@
#!/usr/bin/python3
from http import cookies
import sys
import urllib.parse
C = cookies.SimpleCookie()
for field, value in urllib.parse.parse_qsl(sys.stdin.read()):
C[field] = value
print(C)

View file

@ -18,9 +18,8 @@ Define http test support classes for LinkChecker tests.
"""
import html
from http.server import CGIHTTPRequestHandler, SimpleHTTPRequestHandler, HTTPServer
from http.server import SimpleHTTPRequestHandler, HTTPServer
from http.client import HTTPConnection, HTTPSConnection
import os.path
import ssl
import time
import threading
@ -304,18 +303,3 @@ class CookieRedirectHttpRequestHandler(NoQueryHttpRequestHandler):
self.redirect()
else:
super().do_HEAD()
class CGIHandler(CGIHTTPRequestHandler, StoppableHttpRequestHandler):
cgi_path = "/tests/checker/cgi-bin/"
def is_cgi(self):
# CGIHTTPRequestHandler.is_cgi() can only handle a single-level path
# override so that we can store scripts under /tests/checker
if CGIHandler.cgi_path in self.path:
self.cgi_info = (
CGIHandler.cgi_path,
os.path.relpath(self.path, CGIHandler.cgi_path),
)
return True
return False

View file

@ -1,4 +1,4 @@
# Copyright (C) 2020 Chris Mayo
# Copyright (C) 2020-2023 Chris Mayo
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -18,17 +18,28 @@ Test director.aggregator.Aggregate.visit_loginurl().
This includes the retrieval and search of a login form and posting credentials.
"""
import re
import urllib.parse
from .httpserver import HttpServerTest, CGIHandler
from .httpserver import HttpServerTest, StoppableHttpRequestHandler
from . import get_test_aggregate
class LoginPostHandler(StoppableHttpRequestHandler):
def do_POST(self):
length = int(self.headers.get("content-length"))
form_data = self.rfile.read(length).decode()
self.send_response(200)
for name, value in urllib.parse.parse_qsl(form_data):
self.send_header("Set-Cookie", f"{name}={value}")
self.end_headers()
class TestLoginUrl(HttpServerTest):
"""Test loginurl retrieval, search and posting credentials."""
def __init__(self, methodName="runTest"):
super().__init__(methodName=methodName)
self.handler = CGIHandler
self.handler = LoginPostHandler
def visit_loginurl(self, page, user=None, password=None, extrafields=False):
confargs = {}