|
18 | 18 | from test.fixtures import get_client_auth_manager_scoped as client_auth_manager_scoped # NOQA |
19 | 19 | from test.fixtures import get_service_principal_auth_manager as service_principal_auth_manager # NOQA |
20 | 20 | from splunk_sdk.common.context import Context |
21 | | -from splunk_sdk.base_client import BaseClient |
| 21 | +from splunk_sdk.base_client import BaseClient, build_url |
22 | 22 | from splunk_sdk.identity import Identity as IdentityAndAccessControl |
23 | 23 |
|
24 | 24 | @pytest.mark.usefixtures("pkce_auth_manager") # NOQA |
@@ -193,3 +193,33 @@ def test_base_client_instance_with_sp_auth(service_principal_auth_manager): |
193 | 193 | assert (default_config is not None) |
194 | 194 | assert (base_client is not None) |
195 | 195 | _assert_sp_credentials_auth_context(base_client.auth_manager.context) |
| 196 | + |
| 197 | + |
| 198 | +def test_build_url(): |
| 199 | + # normal tenant |
| 200 | + context = Context(host="test.splunk.com", tenant="tttt", tenant_scoped=True, scheme="http") |
| 201 | + assert ("http://tttt.test.splunk.com/tttt/v2/test" == build_url(context, "/v2/test", True)) |
| 202 | + context = Context(host="test.splunk.com", tenant="tttt", tenant_scoped=False, port=9999) |
| 203 | + assert ("test.splunk.com:9999/tttt/v2/test" == build_url(context, "v2/test", False)) |
| 204 | + context = Context(host="test.splunk.com", tenant="tttt", tenant_scoped=False, port=9999) |
| 205 | + assert ("test.splunk.com:9999/v2/test" == build_url(context, "v2/test", False, True)) |
| 206 | + # system tenant |
| 207 | + context = Context(host="test.splunk.com", tenant="system", tenant_scoped=True, region="iad10") |
| 208 | + assert ("region-iad10.test.splunk.com/system/v2/test" == build_url(context, "/v2/test")) |
| 209 | + context = Context(host="test.splunk.com", tenant="system", tenant_scoped=False) |
| 210 | + assert ("test.splunk.com/system/v2/test" == build_url(context, "v2/test")) |
| 211 | + context = Context(host="test.splunk.com", tenant="system", tenant_scoped=False) |
| 212 | + assert ("https://test.splunk.com/system/v2/test" == build_url(context, "v2/test", True)) |
| 213 | + context = Context(host="test.splunk.com", tenant="system", tenant_scoped=False) |
| 214 | + assert ("https://test.splunk.com/system/v2/test" == build_url(context, "v2/test", True, True)) |
| 215 | + # input sanity test |
| 216 | + context = Context(host=" test.splunk.com ", tenant=" system ", tenant_scoped=True, region=" iad10 ") |
| 217 | + assert ("region-iad10.test.splunk.com/system/v2/test" == build_url(context, " v2/test ")) |
| 218 | + with pytest.raises(ValueError): |
| 219 | + build_url(Context(host=None, tenant="system", tenant_scoped=False), "v2/test") |
| 220 | + with pytest.raises(ValueError): |
| 221 | + build_url(Context(tenant=" ", tenant_scoped=True), "v2/test") |
| 222 | + with pytest.raises(ValueError): |
| 223 | + build_url(Context(tenant_scoped=True), "v2/test") |
| 224 | + with pytest.raises(ValueError): |
| 225 | + build_url(Context(tenant_scoped=True, scheme=""), "v2/test", True) |
0 commit comments