Skip to content

Commit

Permalink
added api-key.txt file to server for download.
Browse files Browse the repository at this point in the history
  • Loading branch information
jansalapatek committed Jun 14, 2022
1 parent 8335ced commit 953483a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion test/resources/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ metadata:
labels:
findme: "sure"
data:
api-key.txt.url: "http://dummy-server/200/api-key"
api-key.txt.url: "http://dummy-server/200/api-key.txt"
1 change: 1 addition & 0 deletions test/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions test/server/api-key.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Success! I can only be downloaded with the correct combination of API Key and password!
6 changes: 4 additions & 2 deletions test/server/server.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"

0 comments on commit 953483a

Please sign in to comment.