async def test_x_trace_id_in_default_headers(config, add_x_trace_id): default_headers = {"x-trace-id": "trace-id"} config.default_headers = default_headers with patch("symphony.bdk.core.client.api_client_factory.add_x_trace_id", return_value=add_x_trace_id) as mock: client_factory = ApiClientFactory(config) mock.assert_not_called() assert_default_headers(client_factory.get_pod_client().default_headers, default_headers) assert_default_headers( client_factory.get_login_client().default_headers, default_headers) assert_default_headers( client_factory.get_agent_client().default_headers, default_headers) assert_default_headers( client_factory.get_session_auth_client().default_headers, default_headers) assert_default_headers( client_factory.get_key_auth_client().default_headers, default_headers) assert_default_headers( client_factory.get_app_session_auth_client().default_headers, default_headers) assert_default_headers( client_factory.get_relay_client().default_headers, default_headers)
async def test_client_cert_not_configured(config): client_factory = ApiClientFactory(config) assert client_factory.get_session_auth_client( ).configuration.cert_file is None assert client_factory.get_key_auth_client().configuration.cert_file is None assert client_factory.get_app_session_auth_client( ).configuration.cert_file is None
async def test_client_cert_configured_for_bot(client_certificate_path, config): config.bot.certificate.path = client_certificate_path client_factory = ApiClientFactory(config) assert client_factory.get_session_auth_client( ).configuration.cert_file == client_certificate_path assert client_factory.get_key_auth_client( ).configuration.cert_file == client_certificate_path
async def test_client_cert_configured_for_bot(config): client_cert_path = get_resource_filepath("cert/megabot.pem", as_text=True) config.bot.certificate.path = client_cert_path client_factory = ApiClientFactory(config) assert client_factory.get_session_auth_client( ).configuration.cert_file == client_cert_path assert client_factory.get_key_auth_client( ).configuration.cert_file == client_cert_path
async def test_host_configured(config): client_factory = ApiClientFactory(config) assert_host_configured_only(client_factory.get_pod_client(), POD) assert_host_configured_only(client_factory.get_login_client(), LOGIN) assert_host_configured_only(client_factory.get_agent_client(), AGENT) assert_host_configured_only(client_factory.get_session_auth_client(), SESSION_AUTH) assert_host_configured_only(client_factory.get_key_auth_client(), KEY_AUTH) assert_host_configured_only(client_factory.get_app_session_auth_client(), SESSION_AUTH) assert_host_configured_only(client_factory.get_relay_client(), RELAY)
async def test_global_user_agent_configured(config): custom_user_agent = "custom-user-agent" config.default_headers = {"user-agent": custom_user_agent} client_factory = ApiClientFactory(config) assert client_factory.get_pod_client().user_agent == custom_user_agent assert client_factory.get_login_client().user_agent == custom_user_agent assert client_factory.get_agent_client().user_agent == custom_user_agent assert client_factory.get_session_auth_client( ).user_agent == custom_user_agent assert client_factory.get_key_auth_client().user_agent == custom_user_agent assert client_factory.get_app_session_auth_client( ).user_agent == custom_user_agent assert client_factory.get_relay_client().user_agent == custom_user_agent
async def test_default_headers_at_km_level(config): default_headers = {"header_name": "header_value"} config.key_manager._default_headers = default_headers client_factory = ApiClientFactory(config) assert_default_headers(client_factory.get_pod_client().default_headers, {}) assert_default_headers(client_factory.get_login_client().default_headers, {}) assert_default_headers(client_factory.get_agent_client().default_headers, {}) assert_default_headers( client_factory.get_session_auth_client().default_headers, {}) assert_default_headers( client_factory.get_key_auth_client().default_headers, default_headers) assert_default_headers( client_factory.get_app_session_auth_client().default_headers, {}) assert_default_headers(client_factory.get_relay_client().default_headers, default_headers)
async def test_x_trace_id_not_in_default_headers(config, add_x_trace_id): with patch("symphony.bdk.core.client.api_client_factory.add_x_trace_id", return_value=add_x_trace_id) as mock: client_factory = ApiClientFactory(config) assert mock.call_count == 7 assert_default_headers(client_factory.get_pod_client().default_headers, {}) assert_default_headers( client_factory.get_login_client().default_headers, {}) assert_default_headers( client_factory.get_agent_client().default_headers, {}) assert_default_headers( client_factory.get_session_auth_client().default_headers, {}) assert_default_headers( client_factory.get_key_auth_client().default_headers, {}) assert_default_headers( client_factory.get_app_session_auth_client().default_headers, {}) assert_default_headers( client_factory.get_relay_client().default_headers, {})
async def test_proxy_configured(config): proxy_host = "proxy.com" proxy_port = 1234 config.proxy = BdkProxyConfig(proxy_host, proxy_port) client_factory = ApiClientFactory(config) assert_host_and_proxy_configured(client_factory.get_pod_client(), POD, proxy_host, proxy_port) assert_host_and_proxy_configured(client_factory.get_login_client(), LOGIN, proxy_host, proxy_port) assert_host_and_proxy_configured(client_factory.get_agent_client(), AGENT, proxy_host, proxy_port) assert_host_and_proxy_configured(client_factory.get_session_auth_client(), SESSION_AUTH, proxy_host, proxy_port) assert_host_and_proxy_configured(client_factory.get_key_auth_client(), KEY_AUTH, proxy_host, proxy_port) assert_host_and_proxy_configured( client_factory.get_app_session_auth_client(), SESSION_AUTH, proxy_host, proxy_port) assert_host_and_proxy_configured(client_factory.get_relay_client(), RELAY, proxy_host, proxy_port)
async def test_global_default_headers(config): config.default_headers = {"header_name": "header_value"} client_factory = ApiClientFactory(config) assert_default_headers(client_factory.get_pod_client().default_headers, config.default_headers) assert_default_headers(client_factory.get_login_client().default_headers, config.default_headers) assert_default_headers(client_factory.get_agent_client().default_headers, config.default_headers) assert_default_headers( client_factory.get_session_auth_client().default_headers, config.default_headers) assert_default_headers( client_factory.get_key_auth_client().default_headers, config.default_headers) assert_default_headers( client_factory.get_app_session_auth_client().default_headers, config.default_headers) assert_default_headers(client_factory.get_relay_client().default_headers, config.default_headers)