Skip to content

Commit 3c0f8e1

Browse files
committed
✨ feat(tests): Add test for forwardauth configuration in docker-compose-dev-vendors.yml
1 parent 694c3a2 commit 3c0f8e1

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

packages/pytest-simcore/src/pytest_simcore/repository_paths.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ def services_docker_compose_file(services_dir: Path) -> Path:
8585
return dcpath
8686

8787

88+
@pytest.fixture(scope="session")
89+
def services_docker_compose_dev_vendors_file(osparc_simcore_services_dir: Path) -> Path:
90+
"""Path to osparc-simcore/services/docker-compose-dev-vendors.yml file"""
91+
dcpath = osparc_simcore_services_dir / "docker-compose-dev-vendors.yml"
92+
assert dcpath.exists()
93+
return dcpath
94+
95+
8896
@pytest.fixture(scope="session")
8997
def pylintrc(osparc_simcore_root_dir: Path) -> Path:
9098
pylintrc = osparc_simcore_root_dir / ".pylintrc"

services/docker-compose-dev-vendors.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
- traefik.enable=true
1616
- traefik.swarm.network=${SWARM_STACK_NAME}_default
1717
# auth: https://doc.traefik.io/traefik/middlewares/http/forwardauth
18-
- traefik.http.middlewares.${SWARM_STACK_NAME}_manual-auth.forwardauth.address=http://${WEBSERVER_HOST}:${WEBSERVER_PORT}/v0/auth:check
18+
- traefik.http.middlewares.${SWARM_STACK_NAME}_manual-auth.forwardauth.address=http://${WB_AUTH_WEBSERVER_HOST}:${WB_AUTH_WEBSERVER_PORT}/v0/auth:check
1919
- traefik.http.middlewares.${SWARM_STACK_NAME}_manual-auth.forwardauth.trustForwardHeader=true
2020
- traefik.http.middlewares.${SWARM_STACK_NAME}_manual-auth.forwardauth.authResponseHeaders=Set-Cookie,osparc-sc2
2121
# routing

services/web/server/tests/unit/with_dbs/03/test_login_auth_app.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
import logging
88
from collections.abc import Callable
9+
from pathlib import Path
910

1011
import pytest
1112
import pytest_asyncio
1213
import sqlalchemy as sa
14+
import yaml
1315
from aiohttp import web
1416
from aiohttp.test_utils import TestClient, TestServer
1517
from pytest_simcore.helpers.assert_checks import assert_status
@@ -151,3 +153,72 @@ async def test_check_endpoint_in_auth_app(client: TestClient, user: UserInfoDict
151153

152154
response = await client.get("/v0/auth:check")
153155
await assert_status(response, status.HTTP_401_UNAUTHORIZED)
156+
157+
158+
def test_docker_compose_dev_vendors_forwardauth_configuration(
159+
services_docker_compose_dev_vendors_file: Path,
160+
app_environment_for_wb_authz_service_dict: EnvVarsDict,
161+
):
162+
"""Test that manual service forwardauth.address points to correct WB_AUTH_WEBSERVER_HOST and port."""
163+
164+
# Load docker-compose file
165+
compose_config = yaml.safe_load(
166+
services_docker_compose_dev_vendors_file.read_text()
167+
)
168+
169+
# Get the manual service configuration
170+
manual_service = compose_config.get("services", {}).get("manual")
171+
assert (
172+
manual_service is not None
173+
), "Manual service not found in docker-compose-dev-vendors.yml"
174+
175+
# Extract forwardauth.address from deploy labels
176+
deploy_labels = manual_service.get("deploy", {}).get("labels", [])
177+
forwardauth_address_label = None
178+
179+
for label in deploy_labels:
180+
if "forwardauth.address=" in label:
181+
forwardauth_address_label = label
182+
break
183+
184+
assert (
185+
forwardauth_address_label is not None
186+
), "forwardauth.address label not found in manual service"
187+
188+
# Parse the forwardauth address
189+
# Expected format: traefik.http.middlewares.${SWARM_STACK_NAME}_manual-auth.forwardauth.address=http://${WB_AUTH_WEBSERVER_HOST}:${WB_AUTH_WEBSERVER_PORT}/v0/auth:check
190+
address_part = forwardauth_address_label.split("forwardauth.address=")[1]
191+
192+
# Verify it contains the expected pattern
193+
assert (
194+
"${WB_AUTH_WEBSERVER_HOST}" in address_part
195+
), "forwardauth.address should reference WB_AUTH_WEBSERVER_HOST"
196+
assert (
197+
"${WB_AUTH_WEBSERVER_PORT}" in address_part
198+
), "forwardauth.address should reference WB_AUTH_WEBSERVER_PORT"
199+
assert (
200+
"/v0/auth:check" in address_part
201+
), "forwardauth.address should point to /v0/auth:check endpoint"
202+
203+
# Verify the full expected pattern
204+
expected_pattern = (
205+
"http://${WB_AUTH_WEBSERVER_HOST}:${WB_AUTH_WEBSERVER_PORT}/v0/auth:check"
206+
)
207+
assert (
208+
address_part == expected_pattern
209+
), f"forwardauth.address should be '{expected_pattern}', got '{address_part}'"
210+
211+
# Verify that WB_AUTH_WEBSERVER_HOST and WB_AUTH_WEBSERVER_PORT are configured in the test environment
212+
wb_auth_host = app_environment_for_wb_authz_service_dict.get(
213+
"WB_AUTH_WEBSERVER_HOST"
214+
)
215+
wb_auth_port = app_environment_for_wb_authz_service_dict.get(
216+
"WB_AUTH_WEBSERVER_PORT"
217+
)
218+
219+
assert (
220+
wb_auth_host is not None
221+
), "WB_AUTH_WEBSERVER_HOST should be configured in test environment"
222+
assert (
223+
wb_auth_port is not None
224+
), "WB_AUTH_WEBSERVER_PORT should be configured in test environment"

0 commit comments

Comments
 (0)