Skip to content

Commit

Permalink
Trying to reconcile tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Filienko committed Aug 14, 2024
1 parent b45080b commit dc6dc49
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -57,14 +84,14 @@ 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'})
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)
self.assertEqual(response.json.get('message'), 'request proxied')

# Test missing token
response = self.client.get('/')
Expand All @@ -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()

0 comments on commit dc6dc49

Please sign in to comment.