Skip to content

Commit 8f821d4

Browse files
committed
fix tests 3 (ssl test context + httpcore dependency for backend)
1 parent 32e4d24 commit 8f821d4

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

backend/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ exceptiongroup==1.2.2
1616
fastapi==0.115.12
1717
google-auth==2.35.0
1818
greenlet==3.1.1
19+
httpcore==1.0.9
1920
h11==0.16.0
2021
idna==3.10
2122
importlib_metadata==8.5.0

backend/tests/conftest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
import pathlib
2+
import ssl
23
from typing import AsyncGenerator, Optional
34

45
import httpx
56
import pytest
67
from app.config import Settings
78
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase
89

10+
11+
def create_test_ssl_context() -> ssl.SSLContext:
12+
context = ssl.create_default_context()
13+
context.check_hostname = False
14+
context.verify_mode = ssl.CERT_NONE
15+
return context
16+
917
ENV_FILE_PATH = pathlib.Path(__file__).parent / '.env.test'
1018

1119
@pytest.fixture(scope="function")
1220
async def client() -> AsyncGenerator[httpx.AsyncClient, None]:
1321
backend_service_url = "https://localhost:443"
1422
async with httpx.AsyncClient(
1523
base_url=backend_service_url,
16-
verify=False,
24+
verify=create_test_ssl_context(),
1725
timeout=30.0
1826
) as async_client:
1927
try:

backend/tests/integration/test_auth_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from app.schemas.user import UserCreate
55
from httpx import AsyncClient
66
from motor.motor_asyncio import AsyncIOMotorDatabase
7+
from tests.conftest import create_test_ssl_context
78

89

910
@pytest.mark.integration
@@ -119,7 +120,7 @@ async def test_verify_token_invalid_token(self) -> None:
119120
"""Verify an invalid/malformed token fails."""
120121
async with httpx.AsyncClient(
121122
base_url="https://localhost:443",
122-
verify=False,
123+
verify=create_test_ssl_context(),
123124
timeout=30.0
124125
) as new_client:
125126
response = await new_client.get("/api/v1/verify-token")
@@ -130,7 +131,7 @@ async def test_verify_token_no_token(self) -> None:
130131
"""Verify request fails without token."""
131132
async with httpx.AsyncClient(
132133
base_url="https://localhost:443",
133-
verify=False,
134+
verify=create_test_ssl_context(),
134135
timeout=30.0
135136
) as new_client:
136137
response = await new_client.get("/api/v1/verify-token")

backend/tests/integration/test_execution_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from app.schemas.user import UserCreate
66
from httpx import AsyncClient, HTTPStatusError
77
from motor.motor_asyncio import AsyncIOMotorDatabase
8+
from tests.conftest import create_test_ssl_context
89

910
POLL_INTERVAL = 2 # seconds
1011
EXECUTION_TIMEOUT = 120 # seconds
@@ -147,7 +148,7 @@ async def test_execute_endpoint_without_auth(self) -> None:
147148
"""Test accessing execute endpoint without authentication (should succeed)."""
148149
async with httpx.AsyncClient(
149150
base_url="https://localhost:443",
150-
verify=False,
151+
verify=create_test_ssl_context(),
151152
timeout=30.0
152153
) as new_client:
153154
execution_request = {"script": "print('no auth test should pass')"}
@@ -163,7 +164,7 @@ async def test_result_endpoint_without_auth(self) -> None:
163164
import httpx
164165
async with httpx.AsyncClient(
165166
base_url="https://localhost:443",
166-
verify=False,
167+
verify=create_test_ssl_context(),
167168
timeout=30.0
168169
) as new_client:
169170
non_existent_id = "nonexistent-public-id-999"

backend/tests/integration/test_saved_scripts_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from app.schemas.user import UserCreate
55
from httpx import AsyncClient
66
from motor.motor_asyncio import AsyncIOMotorDatabase
7+
from tests.conftest import create_test_ssl_context
78

89

910
@pytest.mark.integration
@@ -134,7 +135,7 @@ async def test_scripts_endpoints_without_auth(self) -> None:
134135
"""Test accessing scripts endpoints without authentication."""
135136
async with httpx.AsyncClient(
136137
base_url="https://localhost:443",
137-
verify=False,
138+
verify=create_test_ssl_context(),
138139
timeout=30.0
139140
) as new_client:
140141
script_data = {"name": "No Auth", "script": "print('no')"}

0 commit comments

Comments
 (0)