From 953483a7389619cb9c555743096cbaf80943820b Mon Sep 17 00:00:00 2001 From: Jan Salapatek Date: Tue, 14 Jun 2022 13:43:17 +0200 Subject: [PATCH] added api-key.txt file to server for download. --- .github/workflows/build_and_test.yaml | 4 ++-- test/resources/resources.yaml | 2 +- test/server/Dockerfile | 1 + test/server/api-key.txt | 1 + test/server/server.py | 6 ++++-- 5 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 test/server/api-key.txt diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 394f2524..4037e831 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -137,6 +137,6 @@ jobs: echo -n "This relatively exists" | diff - /tmp/5xx/relative.txt && echo -n "500" | diff - /tmp/5xx/500.txt && ls /tmp/5xx/script_result && - grep "200" /tmp/api-key/api-key.txt && echo "api-key used successfully for authentication" && - grep "Forbidden" /tmp/api-key-fails/api-key.txt && echo "api-key-fails expectedly with wrong credentials" + grep -i "success" /tmp/api-key/api-key.txt && echo "api-key used successfully for authentication" && + [ ! -f /tmp/api-key-fails/api-key.txt ] && echo "api-key-fails expectedly with wrong credentials" \ No newline at end of file diff --git a/test/resources/resources.yaml b/test/resources/resources.yaml index 6c1080e2..608804f4 100644 --- a/test/resources/resources.yaml +++ b/test/resources/resources.yaml @@ -59,4 +59,4 @@ metadata: labels: findme: "sure" data: - api-key.txt.url: "http://dummy-server/200/api-key" \ No newline at end of file + api-key.txt.url: "http://dummy-server/200/api-key.txt" \ No newline at end of file diff --git a/test/server/Dockerfile b/test/server/Dockerfile index 1992415a..b1f9e8f5 100644 --- a/test/server/Dockerfile +++ b/test/server/Dockerfile @@ -2,4 +2,5 @@ FROM python:3.9-alpine RUN pip install fastapi uvicorn EXPOSE 80 COPY server.py /server.py +COPY api-key.txt /api-key.txt CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "80"] diff --git a/test/server/api-key.txt b/test/server/api-key.txt new file mode 100644 index 00000000..caaa5e19 --- /dev/null +++ b/test/server/api-key.txt @@ -0,0 +1 @@ +Success! I can only be downloaded with the correct combination of API Key and password! \ No newline at end of file diff --git a/test/server/server.py b/test/server/server.py index 22b9a77d..60903f5f 100644 --- a/test/server/server.py +++ b/test/server/server.py @@ -1,5 +1,7 @@ from fastapi import FastAPI, Security, Depends, HTTPException from fastapi.security.api_key import APIKeyQuery, APIKey +from fastapi.responses import FileResponse + API_KEY_NAME="private_token" API_KEY="super-duper-secret" @@ -38,6 +40,6 @@ async def read_item(): return 503 -@app.get("/200/api-key") +@app.get("/200/api-key.txt", response_class=FileResponse) def read_root(api_key: APIKey = Depends(get_api_key)): - return 200 + return "api-key.txt"