Skip to content

Commit

Permalink
Remove ability to send key via query string
Browse files Browse the repository at this point in the history
  • Loading branch information
rosswhitfield committed Jul 8, 2024
1 parent 7b2b256 commit d74a0d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
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

0 comments on commit d74a0d1

Please sign in to comment.