"""{{ display_name }} MCP server — generated by mcpify. Do not hand-edit."""

from __future__ import annotations

import base64

import pytest

from {{ module_name }}.auth.errors import MissingCredentialsError
from {{ module_name }}.auth.strategies.basic import BasicAuthStrategy


async def test_encodes_username_and_password_as_a_basic_authorization_header() -> None:
    strategy = BasicAuthStrategy()
    credentials = await strategy.authenticate({"username": "alice", "password": "s3cr3t"})
    expected = base64.b64encode(b"alice:s3cr3t").decode()
    assert credentials["authorization_header"] == f"Basic {expected}"


async def test_rejects_a_config_missing_either_field() -> None:
    strategy = BasicAuthStrategy()
    with pytest.raises(MissingCredentialsError):
        await strategy.authenticate({})


def test_validates_credentials_carrying_an_authorization_header() -> None:
    strategy = BasicAuthStrategy()
    assert strategy.validate_credentials({"authorization_header": "Basic abc"})
    assert not strategy.validate_credentials({})
