Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ability to send key via query string #22

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/live_data_server/plots/view_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ def request_processor(request, instrument, run_id):

client_key = request.META.get("HTTP_AUTHORIZATION")

# getting the client_key from request.GET.get("key") should be
# removed after WebMon/WebRef supports Authorization request header
if client_key is None:
client_key = request.GET.get("key")

if client_key == server_key:
return fn(request, instrument, run_id)
return HttpResponse(status=401)
Expand Down
19 changes: 8 additions & 11 deletions tests/test_post_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,31 @@ def test_get_request(self, data_server):
)
assert http_request.status_code == HTTP_OK

base_url = f"{TEST_URL}/plots/{instrument}/{run_number}/update/html/"
url = f"{TEST_URL}/plots/{instrument}/{run_number}/update/html/"

# test GET request - authenticate with secret key
url = f"{base_url}?key={_generate_key(instrument, run_number)}"
http_request = requests.get(url)
http_request = requests.get(
url,
headers={"Authorization": _generate_key(instrument, run_number)},
)
assert http_request.status_code == HTTP_OK
assert http_request.text == files["file"]

# test that getting the json should return not found
http_request = requests.get(
f"{TEST_URL}/plots/{instrument}/{run_number}/update/json/?key={_generate_key(instrument, run_number)}"
f"{TEST_URL}/plots/{instrument}/{run_number}/update/json/",
headers={"Authorization": _generate_key(instrument, run_number)},
)
assert http_request.status_code == HTTP_NOT_FOUND
assert http_request.text == "No data available for REF_M 12346"

# test GET request - no key
url = base_url
http_request = requests.get(url)
assert http_request.status_code == HTTP_UNAUTHORIZED

# test GET request - wrong key
url = f"{base_url}?key=WRONG-KEY"
http_request = requests.get(url)
assert http_request.status_code == HTTP_UNAUTHORIZED

# test GET request - wrong key
http_request = requests.get(
base_url,
url,
headers={"Authorization": "WRONG-KEY"},
)
assert http_request.status_code == HTTP_UNAUTHORIZED
Expand Down
Loading