diff --git a/tests/checker/cgi-bin/input2cookies.py b/tests/checker/cgi-bin/input2cookies.py deleted file mode 100755 index 8abd97ee..00000000 --- a/tests/checker/cgi-bin/input2cookies.py +++ /dev/null @@ -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) diff --git a/tests/checker/httpserver.py b/tests/checker/httpserver.py index 6b58dd63..9c462218 100644 --- a/tests/checker/httpserver.py +++ b/tests/checker/httpserver.py @@ -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 diff --git a/tests/checker/test_loginurl.py b/tests/checker/test_loginurl.py index 2274fe7d..7456420a 100644 --- a/tests/checker/test_loginurl.py +++ b/tests/checker/test_loginurl.py @@ -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 = {}