Skip to content

Commit

Permalink
Add test coverage for util endpoints
Browse files Browse the repository at this point in the history
Make IP address lookups in util module safe
  • Loading branch information
NeonDaniel committed Nov 14, 2024
1 parent e266c34 commit 60121c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 5 additions & 3 deletions neon_hana/app/routers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@

@util_route.get("/client_ip", response_class=PlainTextResponse)
async def api_client_ip(request: Request) -> str:
client_manager.validate_auth("", request.client.host)
return request.client.host
ip_addr = request.client.host if request.client else "127.0.0.1"
client_manager.validate_auth("", ip_addr)
return ip_addr


@util_route.get("/headers")
async def api_headers(request: Request):
client_manager.validate_auth("", request.client.host)
ip_addr = request.client.host if request.client else "127.0.0.1"
client_manager.validate_auth("", ip_addr)
return request.headers
15 changes: 11 additions & 4 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,16 @@ def test_llm(self, send_request):
headers={"Authorization": f"Bearer {token}"})
self.assertEqual(response.status_code, 422, response.text)

@patch("neon_hana.mq_service_api.send_mq_request")
def test_util_headers(self, send_request):
send_request.return_value = {}
# TODO
def test_util_client_ip(self):
response = self.test_app.get("/util/client_ip")
self.assertEqual(response.text, "127.0.0.1")

def test_util_headers(self):
test_headers = {"X-Auth-Token": "Token",
"Authorization": "Test Auth",
"My Custom Header": "Value"}
response = self.test_app.get("/util/headers", headers=test_headers)
for key, val in test_headers.items():
self.assertEqual(response.json()[key.lower()], val, response.json())

# TODO: Define node endpoint tests

0 comments on commit 60121c7

Please sign in to comment.