Compare commits

...

4 Commits

Author SHA1 Message Date
Aravinth Manivannan ec7f3f54b7
doc: check all TODO items
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-10-01 14:16:13 +05:30
Aravinth Manivannan 2c1f1705ea
doc: success and failrue example logs 2023-10-01 14:15:28 +05:30
Aravinth Manivannan 52b7397591
feat: upload to ftest server 2023-10-01 14:15:06 +05:30
Aravinth Manivannan b483a9b971
feat: add schema validation 2023-10-01 14:14:32 +05:30
2 changed files with 101 additions and 20 deletions

View File

@ -6,9 +6,9 @@
## TODO
- [ ] Write code to upload to ftest server
- [ ] Package Docker container
- [ ] Upload to Docker Hub
- [x] Write code to upload to ftest server
- [x] Package Docker container
- [x] Upload to Docker Hub
## Environment Variables
@ -43,28 +43,83 @@ docker run \
### Successful run:
TODO
<details>
<summary>Please open to see logs</summary>
```bash
2023-10-01 14:11:52,711 - nodeinfo - INFO - Environment: FTEST_AUTH: aACGJUaWKbUAynhz54762jYC0lcTtIei
2023-10-01 14:11:52,711 - nodeinfo - INFO - Environment: FTEST_HOST: http://localhost:9000
2023-10-01 14:11:52,711 - nodeinfo - INFO - Environment: FTEST_TARGET_HOST: http://forgejo:7000
2023-10-01 14:11:52,711 - nodeinfo - INFO - Query nodeinfo: http://forgejo:7000/.well-known/nodeinfo
2023-10-01 14:11:52,715 - nodeinfo - DEBUG - nodeinfo response:
STATUS: 200
HEADERS:
{'Cache-Control': 'max-age=0, private, must-revalidate, no-transform', 'Content-Type': 'application/json;charset=utf-8', 'Set-Cookie': 'i_like_gitea=3dfde1a36bac742e; Path=/; HttpOnly; SameSite=Lax, _csrf=mItNQEJtk8C_SAffDQzjbRFl0_s6MTY5NjE0OTcxMjcxNDI5OTg3NQ; Path=/; Max-Age=86400; HttpOnly; SameSite=Lax', 'X-Frame-Options': 'SAMEORIGIN', 'Date': 'Sun, 01 Oct 2023 08:41:52 GMT', 'Content-Length': '115'}
RESPONSE PAYLOAD:
{'links': [{'href': 'http://forgejo:7000/api/v1/nodeinfo', 'rel': 'http://nodeinfo.diaspora.software/ns/schema/2.1'}]}
2023-10-01 14:11:52,715 - nodeinfo - INFO - [SUCCESS] nodeinfo query response is HTTP 200
2023-10-01 14:11:52,715 - nodeinfo - INFO - [SUCESS] links passed schema validation
2023-10-01 14:11:53,387 - nodeinfo - INFO - [SUCESS] passed Nodeinfo 2.1 schema validation
===============
2023-10-01 14:11:53,387 - nodeinfo - INFO - All tests passed
2023-10-01 14:11:53,396 - nodeinfo - INFO - Summary:
2023-10-01 14:11:53,396 - nodeinfo - INFO - Successful tests:
2023-10-01 14:11:53,396 - nodeinfo - INFO - [OK] test_links
2023-10-01 14:11:53,396 - nodeinfo - INFO - [OK] test_schema_Nodeinfo_2.1
```
</details>
### Failed run:
TODO
<details>
<summary>Please open to see logs</summary>
```bash
14:13 (venv) atm@lab nodeinfo ±|master ✗|→ python run.py
2023-10-01 14:13:54,964 - nodeinfo - INFO - Environment: FTEST_AUTH: aACGJUaWKbUAynhz54762jYC0lcTtIei
2023-10-01 14:13:54,964 - nodeinfo - INFO - Environment: FTEST_HOST: http://localhost:9000
2023-10-01 14:13:54,973 - nodeinfo - INFO - Environment: FTEST_TARGET_HOST: http://forgejo:7000
2023-10-01 14:13:54,973 - nodeinfo - INFO - Query nodeinfo: http://forgejo:7000/.well-known/nodeinfo
2023-10-01 14:13:54,977 - nodeinfo - DEBUG - nodeinfo response:
STATUS: 200
HEADERS:
{'Cache-Control': 'max-age=0, private, must-revalidate, no-transform', 'Content-Type': 'application/json;charset=utf-8', 'Set-Cookie': 'i_like_gitea=4cb5cb90cf023e54; Path=/; HttpOnly; SameSite=Lax, _csrf=CXHunQ6_4ADS51avMV3FZQPSAdY6MTY5NjE0OTgzNDk3NjU2ODY0Nw; Path=/; Max-Age=86400; HttpOnly; SameSite=Lax', 'X-Frame-Options': 'SAMEORIGIN', 'Date': 'Sun, 01 Oct 2023 08:43:54 GMT', 'Content-Length': '115'}
RESPONSE PAYLOAD:
{'links': [{'href': 'http://forgejo:7000/api/v1/nodeinfo', 'rel': 'http://nodeinfo.diaspora.software/ns/schema/2.1'}]}
2023-10-01 14:13:54,977 - nodeinfo - INFO - [SUCCESS] nodeinfo query response is HTTP 200
2023-10-01 14:13:54,977 - nodeinfo - INFO - [SUCESS] links passed schema validation
2023-10-01 14:13:54,977 - nodeinfo - ERROR - '1.0'
===============
2023-10-01 14:13:54,977 - nodeinfo - INFO - Partial success. 1 out of 2 tests passed
2023-10-01 14:13:54,977 - nodeinfo - INFO - Summary:
2023-10-01 14:13:54,977 - nodeinfo - INFO - Successful tests:
2023-10-01 14:13:54,977 - nodeinfo - INFO - [OK] test_links
2023-10-01 14:13:54,977 - nodeinfo - ERROR -
Failed tests:
2023-10-01 14:13:54,977 - nodeinfo - ERROR - [FAIL] test_schema_Nodeinfo_2.1 failed with error:
'1.0'
-----
```
</details>

52
run.py
View File

@ -8,6 +8,14 @@ import logging
LOG_FILE = "nodeinfo.log"
NODEINFO_VERSIONS = {
1.0: "http://nodeinfo.diaspora.software/ns/schema/1.0",
1.1: "http://nodeinfo.diaspora.software/ns/schema/1.1",
2.0: "http://nodeinfo.diaspora.software/ns/schema/2.0",
2.1: "http://nodeinfo.diaspora.software/ns/schema/2.1",
}
def configure_logger():
logger = logging.getLogger("nodeinfo")
logger.setLevel(logging.DEBUG)
@ -66,9 +74,6 @@ def query_nodeinfo():
def test_links(resp):
self_link = None
profile_link = None
for link in resp["links"]:
assert "href" in link, "'href' present in link item"
assert "rel" in link, "'rel' present in link item"
@ -76,6 +81,14 @@ def test_links(resp):
logger.info("[SUCESS] links passed schema validation")
def test_schema(source, version):
schema = requests.get(NODEINFO_VERSIONS[version]).json()
resp = requests.get(source).json()
jsonschema.validate(resp, schema)
logger.info(f"[SUCESS] passed Nodeinfo {version} schema validation")
def upload_logs_to_ftest(success: bool, logs: str):
parsed_ftest_host = urlparse(FTEST_HOST)
ftest = urlunparse(
@ -100,11 +113,10 @@ def upload_logs_to_ftest(success: bool, logs: str):
if __name__ == "__main__":
max_score = 5
max_score = "NaN"
score = 0
resp = query_nodeinfo()
json = resp.json()
score += 1
success = []
failures = {}
@ -117,28 +129,42 @@ if __name__ == "__main__":
logger.error(e)
failures["test_links"] = e
max_score = 1 + len(json["links"])
for link in json["links"]:
for version in NODEINFO_VERSIONS:
if NODEINFO_VERSIONS[version] == link["rel"]:
test_name = f"test_schema_Nodeinfo_{version}"
try:
test_schema(link["href"], version)
score += 1
success.append(test_name)
except Exception as e:
logger.error(e)
failures[test_name] = e
print("\n\n===============")
if score == max_score:
print("All tests passed")
logger.info("All tests passed")
elif score > 0:
print(f"Partial success. {score} out of {max_score} tests passed")
logger.info(f"Partial success. {score} out of {max_score} tests passed")
print("Summary:\n")
logger.info("Summary:\n")
logs = ""
if success:
print(f"Successful tests:\n")
logger.info(f"Successful tests:\n")
for s in success:
log = f"[OK] {s}\n"
print(log)
logger.info(log)
logs += log
if failures:
print(f"\n\nFailed tests:\n")
logger.error(f"\n\nFailed tests:\n")
for _, (test, error) in enumerate(failures.items()):
log = f"[FAIL] {test} failed with error:\n{error}\n-----\n"
print(log)
logger.error(log)
logs += log
# upload_logs_to_ftest(len(failures) == 0, logs)
upload_logs_to_ftest(len(failures) == 0, logs)