"""Tests for STS stub routes."""

from __future__ import annotations

import httpx
import pytest

from lws.providers.sts.routes import create_sts_app


class TestStsRoutes:
    """Test STS HTTP wire protocol routes."""

    @pytest.fixture
    def client(self):
        app = create_sts_app()
        transport = httpx.ASGITransport(app=app)
        return httpx.AsyncClient(transport=transport, base_url="http://testserver")

    @pytest.mark.asyncio
    async def test_get_caller_identity(self, client) -> None:
        resp = await client.post(
            "/",
            data={"Action": "GetCallerIdentity"},
        )

        # Assert
        expected_status = 200
        expected_account = "000000000000"
        assert resp.status_code == expected_status
        assert "<GetCallerIdentityResponse" in resp.text
        assert f"<Account>{expected_account}</Account>" in resp.text
        assert "<Arn>" in resp.text
        assert "<UserId>" in resp.text

    @pytest.mark.asyncio
    async def test_unknown_action_returns_error(self, client) -> None:
        action_name = "GetSessionToken"
        resp = await client.post(
            "/",
            data={"Action": action_name},
        )

        # Assert
        expected_status = 400
        assert resp.status_code == expected_status
        assert "<ErrorResponse>" in resp.text
        assert "<Code>InvalidAction</Code>" in resp.text
        assert "lws" in resp.text
        assert "STS" in resp.text
        assert action_name in resp.text
