From 65d43335d184e16c7002b7c3be82e3991fe3afcd Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Thu, 28 Sep 2023 00:06:16 +0530 Subject: [PATCH] fix: include host in webfinger query --- run.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/run.py b/run.py index 9c8ff4c..02343c2 100755 --- a/run.py +++ b/run.py @@ -9,11 +9,12 @@ import os import requests from urllib.parse import urlparse, urlunparse +LOG_FILE = "webfinger.log" def configure_logger(): logger = logging.getLogger("webfinger") logger.setLevel(logging.DEBUG) - fh = logging.FileHandler("webfinger.log") + fh = logging.FileHandler(LOG_FILE) fh.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) @@ -40,6 +41,7 @@ def get_env(name) -> str: logger = configure_logger() FTEST_AUTH = get_env("FTEST_AUTH") +FTEST_HOST = get_env("FTEST_HOST") TARGET_HOST = get_env("FTEST_TARGET_HOST") TEST_USER = get_env("FTEST_USER") # actor ex: john@example.org TEST_HOST = urlparse(TARGET_HOST).netloc @@ -53,7 +55,7 @@ def query_webfinger(): parsed_target_host.netloc, "/.well-known/webfinger", "", - f"resource=acct:{TEST_USER}", + f"resource=acct:{TEST_USER}@{TARGET_HOST}", "", ) ) @@ -128,6 +130,36 @@ def test_access_control_allow_origin(resp): ), "Access-Control-Allow-Origin header should be '*' to allow any domain to access the resource with CORS. Please see https://www.rfc-editor.org/rfc/rfc7033.html#section-5" logger.info("[SUCESS] WebFinger endpoint is configured correctly for CORS") +def upload_logs_to_ftest(success: bool, logs: str): + parsed_ftest_host = urlparse(FTEST_HOST) + ftest = urlunparse( + ( + parsed_ftest_host.scheme, + parsed_ftest_host.netloc, + "/suites//tests/results", + "", + "" + "", + ) + ) + + + raw_logs = "" + + with open(LOG_FILE) as log_file: + for line in log_file: + raw_logs += line + payload = { + "success": success, + "logs": logs, + "raw_logs": raw_logs, + } + + + res = requests.post(webfinger, headers={"Origin": "http://example.org"}) + + + if __name__ == "__main__": max_score = 5 @@ -178,12 +210,18 @@ if __name__ == "__main__": print("Summary:\n") + logs = [] + if success: print(f"Successful tests:\n") for s in success: - print(f"[OK] {s}") + log = f"[OK] {s}" + print(log) + logs.append(log) if failures: print(f"\n\nFailed tests:\n") for _, (test, error) in enumerate(failures.items()): - print(f"[FAIL] {test} failed with error:\n{error}\n-----\n") + log = f"[FAIL] {test} failed with error:\n{error}\n-----\n" + print(log) + logs.append(log)