|
6 | 6 |
|
7 | 7 | import logging |
8 | 8 | from collections.abc import Callable |
| 9 | +from pathlib import Path |
9 | 10 |
|
10 | 11 | import pytest |
11 | 12 | import pytest_asyncio |
12 | 13 | import sqlalchemy as sa |
| 14 | +import yaml |
13 | 15 | from aiohttp import web |
14 | 16 | from aiohttp.test_utils import TestClient, TestServer |
15 | 17 | 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 |
151 | 153 |
|
152 | 154 | response = await client.get("/v0/auth:check") |
153 | 155 | 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