diff --git a/neon_hana/app/routers/util.py b/neon_hana/app/routers/util.py index a4bf674..8b91e82 100644 --- a/neon_hana/app/routers/util.py +++ b/neon_hana/app/routers/util.py @@ -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 diff --git a/tests/test_app.py b/tests/test_app.py index 6fb9924..88b05d5 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -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