"""Integration test configuration.""" import os from typing import Any from pytest import fixture from tests.integration.consts import headers from tests.integration.utils import auth from tests.integration.utils.ows_store_api_client import OwsStoreAPIClient QA_BASE_URL = os.environ["QA_BASE_URL"] @fixture def basic_headers() -> dict[str, str]: """Return basic headers.""" return {"Content-Type": "application/json"} def ows_store_api_client(basic_headers: dict[str, str]) -> OwsStoreAPIClient: """Create ows-store client.""" return OwsStoreAPIClient(QA_BASE_URL, basic_headers) @fixture(scope="session") def bearer_token_read_only_user() -> str: """Fetch Auth0 secrets from AWS Secret Manager.""" login_secrets = auth.login_from_secrets_manager( password_secret_name=auth.READONLY_USER_PASSWORD_SECRET_NAME, auth_client_id_secret_name=auth.AUTH0_CLIENT_ID_SECRET_NAME, auth_client_secret_secret_name=auth.AUTH0_CLIENT_SECRET_SECRET_NAME, ) token = auth.generate_auth_token( auth.LoginInfo( auth_client_id=login_secrets.auth_client_id, auth_client_secret=login_secrets.auth_client_secret, password=login_secrets.password, username=auth.READONLY_USER, ) ) return token @fixture(scope="session") def admin_headers() -> dict[str, str]: """Return profile headers.""" return headers.ADMIN_HEADERS @fixture(params=["read_only", "admin"], scope="session") def auth_headers( request: Any, bearer_token_read_only_user: str, admin_headers: dict[str, str] ) -> dict[str, str]: """Return appropriate headers based on the parameter.""" if request.param == "read_only": return { "Authorization": f"Bearer {bearer_token_read_only_user}", "Content-Type": "application/json", "Orchard-Identity-Id": "ff3737b4-7734-4339-9798-5ddd1c9998b0", "Orchard-Profile-Id": "1005", "Orchard-Profile-Type": "Account360Profile", "Orchard-Requestor-Service": "graphql-abacus", "Orchard-Roles": "account360", } else: return admin_headers @fixture() def unauthorized_headers( bearer_token_read_only_user_unauthorized: str, ) -> dict[str, str]: """Return headers for unauthorized user.""" return { "Authorization": f"Bearer {bearer_token_read_only_user_unauthorized}", "Orchard-Requestor-Service": "graphql-abacus", } @fixture(scope="session") def bearer_token_read_only_user_unauthorized() -> str: """Fetch Auth0 secrets from AWS Secret Manager.""" login_secrets = auth.login_from_secrets_manager( password_secret_name=auth.READONLY_USER_PASSWORD_SECRET_NAME, auth_client_id_secret_name=auth.AUTH0_CLIENT_ID_SECRET_NAME, auth_client_secret_secret_name=auth.AUTH0_CLIENT_SECRET_SECRET_NAME, ) token = auth.generate_auth_token( auth.LoginInfo( auth_client_id=login_secrets.auth_client_id, auth_client_secret=login_secrets.auth_client_secret, password=login_secrets.password, username=auth.READONLY_USER_UNAUTHORIZED, ) ) return token