"""Fixtures for integration tests using jwtauth[testing].""" from dataclasses import dataclass from typing import Callable import pytest from jwtauth.testing import JwtAuthSecretsManager, SecretLookupInfo # Register the jwtauth pytest plugin for JWT token generation pytest_plugins = ['jwtauth.testing.pytest_plugin'] # Service name for AWS Secrets Manager lookups SERVICE_NAME = 'ows-account-integration-test' # Secret names in AWS Secrets Manager for user credentials OWS_ACCOUNT_TEST_USER_CREDENTIALS = 'OWS_ACCOUNT_TEST_USER_CREDENTIALS' OWS_PERMISSIONS_TEST_USER_CREDENTIALS = 'OWS_PERMISSIONS_TEST_USER_CREDENTIALS' AWAL_CONTRACT_ADMIN_CREDENTIALS = 'AWAL_CONTRACT_ADMIN_USER_CREDENTIALS' KNR_CONTRACT_ADMIN_CREDENTIALS = 'KNR_CONTRACT_ADMIN_USER_CREDENTIALS' ALTAFONTE_CONTRACT_ADMIN_CREDENTIALS = 'ALTAFONTE_CONTRACT_ADMIN_USER_CREDENTIALS' SME_CONTRACT_ADMIN_CREDENTIALS = 'SME_CONTRACT_ADMIN_USER_CREDENTIALS' THEORCHARD_CONTRACT_ADMIN_CREDENTIALS = 'THEORCHARD_CONTRACT_ADMIN_USER_CREDENTIALS' THEORCHARD_ACCOUNT_ADMIN_CREDENTIALS = 'THEORCHARD_ACCOUNT_ADMIN_USER_CREDENTIALS' ACCOUNT360_TEST_USER_CREDENTIALS = 'ACCOUNT360_TEST_USER_CREDENTIALS' SEAT_ADMIN_CREDENTIALS = 'OWS_ACCOUNT_TEST_SEAT_USER_CREDENTIALS' # Secret names in AWS Secrets Manager for Auth0 app credentials SETTINGS_AUTH0_APP_CREDENTIALS = 'SETTINGS_AUTH0_APP_CREDENTIALS' ACCOUNT360_AUTH0_APP_CREDENTIALS = 'ACCOUNT360_AUTH0_APP_CREDENTIALS' SEAT_AUTH0_APP_CREDENTIALS = 'SEAT_AUTH0_APP_CREDENTIALS' # Environment QA_ENVIRONMENT = 'qa' @dataclass class ProfileInfo: """Holds profile info.""" identity_id: str profile_id: int profile_type: str # ===================================== # JWT Token Fixtures (using jwtauth) # ===================================== @pytest.fixture(scope='session') def bearer_token_with_vendor_star( generate_bearer_token: Callable, jwtauth_secrets_manager: JwtAuthSecretsManager, ) -> str: """Return a JWT for the ows-account integration test user with Vendor * access.""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=OWS_ACCOUNT_TEST_USER_CREDENTIALS, ), get_auth0_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=SETTINGS_AUTH0_APP_CREDENTIALS, ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture(scope='session') def bearer_token_without_vendor_star( generate_bearer_token: Callable, jwtauth_secrets_manager: JwtAuthSecretsManager, ) -> str: """Return a JWT for the ows-permissions user without Vendor * access.""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=OWS_PERMISSIONS_TEST_USER_CREDENTIALS, ), get_auth0_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=SETTINGS_AUTH0_APP_CREDENTIALS, ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture(scope='session') def bearer_token_contract_admin_awal( generate_bearer_token: Callable, jwtauth_secrets_manager: JwtAuthSecretsManager, ) -> str: """Return a JWT for contract_admin identity for awal company_brand.""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=AWAL_CONTRACT_ADMIN_CREDENTIALS, ), get_auth0_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=SETTINGS_AUTH0_APP_CREDENTIALS, ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture(scope='session') def bearer_token_contract_admin_knr( generate_bearer_token: Callable, jwtauth_secrets_manager: JwtAuthSecretsManager, ) -> str: """Return a JWT for contract_admin identity for knr company_brand.""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=KNR_CONTRACT_ADMIN_CREDENTIALS, ), get_auth0_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=SETTINGS_AUTH0_APP_CREDENTIALS, ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture(scope='session') def bearer_token_contract_admin_altafonte( generate_bearer_token: Callable, jwtauth_secrets_manager: JwtAuthSecretsManager, ) -> str: """Return a JWT for contract_admin identity for altafonte company_brand.""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=ALTAFONTE_CONTRACT_ADMIN_CREDENTIALS, ), get_auth0_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=SETTINGS_AUTH0_APP_CREDENTIALS, ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture(scope='session') def bearer_token_contract_admin_sme( generate_bearer_token: Callable, jwtauth_secrets_manager: JwtAuthSecretsManager, ) -> str: """Return a JWT for contract_admin identity for sme company_brand.""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=SME_CONTRACT_ADMIN_CREDENTIALS, ), get_auth0_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=SETTINGS_AUTH0_APP_CREDENTIALS, ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture(scope='session') def bearer_token_contract_admin_theorchard( generate_bearer_token: Callable, jwtauth_secrets_manager: JwtAuthSecretsManager, ) -> str: """Return a JWT for contract_admin identity for theorchard company_brand. This user has access to contract_admin roles on all orchard company_brands: theorchard, hrs, msk, ab, drm, ma """ return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=THEORCHARD_CONTRACT_ADMIN_CREDENTIALS, ), get_auth0_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=SETTINGS_AUTH0_APP_CREDENTIALS, ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture(scope='session') def bearer_token_account_admin_theorchard( generate_bearer_token: Callable, jwtauth_secrets_manager: JwtAuthSecretsManager, ) -> str: """Return a JWT for account_admin identity for theorchard parent_company. This user has access to account_admin role on all orchard company_brands: theorchard, hrs, msk, ab, drm, ma """ return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=THEORCHARD_ACCOUNT_ADMIN_CREDENTIALS, ), get_auth0_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=SETTINGS_AUTH0_APP_CREDENTIALS, ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture(scope='session') def bearer_token_account360_user( generate_bearer_token: Callable, jwtauth_secrets_manager: JwtAuthSecretsManager, ) -> str: """Return a JWT for account360 user.""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=ACCOUNT360_TEST_USER_CREDENTIALS, ), get_auth0_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=ACCOUNT360_AUTH0_APP_CREDENTIALS, ), secrets_manager=jwtauth_secrets_manager, ) @pytest.fixture(scope='session') def bearer_token_seat_admin( generate_bearer_token: Callable, jwtauth_secrets_manager: JwtAuthSecretsManager, ) -> str: """Return a JWT for SEAT admin user with seat_can_administer_users role.""" return generate_bearer_token( get_user_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=SEAT_ADMIN_CREDENTIALS, ), get_auth0_creds_args=SecretLookupInfo( environment=QA_ENVIRONMENT, service_name=SERVICE_NAME, secret_name=SETTINGS_AUTH0_APP_CREDENTIALS, ), secrets_manager=jwtauth_secrets_manager, ) # ===================================== # Profile Info Fixtures # ===================================== @pytest.fixture(scope='session') def settings_e2e_user_label_profile() -> ProfileInfo: """LabelProfile for settings-e2e-test without Vendor * access.""" return ProfileInfo( identity_id='cabc0fe4-0cbf-4ce1-b750-130f22bcd8d7', profile_id=60836, profile_type='LabelProfile', ) @pytest.fixture(scope='session') def settings_e2e_user_audience_profile() -> ProfileInfo: """AudienceProfile for settings-e2e-test with Vendor * access.""" return ProfileInfo( identity_id='cabc0fe4-0cbf-4ce1-b750-130f22bcd8d7', profile_id=319021, profile_type='AudienceProfile', ) @pytest.fixture(scope='session') def ows_account_test_user_label_profile() -> ProfileInfo: """LabelProfile for ows-account-integration-test, Settings has Vendor *""" return ProfileInfo( identity_id='40210960-c0e6-47c7-bb49-71f2373260dd', profile_id=10017354, profile_type='LabelProfile', ) @pytest.fixture(scope='session') def ows_account_test_user_settings_profile() -> ProfileInfo: """SettingsProfile for ows-account-integration-test with Vendor * access.""" return ProfileInfo( identity_id='40210960-c0e6-47c7-bb49-71f2373260dd', profile_id=465788, profile_type='SettingsProfile', ) @pytest.fixture(scope='session') def ows_account_test_user_abacus_profile() -> ProfileInfo: """AbacusProfile for ows-account-integration-test with Vendor * access.""" return ProfileInfo( identity_id='40210960-c0e6-47c7-bb49-71f2373260dd', profile_id=95101924, profile_type='AbacusProfile', ) @pytest.fixture(scope='session') def ows_account_test_user_account360_profile() -> ProfileInfo: """Account360Profile for ows-account-integration-test-account360profile@sonymusic-pde.com.""" return ProfileInfo( identity_id='0d6eb9b7-e65e-423c-a635-f09f7745ad65', profile_id=99000014, profile_type='Account360Profile', ) @pytest.fixture(scope='session') def ows_permissions_test_user_settings_profile() -> ProfileInfo: """SettingsProfile for ows-permissions-integration-test without Vendor * access.""" return ProfileInfo( identity_id='d0e55c65-9dae-4d91-b409-677854806272', profile_id=467615, profile_type='SettingsProfile', ) @pytest.fixture(scope='session') def ows_permissions_test_user_label_profile() -> ProfileInfo: """LabelProfile for ows-permissions-integration-test without Vendor * access.""" return ProfileInfo( identity_id='d0e55c65-9dae-4d91-b409-677854806272', profile_id=10018137, profile_type='LabelProfile', ) @pytest.fixture(scope='session') def orchard_permissions_test_user_label_profile() -> ProfileInfo: """LabelProfile for ows-permissions-integration-test without Vendor * access.""" return ProfileInfo( identity_id='510b0265-e6e1-4c4f-bfb9-c3d33e8f02a7', profile_id=1557, profile_type='OrchAdminProfile', ) @pytest.fixture(scope='session') def moneyhub_test_user_profile() -> ProfileInfo: """MoneyhubProfile with accounting role.""" return ProfileInfo( identity_id='99ace606-8acb-413f-8d65-6fb7be194411', profile_id=677134, profile_type='MoneyhubProfile', )