Skip to content

Commit

Permalink
Restore original test cases
Browse files Browse the repository at this point in the history
Add `__getitem__` to `AuthenticationResponse` for backwards-compat.
  • Loading branch information
NeonDaniel committed Nov 5, 2024
1 parent 2cbfad0 commit e38af4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
9 changes: 6 additions & 3 deletions neon_hana/auth/client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ def check_auth_request(self, client_id: str, username: str,
@param origin_ip: Origin IP address of request
@return: response tokens, permissions, and other metadata
"""
if client_id in self.authorized_clients:
print(f"Using cached client: {self.authorized_clients[client_id]}")
return self.authorized_clients[client_id]
# Caching does not work here because there is no guarantee that this
# instance knows the client's refresh token. One client may also want
# to generate multiple tokens.
# if client_id in self.authorized_clients:
# print(f"Using cached client: {self.authorized_clients[client_id]}")
# return self.authorized_clients[client_id]

ratelimit_id = f"auth{origin_ip}"
if not self.rate_limiter.get_all_buckets(ratelimit_id):
Expand Down
4 changes: 4 additions & 0 deletions neon_hana/schema/auth_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class AuthenticationResponse(BaseModel):
"expiration": 1706045776.4168212
}]}}

def __getitem__(self, item):
if hasattr(self, item):
return getattr(self, item)
raise KeyError(item)

class RefreshRequest(BaseModel):
access_token: str
Expand Down
8 changes: 4 additions & 4 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ def test_check_auth_request(self):
auth_resp_1 = self.client_manager.check_auth_request(**request_1)
self.assertEqual(self.client_manager.authorized_clients[client_1],
auth_resp_1)
self.assertEqual(auth_resp_1.username, 'guest')
self.assertEqual(auth_resp_1.client_id, client_1)
self.assertEqual(auth_resp_1['username'], 'guest')
self.assertEqual(auth_resp_1['client_id'], client_1)

# Check auth from different client
auth_resp_2 = self.client_manager.check_auth_request(**request_2)
self.assertNotEquals(auth_resp_1, auth_resp_2)
self.assertEqual(self.client_manager.authorized_clients[client_2],
auth_resp_2)
self.assertEqual(auth_resp_2.username, 'guest')
self.assertEqual(auth_resp_2.client_id, client_2)
self.assertEqual(auth_resp_2['username'], 'guest')
self.assertEqual(auth_resp_2['client_id'], client_2)

# TODO: Test permissions

Expand Down

0 comments on commit e38af4c

Please sign in to comment.