Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit c7fa2bc

Browse files
committed
update mockauth for integration tests, fix bug in integtest17 and typo in integtest32
1 parent e8de1cd commit c7fa2bc

2 files changed

Lines changed: 77 additions & 47 deletions

File tree

deploy/test/integ_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ async def test_17():
389389
async with session.post('http://localhost:5050/query', data=json.dumps(payload)) as resp:
390390
data = await resp.json()
391391
assert data['exists'] is True, sys.exit('Query POST Endpoint Error!')
392-
assert len(data['datasetAlleleResponses']) == 1, sys.exit('Should be able to retrieve both requested.')
392+
assert len(data['datasetAlleleResponses']) == 2, sys.exit('Should be able to retrieve both requested.')
393393

394394

395395
async def test_18():
@@ -701,7 +701,7 @@ async def test_32():
701701
async with aiohttp.ClientSession() as session:
702702
async with session.get('http://localhost:5050/service-info') as resp:
703703
data = await resp.json()
704-
# GA4GH Discovery Service-Info is small and its length should be between 3 and 6, when the Beacon info is very long
704+
# GA4GH Discovery Service-Info is small and its length should be at least 5 (required keys), when the Beacon info is very long
705705
# https://github.com/ga4gh-discovery/service-info/blob/develop/service-info.yaml
706706
assert len(data) >= 5, 'Service info size error' # ga4gh service-info has 5 required keys, and option to add custom keys
707707
assert data['type'].startswith('org.ga4gh:beacon'), 'Service type error' # a new key used in beacon network

deploy/test/mock_auth.py

Lines changed: 75 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@ def generate_token():
2727
"sub": "requester@elixir-europe.org",
2828
"aud": ["aud2", "aud3"],
2929
"azp": "azp",
30-
"scope": "openid ga4gh",
30+
"scope": "openid ga4gh_passport_v1",
3131
"iss": "http://test.csc.fi",
3232
"exp": 9999999999,
3333
"iat": 1561621913,
34-
"jti": "6ad7aa42-3e9c-4833-bd16-765cb80c2102",
35-
"ga4gh_userinfo_claims": [
36-
"ga4gh.AffiliationAndRole",
37-
"ga4gh.ControlledAccessGrants",
38-
"ga4gh.AcceptedTermsAndPolicies",
39-
"ga4gh.ResearcherStatus"
40-
]
34+
"jti": "6ad7aa42-3e9c-4833-bd16-765cb80c2102"
4135
}
4236
empty_payload = {
4337
"sub": "requester@elixir-europe.org",
@@ -46,11 +40,77 @@ def generate_token():
4640
"iat": 1547794655,
4741
"jti": "6ad7aa42-3e9c-4833-bd16-765cb80c2102"
4842
}
43+
# Craft 4 passports, 2 for bona fide status and 2 for dataset permissions
44+
# passport for bona fide: terms
45+
passport_terms = {
46+
"iss": "http://test.csc.fi",
47+
"sub": "requester@elixir-europe.org",
48+
"ga4gh_visa_v1": {
49+
"type": "AcceptedTermsAndPolicies",
50+
"value": "https://doi.org/10.1038/s41431-018-0219-y",
51+
"source": "https://ga4gh.org/duri/no_org",
52+
"by": "dac",
53+
"asserted": 1568699331
54+
},
55+
"iat": 1571144438,
56+
"exp": 99999999999,
57+
"jti": "bed0aff9-29b1-452c-b776-a6f2200b6db1"
58+
}
59+
# passport for bona fide: status
60+
passport_status = {
61+
"iss": "http://test.csc.fi",
62+
"sub": "requester@elixir-europe.org",
63+
"ga4gh_visa_v1": {
64+
"type": "ResearcherStatus",
65+
"value": "https://doi.org/10.1038/s41431-018-0219-y",
66+
"source": "https://ga4gh.org/duri/no_org",
67+
"by": "peer",
68+
"asserted": 1568699331
69+
},
70+
"iat": 1571144438,
71+
"exp": 99999999999,
72+
"jti": "722ddde1-617d-4651-992d-f0fdde77bf29"
73+
}
74+
# passport for dataset permissions 1
75+
passport_dataset1 = {
76+
"iss": "http://test.csc.fi",
77+
"sub": "requester@elixir-europe.org",
78+
"ga4gh_visa_v1": {
79+
"type": "ControlledAccessGrants",
80+
"value": "https://www.ebi.ac.uk/ega/urn:hg:1000genome:controlled",
81+
"source": "https://ga4gh.org/duri/no_org",
82+
"by": "self",
83+
"asserted": 1568699331
84+
},
85+
"iat": 1571144438,
86+
"exp": 99999999999,
87+
"jti": "d1d7b521-bd6b-433d-b2d5-3d874aab9d55"
88+
}
89+
# passport for dataset permissions 2
90+
passport_dataset2 = {
91+
"iss": "http://test.csc.fi",
92+
"sub": "requester@elixir-europe.org",
93+
"ga4gh_visa_v1": {
94+
"type": "ControlledAccessGrants",
95+
"value": "https://www.ebi.ac.uk/ega/urn:hg:1000genome:controlled1",
96+
"source": "https://ga4gh.org/duri/no_org",
97+
"by": "dac",
98+
"asserted": 1568699331
99+
},
100+
"iat": 1571144438,
101+
"exp": 99999999999,
102+
"jti": "9fa600d6-4148-47c1-b708-36c4ba2e980e"
103+
}
49104
public_jwk = jwk.dumps(public_key, kty='RSA')
50105
private_jwk = jwk.dumps(pem, kty='RSA')
51106
dataset_encoded = jwt.encode(header, dataset_payload, private_jwk).decode('utf-8')
52107
empty_encoded = jwt.encode(header, empty_payload, private_jwk).decode('utf-8')
53-
return (public_jwk, dataset_encoded, empty_encoded)
108+
passport_terms_encoded = jwt.encode(header, passport_terms, private_jwk).decode('utf-8')
109+
passport_status_encoded = jwt.encode(header, passport_status, private_jwk).decode('utf-8')
110+
passport_dataset1_encoded = jwt.encode(header, passport_dataset1, private_jwk).decode('utf-8')
111+
passport_dataset2_encoded = jwt.encode(header, passport_dataset2, private_jwk).decode('utf-8')
112+
return (public_jwk, dataset_encoded, empty_encoded, passport_terms_encoded, passport_status_encoded,
113+
passport_dataset1_encoded, passport_dataset2_encoded)
54114

55115

56116
DATA = generate_token()
@@ -75,42 +135,12 @@ async def userinfo(request):
75135
data = {}
76136
else:
77137
data = {
78-
"ga4gh": {
79-
"AcceptedTermsAndPolicies": [
80-
{
81-
"value": "https://doi.org/10.1038/s41431-018-0219-y",
82-
"source": "https://ga4gh.org/duri/no_org",
83-
"by": "self",
84-
"asserted": 1539069213,
85-
"expires": 9999999999
86-
}
87-
],
88-
"ResearcherStatus": [
89-
{
90-
"value": "https://doi.org/10.1038/s41431-018-0219-y",
91-
"source": "https://ga4gh.org/duri/no_org",
92-
"by": "peer",
93-
"asserted": 1539017776,
94-
"expires": 9999999999
95-
}
96-
],
97-
"ControlledAccessGrants": [
98-
{
99-
"value": "https://www.ebi.ac.uk/ega/urn:hg:1000genome",
100-
"source": "https://ga4gh.org/duri/no_org",
101-
"by": "dac",
102-
"asserted": 1559893314,
103-
"expires": 9999999999
104-
},
105-
{
106-
"value": "https://www.ebi.ac.uk/ega/urn:hg:1000genome:controlled",
107-
"source": "https://ga4gh.org/duri/no_org",
108-
"by": "dac",
109-
"asserted": 1559897355,
110-
"expires": 9999999999
111-
}
112-
]
113-
}
138+
"ga4gh_passport_v1": [
139+
DATA[3],
140+
DATA[4],
141+
DATA[5],
142+
DATA[6]
143+
]
114144
}
115145
return web.json_response(data)
116146

0 commit comments

Comments
 (0)