From 8c0872ea1ad26fc8f26037153155ce5ce8b6c110 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Sun, 20 Feb 2022 05:52:15 +0000 Subject: [PATCH] Remove ref check --- app/dependencies.py | 6 ------ app/main.py | 4 ++-- app/test/test.py | 20 ++++++++------------ 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/app/dependencies.py b/app/dependencies.py index 18b52ca..da7c3bd 100644 --- a/app/dependencies.py +++ b/app/dependencies.py @@ -3,12 +3,6 @@ import hmac from fastapi import Request from fastapi.exceptions import HTTPException -async def check_ref(request: Request): - json = await request.json() - if json["ref"] and json["ref"] == f"refs/heads/{getenv('BRANCH')}": - return - raise HTTPException(status_code=202, detail="Invalid branch") - async def auth_hook(request: Request): try: json = await request.json() diff --git a/app/main.py b/app/main.py index 39fea3e..e0f3268 100644 --- a/app/main.py +++ b/app/main.py @@ -1,13 +1,13 @@ from fastapi import FastAPI, Request, Depends from fastapi_responses import custom_openapi -from app.dependencies import auth_hook, auth_web, check_ref +from app.dependencies import auth_hook, auth_web app = FastAPI() app.openapi = custom_openapi(app) @app.get("/", dependencies=[Depends(auth_web)]) -@app.post("/", dependencies=[Depends(auth_hook), Depends(check_ref)]) +@app.post("/", dependencies=[Depends(auth_hook)]) async def hook(req: Request): return "Update" diff --git a/app/test/test.py b/app/test/test.py index 8ec842b..92ff5fb 100644 --- a/app/test/test.py +++ b/app/test/test.py @@ -3,7 +3,7 @@ from fastapi import FastAPI, Request, Depends from fastapi.testclient import TestClient import hmac from app.main import app -from app.dependencies import auth_hook, auth_web, check_ref +from app.dependencies import auth_hook, auth_web from os import environ, getenv import json @@ -18,10 +18,6 @@ client = TestClient(app) async def auth_test_handler(request: Request): return 200 -@app.post("/test_ref", dependencies=[Depends(check_ref)]) -async def auth_test_handler(request: Request): - return 200 - @app.get("/test_web", dependencies=[Depends(auth_web)]) async def web_test_hnadler(request: Request): return 200 @@ -51,14 +47,14 @@ def test_auth(): assert response.text == '{"detail":"Unauthorized"}' -def test_branch(): - payload = {"ref": "refs/heads/master"} - response = client.post("/test_ref", json= payload) - assert response.status_code == 202 +# def test_branch(): +# payload = {"ref": "refs/heads/master"} +# response = client.post("/test_ref", json= payload) +# assert response.status_code == 202 - payload = {"ref": "refs/heads/test"} - response = client.post("/test_ref", json= payload) - assert response.status_code == 403 +# payload = {"ref": "refs/heads/test"} +# response = client.post("/test_ref", json= payload) +# assert response.status_code == 403 def test_web(): response = client.get('/test_web?token={}'.format(getenv("TOKEN")))