Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitvinnakota-codecov committed Jan 17, 2025
1 parent c0b07ff commit da13f82
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions api/gen_ai/tests/test_gen_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_missing_parameters(self, mock_config):
VIEW_URL,
data=payload,
content_type="application/json",
HTTP_X_GEN_AI_AUTH_SIGNATURE=sig,
HTTP_HTTP_X_GEN_AI_AUTH_SIGNATURE=sig,
)
self.assertEqual(response.status_code, 400)
self.assertIn("Missing required parameters", response.data)
Expand All @@ -45,7 +45,7 @@ def test_invalid_signature(self, mock_config):
VIEW_URL,
data=payload,
content_type="application/json",
HTTP_X_GEN_AI_AUTH_SIGNATURE=wrong_sig,
HTTP_HTTP_X_GEN_AI_AUTH_SIGNATURE=wrong_sig,
)
self.assertEqual(response.status_code, 403)

Expand All @@ -55,7 +55,7 @@ def test_owner_not_found(self, mock_config):
sig, serialized_data = sign_payload(payload)
response = self.client.post(
VIEW_URL,
HTTP_X_GEN_AI_AUTH_SIGNATURE=sig,
HTTP_HTTP_X_GEN_AI_AUTH_SIGNATURE=sig,
data=serialized_data,
content_type="application/json",
)
Expand All @@ -70,7 +70,7 @@ def test_no_installation(self, mock_config):
VIEW_URL,
data=data,
content_type="application/json",
HTTP_X_GEN_AI_AUTH_SIGNATURE=sig,
HTTP_HTTP_X_GEN_AI_AUTH_SIGNATURE=sig,
)

self.assertEqual(response.status_code, 200)
Expand All @@ -92,7 +92,7 @@ def test_authorized(self, mock_config):
VIEW_URL,
data=data,
content_type="application/json",
HTTP_X_GEN_AI_AUTH_SIGNATURE=sig,
HTTP_HTTP_X_GEN_AI_AUTH_SIGNATURE=sig,
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, {"is_valid": True})
Expand All @@ -114,7 +114,7 @@ def test_unauthorized(self, mock_config):
VIEW_URL,
data=data,
content_type="application/json",
HTTP_X_GEN_AI_AUTH_SIGNATURE=sig,
HTTP_HTTP_X_GEN_AI_AUTH_SIGNATURE=sig,
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, {"is_valid": False})
1 change: 1 addition & 0 deletions api/gen_ai/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def validate_signature(self, request):
if isinstance(key, str):
key = key.encode("utf-8")

Check warning on line 28 in api/gen_ai/views.py

View check run for this annotation

Codecov Notifications / codecov/patch

api/gen_ai/views.py#L28

Added line #L28 was not covered by tests
expected_sig = request.headers.get("HTTP-X-GEN-AI-AUTH-SIGNATURE")
print(request.headers)
computed_sig = (
"sha256=" + hmac.new(key, request.body, digestmod=sha256).hexdigest()
)
Expand Down

0 comments on commit da13f82

Please sign in to comment.