[feat] process inbox request
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
SouthFox 2023-06-13 14:11:29 +08:00
parent 5dc49fbdf9
commit e006e448ed
4 changed files with 37 additions and 1 deletions

12
app.py
View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3
"""Creatr App"""
from flask import Flask
from flask import Flask, request
from demo.utils.checker import inbox_prechecker
app = Flask(__name__)
@ -9,3 +10,12 @@ app = Flask(__name__)
def index():
"""Show index page"""
return "Hello Fediverse!"
@app.route("/inbox", methods=["POST"])
def inbox():
"""Process inbox request"""
is_verify = inbox_prechecker(request)
if is_verify:
return "STUB"
return "STUB"

1
demo/utils/__init__.py Normal file
View file

@ -0,0 +1 @@
#!/usr/bin/env python3

17
demo/utils/checker.py Normal file
View file

@ -0,0 +1,17 @@
from flask import Request, abort
from demo.httpsig import HttpSignature
def inbox_prechecker(
request: Request,
) -> bool:
try:
payload = request.headers
parsec_signature = HttpSignature.parse_signature(
payload["signature"]
)
print(parsec_signature)
except KeyError:
abort(401, "Missing signature key!")
return True

8
tests/test_inbox.py Normal file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env python3
"""Test inbox route."""
def test_inbox(client):
"""Test inbox"""
response = client.post("/inbox",
data={"name": "Test"})
assert response.status_code == 401