def test_invalid_header(self):
     # Two spaces, must only have one
     with patch('oidc_provider.authentication.get_authorization_header', return_value='Bearer bad token'):
             auth = JSONWebTokenAuthentication()
             with self.assertRaises(AuthenticationFailed):
                 auth.authenticate(None)
     # No spaces at all
     with patch('oidc_provider.authentication.get_authorization_header', return_value='Bearer'):
             auth = JSONWebTokenAuthentication()
             with self.assertRaises(AuthenticationFailed):
                 auth.authenticate(None)
    def test_validate_claims_issuer(self, config_patch):
        auth = JSONWebTokenAuthentication()
        with self.assertRaises(AuthenticationFailed) as error:
            auth.authenticate(None)

        self.assertIn('Invalid JWT issuer', str(error.exception))
    def test_validate_claims_audience(self, mock_aud):
        auth = JSONWebTokenAuthentication()
        with self.assertRaises(AuthenticationFailed) as error:
            auth.authenticate(None)

        self.assertIn('Invalid JWT audience', str(error.exception))
 def test_valid_token(self):
     auth = JSONWebTokenAuthentication()
     user, authenticated = auth.authenticate({})
     self.assertTrue(authenticated)