Skip to content

Commit

Permalink
Merge pull request #259 from CanDIG/daisieh/allele_form
Browse files Browse the repository at this point in the history
  • Loading branch information
daisieh authored May 3, 2023
2 parents 182237a + b6aeb8d commit 10a3e40
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions htsget_server/authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def is_authed(id_, request):
if request is None:
return 401
if request.headers.get("Test_Key") == TEST_KEY:
if request.headers.get("Authorization") == f"Bearer {TEST_KEY}":
print("WARNING: TEST MODE, AUTHORIZATION IS DISABLED")
app.logger.warning("WARNING: TEST MODE, AUTHORIZATION IS DISABLED")
return 200 # no auth
Expand All @@ -30,7 +30,7 @@ def is_authed(id_, request):


def is_testing(request):
if request.headers.get("Test_Key") == TEST_KEY:
if request.headers.get("Authorization") == f"Bearer {TEST_KEY}":
print("WARNING: TEST MODE, AUTHORIZATION IS DISABLED")
app.logger.warning("WARNING: TEST MODE, AUTHORIZATION IS DISABLED")
return True
Expand All @@ -49,7 +49,7 @@ def is_site_admin(request):
"""
Is the user associated with the token a site admin?
"""
if request.headers.get("Test_Key") == TEST_KEY:
if request.headers.get("Authorization") == f"Bearer {TEST_KEY}":
print("WARNING: TEST MODE, AUTHORIZATION IS DISABLED")
app.logger.warning("WARNING: TEST MODE, AUTHORIZATION IS DISABLED")
return True # no auth
Expand Down
7 changes: 7 additions & 0 deletions htsget_server/beacon_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json
import re
import connexion
from functools import reduce


app = Flask(__name__)
Expand Down Expand Up @@ -126,6 +127,12 @@ def post_search():
if 'requestedGranularity' not in req:
req['requestedGranularity'] = 'record'

params = list(req['query']['requestParameters'].keys())
for param in params:
# change all names of parameters to snake case from camel case
new_param = reduce(lambda x, y: x + ('_' if y.isupper() else '') + y, param).lower()
req['query']['requestParameters'][new_param] = req['query']['requestParameters'].pop(param)

try:
result = search(req)
return result, 200
Expand Down
12 changes: 6 additions & 6 deletions tests/test_htsget_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@


def get_headers(username=USERNAME, password=PASSWORD):
headers={"Test_Key": TEST_KEY}
headers = {}
try:
token = get_access_token(username=username, password=password)
headers["Authorization"] = f"Bearer {token}"
except Exception as e:
headers["Authorization"] = "Bearer testtest"
headers["Authorization"] = f"Bearer {TEST_KEY}"
return headers


Expand Down Expand Up @@ -354,7 +354,7 @@ def test_beacon_get_search():

# for an unauthorized user, the request should not contain a full response, just a count
headers = get_headers(username="test", password="test")
headers.pop("Test_Key")
headers["Authorization"] = "Bearer unauthorized"
response = requests.get(url, headers=headers)
print(response.text)
assert 'response' not in response.json()
Expand All @@ -371,8 +371,8 @@ def get_beacon_post_search():
"requestParameters": {
"start": [5030000],
"end": [5030847],
"assembly_id": "hg37",
"reference_name": "21"
"assemblyId": "hg37",
"referenceName": "21"
}
},
"meta": {
Expand All @@ -388,7 +388,7 @@ def get_beacon_post_search():
"requestParameters": {
"start": [16562322],
"end": [16613564],
"reference_name": "1"
"referenceName": "1"
}
},
"meta": {
Expand Down

0 comments on commit 10a3e40

Please sign in to comment.