def test_get_uaa_public_key_no_value_key(self, mock_request):
     """When there isn't a 'value' key in the returned json, a KeyError exception is raised.  This test, however,
     assertIsNone because the exception is consumed, an exception is logged and then returns None.
     """
     mock_request.get(f'{self.app.config["UAA_SERVICE_URL"]}/token_key',
                      json={'notvalue': 'text'})
     self.app.config["UAA_PUBLIC_KEY"] = None
     with self.app.app_context():
         self.assertIsNone(uaa.get_uaa_public_key())
 def test_get_uaa_public_key_server_error_response(self, mock_request):
     """When the getting of the public key fails a HTTPError exception is raised.  This test, however,
     assertIsNone because the exception is consumed, an exception is logged and then returns None.
     """
     mock_request.get(f'{self.app.config["UAA_SERVICE_URL"]}/token_key',
                      status_code=500)
     self.app.config["UAA_PUBLIC_KEY"] = None
     with self.app.app_context():
         self.assertIsNone(uaa.get_uaa_public_key())
Beispiel #3
0
def decode_access_token(access_token):
    """Decodes the access token provided by uaa.  It's important to note that this JWT is
    using RS256 as it's what uaa uses whereas other parts of the application use HS256.
    """
    uaa_public_key = get_uaa_public_key()
    decoded_jwt = jwt.decode(access_token,
                             key=uaa_public_key,
                             algorithms=['RS256'],
                             audience='response_operations',
                             leeway=10)
    return decoded_jwt
 def test_get_uaa_public_key_with_no_config_set(self, mock_request):
     mock_request.get(f'{self.app.config["UAA_SERVICE_URL"]}/token_key',
                      json={'value': 'Test'})
     self.app.config["UAA_PUBLIC_KEY"] = None
     with self.app.app_context():
         self.assertEqual("Test", uaa.get_uaa_public_key())
 def test_get_uaa_public_key_with_config_set(self):
     with self.app.app_context():
         self.assertEqual(TestingConfig.UAA_PUBLIC_KEY,
                          uaa.get_uaa_public_key())