diff --git a/tests/test_api.py b/tests/test_api.py index e367463..193ea6e 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -45,6 +45,33 @@ def test_proxy_request(self, mock_request): response = proxy_request(req, 'http://example.com/api') self.assertEqual(response, "Plain text response") + def test_smart_configuration(self): + """Test /fhir/.well-known/smart-configuration endpoint""" + response = self.client.get('/fhir/.well-known/smart-configuration') + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json, { + 'authorization_endpoint': 'http://authorize.example.com', + 'token_endpoint': 'http://token.example.com', + 'introspection_endpoint': 'http://introspection.example.com' + }) + + def test_config_settings(self): + """Test /settings endpoint""" + # Test retrieving non-sensitive config + response = self.client.get('/settings') + self.assertEqual(response.status_code, 200) + self.assertIn('UPSTREAM_SERVER', response.json) + self.assertNotIn('SECRET', response.json) + + # Test retrieving specific config + response = self.client.get('/settings/UPSTREAM_SERVER') + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json['UPSTREAM_SERVER'], 'http://example.com') + + # Test accessing sensitive config + response = self.client.get('/settings/SECRET_KEY') + self.assertEqual(response.status_code, 400) + @patch('jwt.PyJWKClient') @patch('jwt.decode') def test_validate_jwt(self, mock_decode, mock_jwk_client): @@ -57,7 +84,6 @@ def test_validate_jwt(self, mock_decode, mock_jwk_client): # Set up mock JWT decoding mock_decode.return_value = {'email': 'user@example.com'} - self.app.json = CustomJSONProvider(self.app) # Test valid token response = self.client.get('/', headers={'Authorization': 'Bearer valid_token'}) @@ -65,6 +91,7 @@ def test_validate_jwt(self, mock_decode, mock_jwk_client): print(f'Response Data: {response.data.decode()}') print(f'Response JSON: {response.json}') self.assertEqual(response.status_code, 200) + self.assertEqual(response.json.get('message'), 'request proxied') # Test missing token response = self.client.get('/') @@ -84,38 +111,12 @@ def test_validate_jwt(self, mock_decode, mock_jwk_client): self.assertEqual(response.json.get('message'), "token expired") # Test whitelisted path without token - response = self.client.get('/whitelisted', content_type='application/json') + response = self.client.get('/whitelisted') print(f'Status Code: {response.status_code}') print(f'Response Data: {response.data.decode()}') print(f'Response JSON: {response.json}') self.assertEqual(response.status_code, 200) - - def test_smart_configuration(self): - """Test /fhir/.well-known/smart-configuration endpoint""" - response = self.client.get('/fhir/.well-known/smart-configuration') - self.assertEqual(response.status_code, 200) - self.assertEqual(response.json, { - 'authorization_endpoint': 'http://authorize.example.com', - 'token_endpoint': 'http://token.example.com', - 'introspection_endpoint': 'http://introspection.example.com' - }) - - def test_config_settings(self): - """Test /settings endpoint""" - # Test retrieving non-sensitive config - response = self.client.get('/settings') - self.assertEqual(response.status_code, 200) - self.assertIn('UPSTREAM_SERVER', response.json) - self.assertNotIn('SECRET', response.json) - - # Test retrieving specific config - response = self.client.get('/settings/UPSTREAM_SERVER') - self.assertEqual(response.status_code, 200) - self.assertEqual(response.json['UPSTREAM_SERVER'], 'http://example.com') - - # Test accessing sensitive config - response = self.client.get('/settings/SECRET_KEY') - self.assertEqual(response.status_code, 400) + self.assertEqual(response.json.get('message'), 'whitelisted path accessed') if __name__ == '__main__': unittest.main()