|
3 | 3 | import pytest
|
4 | 4 |
|
5 | 5 | from symphony.bdk.core.client.api_client_factory import ApiClientFactory
|
6 |
| -from symphony.bdk.core.config.loader import BdkConfigLoader |
7 |
| -from tests.utils.resource_utils import get_config_resource_filepath |
| 6 | +from symphony.bdk.core.config.model.bdk_config import BdkConfig |
| 7 | +from symphony.bdk.core.config.model.bdk_server_config import BdkProxyConfig |
| 8 | +from symphony.bdk.core.config.model.bdk_ssl_config import BdkSslConfig |
| 9 | + |
| 10 | +HOST = "acme.symphony.com" |
8 | 11 |
|
9 | 12 |
|
10 | 13 | @pytest.fixture()
|
11 | 14 | def config():
|
12 |
| - return BdkConfigLoader.load_from_file(get_config_resource_filepath("config.yaml")) |
| 15 | + return BdkConfig(host=HOST) |
| 16 | + |
| 17 | + |
| 18 | +@pytest.mark.asyncio |
| 19 | +async def test_host_configured(config): |
| 20 | + client_factory = ApiClientFactory(config) |
| 21 | + |
| 22 | + assert_host_configured_only(client_factory.get_pod_client().configuration, "/pod") |
| 23 | + assert_host_configured_only(client_factory.get_login_client().configuration, "/login") |
| 24 | + assert_host_configured_only(client_factory.get_agent_client().configuration, "/agent") |
| 25 | + assert_host_configured_only(client_factory.get_session_auth_client().configuration, "/sessionauth") |
| 26 | + assert_host_configured_only(client_factory.get_relay_client().configuration, "/relay") |
| 27 | + |
| 28 | + |
| 29 | +@pytest.mark.asyncio |
| 30 | +async def test_proxy_configured(config): |
| 31 | + proxy_host = "proxy.com" |
| 32 | + proxy_port = 1234 |
| 33 | + config.proxy = BdkProxyConfig(proxy_host, proxy_port) |
| 34 | + client_factory = ApiClientFactory(config) |
| 35 | + |
| 36 | + assert_host_and_proxy_configured(client_factory.get_pod_client().configuration, "/pod", proxy_host, proxy_port) |
| 37 | + assert_host_and_proxy_configured(client_factory.get_login_client().configuration, "/login", proxy_host, proxy_port) |
| 38 | + assert_host_and_proxy_configured(client_factory.get_agent_client().configuration, "/agent", proxy_host, proxy_port) |
| 39 | + assert_host_and_proxy_configured(client_factory.get_session_auth_client().configuration, "/sessionauth", proxy_host, |
| 40 | + proxy_port) |
| 41 | + assert_host_and_proxy_configured(client_factory.get_relay_client().configuration, "/relay", proxy_host, proxy_port) |
| 42 | + |
| 43 | + |
| 44 | +@pytest.mark.asyncio |
| 45 | +async def test_proxy_credentials_configured(config): |
| 46 | + proxy_host = "proxy.com" |
| 47 | + proxy_port = 1234 |
| 48 | + config.proxy = BdkProxyConfig(proxy_host, proxy_port, "user", "pass") |
| 49 | + client_factory = ApiClientFactory(config) |
| 50 | + |
| 51 | + assert_host_and_proxy_credentials_configured(client_factory.get_pod_client().configuration, "/pod", proxy_host, |
| 52 | + proxy_port) |
| 53 | + assert_host_and_proxy_credentials_configured(client_factory.get_login_client().configuration, "/login", proxy_host, |
| 54 | + proxy_port) |
| 55 | + assert_host_and_proxy_credentials_configured(client_factory.get_agent_client().configuration, "/agent", proxy_host, |
| 56 | + proxy_port) |
| 57 | + assert_host_and_proxy_credentials_configured(client_factory.get_session_auth_client().configuration, "/sessionauth", |
| 58 | + proxy_host, |
| 59 | + proxy_port) |
| 60 | + assert_host_and_proxy_credentials_configured(client_factory.get_relay_client().configuration, "/relay", proxy_host, |
| 61 | + proxy_port) |
| 62 | + |
| 63 | + |
| 64 | +def test_trust_store_configured(config): |
| 65 | + with patch("symphony.bdk.gen.rest.RESTClientObject"): |
| 66 | + truststore_path = "/path/to/truststore.pem" |
| 67 | + config.ssl = BdkSslConfig({"trustStore": {"path": truststore_path}}) |
| 68 | + |
| 69 | + client_factory = ApiClientFactory(config) |
| 70 | + |
| 71 | + assert client_factory.get_pod_client().configuration.ssl_ca_cert == truststore_path |
| 72 | + |
| 73 | + |
| 74 | +def assert_host_configured_only(configuration, url_suffix): |
| 75 | + assert configuration.host == f"https://{HOST}:443{url_suffix}" |
| 76 | + assert configuration.proxy is None |
| 77 | + assert configuration.proxy_headers is None |
| 78 | + |
| 79 | + |
| 80 | +def assert_host_and_proxy_configured(configuration, url_suffix, proxy_host, proxy_port): |
| 81 | + assert configuration.host == f"https://{HOST}:443{url_suffix}" |
| 82 | + assert configuration.proxy == f"http://{proxy_host}:{proxy_port}" |
| 83 | + assert configuration.proxy_headers is None |
13 | 84 |
|
14 | 85 |
|
15 |
| -def test_get_api_client(config): |
16 |
| - with patch('symphony.bdk.core.client.api_client_factory.ApiClient', autospec=True): |
17 |
| - api_client_factory = ApiClientFactory(config) |
18 |
| - assert api_client_factory.get_pod_client() is not None |
19 |
| - assert api_client_factory.get_login_client() is not None |
20 |
| - assert api_client_factory.get_agent_client() is not None |
21 |
| - assert api_client_factory.get_session_auth_client() is not None |
22 |
| - assert api_client_factory.get_relay_client() is not None |
| 86 | +def assert_host_and_proxy_credentials_configured(configuration, url_suffix, proxy_host, proxy_port): |
| 87 | + assert configuration.host == f"https://{HOST}:443{url_suffix}" |
| 88 | + assert configuration.proxy == f"http://{proxy_host}:{proxy_port}" |
| 89 | + assert "proxy-authorization" in configuration.proxy_headers |
0 commit comments