@@ -290,42 +290,12 @@ def test_access_resolution_controlled_never_reached2(self):
290290 with self .assertRaises (aiohttp .web_exceptions .HTTPForbidden ):
291291 access_resolution (request , token , host , [], [], [8 ])
292292
293- # @asynctest.mock.patch('beacon_api.permissions.ga4gh.retrieve_user_data')
294- # async def test_ga4gh_controlled(self, userinfo):
295- # """Test ga4gh permissions claim parsing."""
296- # userinfo.return_value = {
297- # "ControlledAccessGrants": [
298- # {
299- # "value": "https://www.ebi.ac.uk/ega/EGAD000000000001",
300- # "source": "https://ega-archive.org/dacs/EGAC00000000001",
301- # "by": "dac",
302- # "authoriser": "john.doe@dac.org",
303- # "asserted": 1546300800,
304- # "expires": 1577836800
305- # },
306- # {
307- # "value": "https://www.ebi.ac.uk/ega/EGAD000000000002",
308- # "source": "https://ega-archive.org/dacs/EGAC00000000001",
309- # "by": "dac",
310- # "authoriser": "john.doe@dac.org",
311- # "asserted": 1546300800,
312- # "expires": 1577836800
313- # },
314- # {
315- # "value": "no-prefix-dataset",
316- # "source": "https://ega-archive.org/dacs/EGAC00000000001",
317- # "by": "dac",
318- # "authoriser": "john.doe@dac.org",
319- # "asserted": 1546300800,
320- # "expires": 1577836800
321- # }
322- # ]
323- # }
324- # # Good test: claims OK, userinfo OK
325- # token_claim = ["ga4gh.ControlledAccessGrants"]
326- # token = 'this_is_a_jwt'
327- # datasets = await get_ga4gh_controlled(token, token_claim)
328- # self.assertEqual(datasets, {'EGAD000000000001', 'EGAD000000000002', 'no-prefix-dataset'}) # has permissions
293+ async def test_ga4gh_controlled (self ):
294+ """Test ga4gh permissions claim parsing."""
295+ # Good test: claims OK, userinfo OK
296+ token_claim = []
297+ datasets = await get_ga4gh_controlled (token_claim )
298+ self .assertEqual (datasets , set ()) # has permissions
329299 # # Bad test: no claims, userinfo OK
330300 # token_claim = []
331301 # token = 'this_is_a_jwt'
@@ -343,47 +313,31 @@ def test_access_resolution_controlled_never_reached2(self):
343313 # datasets = await get_ga4gh_controlled(token, token_claim)
344314 # self.assertEqual(datasets, set()) # doesn't have permissions
345315
346- # @asynctest.mock.patch('beacon_api.permissions.ga4gh.retrieve_user_data')
347- # async def test_ga4gh_bona_fide(self, userinfo):
348- # """Test ga4gh statuses claim parsing."""
349- # userinfo.return_value = {
350- # "AcceptedTermsAndPolicies": [
351- # {
352- # "value": "https://doi.org/10.1038/s41431-018-0219-y",
353- # "source": "https://ga4gh.org/duri/no_org",
354- # "by": "self",
355- # "asserted": 1539069213,
356- # "expires": 4694742813
357- # }
358- # ],
359- # "ResearcherStatus": [
360- # {
361- # "value": "https://doi.org/10.1038/s41431-018-0219-y",
362- # "source": "https://ga4gh.org/duri/no_org",
363- # "by": "peer",
364- # "asserted": 1539017776,
365- # "expires": 1593165413
366- # }
367- # ]
368- # }
369- # # Good test: claims OK, userinfo OK
370- # passports = ["ga4gh.AcceptedTermsAndPolicies", "ga4gh.ResearcherStatus"]
371- # bona_fide_status = await get_ga4gh_bona_fide(passports)
372- # self.assertEqual(bona_fide_status, True) # has bona fide
373- # # Bad test: no claims, userinfo OK
374- # passports = []
375- # bona_fide_status = await get_ga4gh_bona_fide(passports)
376- # self.assertEqual(bona_fide_status, False) # doesn't have bona fide
377- # # Bad test: claims OK, no userinfo
378- # userinfo.return_value = {}
379- # passports = ["ga4gh.AcceptedTermsAndPolicies", "ga4gh.ResearcherStatus"]
380- # bona_fide_status = await get_ga4gh_bona_fide(passports)
381- # self.assertEqual(bona_fide_status, False) # doesn't have bona fide
382- # # Bad test: no claims, no userinfo
383- # userinfo.return_value = {}
384- # passports = []
385- # bona_fide_status = await get_ga4gh_bona_fide(passports)
386- # self.assertEqual(bona_fide_status, False) # doesn't have bona fide
316+ @asynctest .mock .patch ('beacon_api.permissions.ga4gh.retrieve_user_data' )
317+ async def test_ga4gh_bona_fide (self , userinfo ):
318+ """Test ga4gh statuses claim parsing."""
319+ passports = [("enc" , "header" , {
320+ "ga4gh_visa_v1" : {"type" : "AcceptedTermsAndPolicies" ,
321+ "value" : "https://doi.org/10.1038/s41431-018-0219-y" ,
322+ "source" : "https://ga4gh.org/duri/no_org" ,
323+ "by" : "self" ,
324+ "asserted" : 1539069213 ,
325+ "expires" : 4694742813 }
326+ }),
327+ ("enc" , "header" , {
328+ "ga4gh_visa_v1" : {"type" : "ResearcherStatus" ,
329+ "value" : "https://doi.org/10.1038/s41431-018-0219-y" ,
330+ "source" : "https://ga4gh.org/duri/no_org" ,
331+ "by" : "peer" ,
332+ "asserted" : 1539017776 ,
333+ "expires" : 1593165413 }})]
334+ # Good test: claims OK, userinfo OK
335+ bona_fide_status = await get_ga4gh_bona_fide (passports )
336+ self .assertEqual (bona_fide_status , True ) # has bona fide
337+ # Bad test: no claims, userinfo OK
338+ passports_empty = []
339+ bona_fide_status = await get_ga4gh_bona_fide (passports_empty )
340+ self .assertEqual (bona_fide_status , False ) # doesn't have bona fide
387341
388342
389343if __name__ == '__main__' :
0 commit comments