Skip to content

Commit

Permalink
Up unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
Filienko committed Aug 14, 2024
1 parent 15858a8 commit c62aec0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 12 additions & 3 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,26 @@ def test_validate_jwt(self, mock_decode, mock_jwk_client):
self.assertEqual(response.status_code, 200)

# Test valid token
response = self.client.get('/', headers={'Authorization': 'Bearer valid_token', 'Content-Type': 'application/json'})
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)

# Test missing token
response = self.client.get('/', headers={'Content-Type': 'application/json'})
response = self.client.get('/')
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, 400)
self.assertEqual(response.json['message'], "token missing")

# Test expired token
mock_decode.side_effect = jwt.exceptions.ExpiredSignatureError()
response = self.client.get('/', headers={'Authorization': 'Bearer expired_token', 'Content-Type': 'application/json'})
response = self.client.get('/', headers={'Authorization': 'Bearer expired_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, 401)
self.assertEqual(response.json['message'], "token expired")

Expand Down
2 changes: 0 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
class TestConfig:
TESTING = True


class TestIsaccJWTProxyApp(unittest.TestCase):
def setUp(self):
self.app = create_app(testing=True)
Expand All @@ -18,6 +17,5 @@ def test_app_exists(self):
def test_blueprints_registered(self):
self.assertIn('auth', self.app.blueprints)


if __name__ == '__main__':
unittest.main()

0 comments on commit c62aec0

Please sign in to comment.