def test_default_url(self):
     content = get_file_content(os.path.join(DIR_PATH, 'correct.txt'))
     with responses.RequestsMock() as rsps:
         rsps.add(responses.GET,
                  'https://mds2.fidoalliance.org/',
                  body=content)
         _get_metadata()
 def test_error_response(self):
     with responses.RequestsMock() as rsps:
         with self.assertRaisesMessage(CommandError, 'MDS response error.'):
             rsps.add(responses.GET,
                      'https://mds2.fidoalliance.org/',
                      body=RequestException('Some error'))
             _get_metadata()
 def test_malformed_response(self):
     with responses.RequestsMock() as rsps:
         with self.assertRaisesMessage(CommandError,
                                       'MDS response malformed.'):
             rsps.add(responses.GET,
                      'https://mds2.fidoalliance.org/',
                      body='')
             _get_metadata()
 def test_bad_signature_response(self):
     content = get_file_content(os.path.join(DIR_PATH, 'bad.txt'))
     with responses.RequestsMock() as rsps:
         with self.assertRaisesMessage(CommandError,
                                       'Could not verify MDS signature.'):
             rsps.add(responses.GET,
                      'https://mds2.fidoalliance.org/',
                      body=content)
             _get_metadata()
 def test_custom_url(self):
     content = get_file_content(os.path.join(DIR_PATH, 'correct.txt'))
     with override_settings(
             DJANGO_FIDO_METADATA_SERVICE={
                 'ACCESS_TOKEN': 'secret_token',
                 'URL': 'https://example.com',
                 'CERTIFICATE': [os.path.join(DIR_PATH, 'Root.cer')]
             }):
         with responses.RequestsMock() as rsps:
             rsps.add(responses.GET, 'https://example.com', body=content)
             _get_metadata()
 def test_bad_cert(self):
     content = get_file_content(os.path.join(DIR_PATH, 'correct.txt'))
     with override_settings(
             DJANGO_FIDO_METADATA_SERVICE={
                 'ACCESS_TOKEN': 'secret_token',
                 'CERTIFICATE': [os.path.join(DIR_PATH, 'Root_bad.cer')]
             }):
         with responses.RequestsMock() as rsps:
             rsps.add(responses.GET,
                      'https://mds2.fidoalliance.org/',
                      body=content)
             with self.assertRaises(CommandError):
                 _get_metadata()
 def test_ok_response(self):
     content = get_file_content(os.path.join(DIR_PATH, 'correct.txt'))
     with responses.RequestsMock() as rsps:
         rsps.add(responses.GET,
                  'https://mds2.fidoalliance.org/',
                  body=content)
         metadata, alg = _get_metadata()
     self.assertEqual(set(metadata.keys()),
                      {'entries', 'nextUpdate', 'no', 'legalHeader'})
     self.assertEqual(alg, 'ES256')