Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BinamB committed Nov 23, 2021
1 parent dcaf3de commit 2cd1263
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
8 changes: 4 additions & 4 deletions fence/blueprints/data/indexd.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ def get_signed_url_for_file(
if ga4gh_passports:
# TODO change this to usernames
user_ids_from_passports = get_gen3_users_from_ga4gh_passports(ga4gh_passports)
print("------------user idss from passports---------------")
print(user_ids_from_passports)

# add the user details to `flask.g.audit_data` first, so they are
# included in the audit log if `IndexedFile(file_id)` raises a 404
Expand Down Expand Up @@ -425,7 +423,9 @@ def get_signed_url(
f"{action_to_permission[action]} permission "
f"on authz resource: {self.index_document['authz']}"
)
authorized_user_id = authorized_user_id if isinstance(authorized_user_id, str) else None
authorized_user_id = (
authorized_user_id if isinstance(authorized_user_id, str) else None
)
else:
if self.public_acl and action == "upload":
raise Unauthorized(
Expand Down Expand Up @@ -520,7 +520,7 @@ def check_authz(self, action, user_ids_from_passports=None):
)

# handle multiple GA4GH passports as a means of authn/z

if user_ids_from_passports:
for user_id in user_ids_from_passports:
authorized = flask.current_app.arborist.auth_request(
Expand Down
8 changes: 1 addition & 7 deletions fence/resources/google/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,7 @@ def _get_proxy_group_id(user_id=None):

if not proxy_group_id:
user_id = user_id or current_token["sub"]
user = (
current_session.query(User).filter(User.id == user_id).first()
)
user = current_session.query(User).filter(User.id == user_id).first()
proxy_group_id = user.google_proxy_group_id

return proxy_group_id
Expand Down Expand Up @@ -607,10 +605,6 @@ def _create_proxy_group(user_id, username):

# link proxy group to user
user = current_session.query(User).filter_by(id=user_id).first()
print("----------proxy grou id---------------- ")
print(proxy_group)
print(proxy_group.id)
print(user)
user.google_proxy_group_id = proxy_group.id

current_session.add(proxy_group)
Expand Down
15 changes: 8 additions & 7 deletions tests/test_drs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import flask
import httpx
import json
import jwt
import pytest
Expand Down Expand Up @@ -239,9 +240,13 @@ def test_get_presigned_url_with_query_params(

@responses.activate
@pytest.mark.parametrize("indexd_client", ["s3", "gs"], indirect=True)
@patch("httpx.get")
@patch("fence.resources.google.utils._create_proxy_group")
@patch("fence.resources.ga4gh.passports.ArboristClient")
def test_get_presigned_url_with_passport_for_non_public_acl(
mock_arborist,
mock_google_proxy_group,
mock_httpx_get,
client,
indexd_client,
kid,
Expand Down Expand Up @@ -274,6 +279,7 @@ def test_get_presigned_url_with_passport_for_non_public_acl(
)
mock_arborist_requests({"arborist/auth/request": {"POST": ({"auth": True}, 200)}})
mock_arborist.return_value = MagicMock(ArboristClient)
mock_google_proxy_group.return_value = google_proxy_group

# Prepare Passport/Visa
headers = {"kid": kid}
Expand Down Expand Up @@ -377,11 +383,8 @@ def test_get_presigned_url_with_passport_for_non_public_acl(

data = {"passports": passports}

flask.current_app.jwt_public_keys = {
"https://stsstg.nih.gov": {
kid: rsa_public_key,
}
}
keys = [keypair.public_key_to_jwk() for keypair in flask.current_app.keypairs]
mock_httpx_get.return_value = httpx.Response(200, json={"keys": keys})

res = client.post(
"/ga4gh/drs/v1/objects/" + test_guid + "/access/" + access_id,
Expand All @@ -391,5 +394,3 @@ def test_get_presigned_url_with_passport_for_non_public_acl(
data=json.dumps(data),
)
assert res.status_code == 200

flask.current_app.jwt_public_keys = {}

0 comments on commit 2cd1263

Please sign in to comment.