fix: include host in webfinger query
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
d75cbec117
commit
65d43335d1
1 changed files with 42 additions and 4 deletions
46
run.py
46
run.py
|
@ -9,11 +9,12 @@ import os
|
||||||
import requests
|
import requests
|
||||||
from urllib.parse import urlparse, urlunparse
|
from urllib.parse import urlparse, urlunparse
|
||||||
|
|
||||||
|
LOG_FILE = "webfinger.log"
|
||||||
|
|
||||||
def configure_logger():
|
def configure_logger():
|
||||||
logger = logging.getLogger("webfinger")
|
logger = logging.getLogger("webfinger")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
fh = logging.FileHandler("webfinger.log")
|
fh = logging.FileHandler(LOG_FILE)
|
||||||
fh.setLevel(logging.DEBUG)
|
fh.setLevel(logging.DEBUG)
|
||||||
ch = logging.StreamHandler()
|
ch = logging.StreamHandler()
|
||||||
ch.setLevel(logging.DEBUG)
|
ch.setLevel(logging.DEBUG)
|
||||||
|
@ -40,6 +41,7 @@ def get_env(name) -> str:
|
||||||
logger = configure_logger()
|
logger = configure_logger()
|
||||||
|
|
||||||
FTEST_AUTH = get_env("FTEST_AUTH")
|
FTEST_AUTH = get_env("FTEST_AUTH")
|
||||||
|
FTEST_HOST = get_env("FTEST_HOST")
|
||||||
TARGET_HOST = get_env("FTEST_TARGET_HOST")
|
TARGET_HOST = get_env("FTEST_TARGET_HOST")
|
||||||
TEST_USER = get_env("FTEST_USER") # actor ex: john@example.org
|
TEST_USER = get_env("FTEST_USER") # actor ex: john@example.org
|
||||||
TEST_HOST = urlparse(TARGET_HOST).netloc
|
TEST_HOST = urlparse(TARGET_HOST).netloc
|
||||||
|
@ -53,7 +55,7 @@ def query_webfinger():
|
||||||
parsed_target_host.netloc,
|
parsed_target_host.netloc,
|
||||||
"/.well-known/webfinger",
|
"/.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"
|
), "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")
|
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__":
|
if __name__ == "__main__":
|
||||||
max_score = 5
|
max_score = 5
|
||||||
|
@ -178,12 +210,18 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
print("Summary:\n")
|
print("Summary:\n")
|
||||||
|
|
||||||
|
logs = []
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
print(f"Successful tests:\n")
|
print(f"Successful tests:\n")
|
||||||
for s in success:
|
for s in success:
|
||||||
print(f"[OK] {s}")
|
log = f"[OK] {s}"
|
||||||
|
print(log)
|
||||||
|
logs.append(log)
|
||||||
|
|
||||||
if failures:
|
if failures:
|
||||||
print(f"\n\nFailed tests:\n")
|
print(f"\n\nFailed tests:\n")
|
||||||
for _, (test, error) in enumerate(failures.items()):
|
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)
|
||||||
|
|
Loading…
Reference in a new issue