fix: include host in webfinger query
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Aravinth Manivannan 2023-09-28 00:06:16 +05:30
parent d75cbec117
commit 65d43335d1
Signed by: realaravinth
GPG key ID: F8F50389936984FF

46
run.py
View file

@ -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)