|
7 | 7 | import pytest |
8 | 8 |
|
9 | 9 | from homeassistant.core import HomeAssistant |
| 10 | +from homeassistant.core_config import async_process_ha_core_config |
10 | 11 |
|
11 | 12 | from . import BASE_CONFIG, async_setup_auth |
12 | 13 |
|
@@ -371,19 +372,54 @@ async def test_login_exist_user_ip_changes( |
371 | 372 | assert response == {"message": "IP address changed"} |
372 | 373 |
|
373 | 374 |
|
| 375 | +@pytest.mark.usefixtures("current_request_with_host") # Has example.com host |
| 376 | +@pytest.mark.parametrize( |
| 377 | + ("config", "expected_url_prefix"), |
| 378 | + [ |
| 379 | + ( |
| 380 | + { |
| 381 | + "internal_url": "http://192.168.1.100:8123", |
| 382 | + # Current request matches external url |
| 383 | + "external_url": "https://example.com", |
| 384 | + }, |
| 385 | + "https://example.com", |
| 386 | + ), |
| 387 | + ( |
| 388 | + { |
| 389 | + # Current request matches internal url |
| 390 | + "internal_url": "https://example.com", |
| 391 | + "external_url": "https://other.com", |
| 392 | + }, |
| 393 | + "https://example.com", |
| 394 | + ), |
| 395 | + ( |
| 396 | + { |
| 397 | + # Current request does not match either url |
| 398 | + "internal_url": "https://other.com", |
| 399 | + "external_url": "https://again.com", |
| 400 | + }, |
| 401 | + "", |
| 402 | + ), |
| 403 | + ], |
| 404 | + ids=["external_url", "internal_url", "no_match"], |
| 405 | +) |
374 | 406 | async def test_well_known_auth_info( |
375 | | - hass: HomeAssistant, aiohttp_client: ClientSessionGenerator |
| 407 | + hass: HomeAssistant, |
| 408 | + aiohttp_client: ClientSessionGenerator, |
| 409 | + config: dict[str, str], |
| 410 | + expected_url_prefix: str, |
376 | 411 | ) -> None: |
377 | | - """Test logging in and the ip address changes results in an rejection.""" |
| 412 | + """Test the well-known OAuth authorization server endpoint with different URL configurations.""" |
| 413 | + await async_process_ha_core_config(hass, config) |
378 | 414 | client = await async_setup_auth(hass, aiohttp_client, setup_api=True) |
379 | 415 | resp = await client.get( |
380 | 416 | "/.well-known/oauth-authorization-server", |
381 | 417 | ) |
382 | 418 | assert resp.status == 200 |
383 | 419 | assert await resp.json() == { |
384 | | - "authorization_endpoint": "/auth/authorize", |
385 | | - "token_endpoint": "/auth/token", |
386 | | - "revocation_endpoint": "/auth/revoke", |
| 420 | + "authorization_endpoint": f"{expected_url_prefix}/auth/authorize", |
| 421 | + "token_endpoint": f"{expected_url_prefix}/auth/token", |
| 422 | + "revocation_endpoint": f"{expected_url_prefix}/auth/revoke", |
387 | 423 | "response_types_supported": ["code"], |
388 | 424 | "service_documentation": "https://developers.home-assistant.io/docs/auth_api", |
389 | 425 | } |
0 commit comments