|
10 | 10 | MutuallyExclusiveArgumentError, |
11 | 11 | RequiredArgumentMissingError, |
12 | 12 | ) |
13 | | -from azext_iot.core.custom import _resolve_linked_hub_hostname |
| 13 | +from azext_iot.core.custom import _resolve_linked_hub_hostname, _warn_mixed_endpoint_types |
14 | 14 |
|
15 | 15 |
|
16 | 16 | class TestResolveLinkedHubHostname: |
17 | 17 | def test_device_with_tls13(self): |
18 | 18 | hub = {"properties": {"deviceHostName": "hub.device.azure-devices.net", "hostName": "hub.azure-devices.net"}} |
19 | 19 | assert _resolve_linked_hub_hostname(hub, "device") == "hub.device.azure-devices.net" |
20 | 20 |
|
21 | | - def test_device_fallback_to_classic(self): |
| 21 | + def test_device_errors_on_v1_hub(self): |
| 22 | + hub = {"properties": {"hostName": "hub.azure-devices.net"}, "name": "hub"} |
| 23 | + with pytest.raises(InvalidArgumentValueError, match="device hostname is not available"): |
| 24 | + _resolve_linked_hub_hostname(hub, "device") |
| 25 | + |
| 26 | + def test_auto_fallback_to_classic(self): |
22 | 27 | hub = {"properties": {"hostName": "hub.azure-devices.net"}} |
23 | | - assert _resolve_linked_hub_hostname(hub, "device") == "hub.azure-devices.net" |
| 28 | + assert _resolve_linked_hub_hostname(hub, "auto") == "hub.azure-devices.net" |
| 29 | + |
| 30 | + def test_auto_uses_device_when_available(self): |
| 31 | + hub = {"properties": {"deviceHostName": "hub.device.azure-devices.net", "hostName": "hub.azure-devices.net"}} |
| 32 | + assert _resolve_linked_hub_hostname(hub, "auto") == "hub.device.azure-devices.net" |
24 | 33 |
|
25 | 34 | def test_classic(self): |
26 | 35 | hub = {"properties": {"deviceHostName": "hub.device.azure-devices.net", "hostName": "hub.azure-devices.net"}} |
27 | 36 | assert _resolve_linked_hub_hostname(hub, "classic") == "hub.azure-devices.net" |
28 | 37 |
|
29 | | - def test_default_is_device(self): |
| 38 | + def test_default_is_auto(self): |
30 | 39 | hub = {"properties": {"deviceHostName": "hub.device.azure-devices.net", "hostName": "hub.azure-devices.net"}} |
31 | 40 | assert _resolve_linked_hub_hostname(hub) == "hub.device.azure-devices.net" |
| 41 | + hub_v1 = {"properties": {"hostName": "hub.azure-devices.net"}} |
| 42 | + assert _resolve_linked_hub_hostname(hub_v1) == "hub.azure-devices.net" |
32 | 43 |
|
33 | 44 |
|
34 | 45 | class TestLinkedHubCreateValidation: |
@@ -111,3 +122,50 @@ def test_mi_null_identity_on_dps(self, fixture_cmd, mock_deps, mocker): |
111 | 122 | cmd=fixture_cmd, client=mock_deps, dps_name="dps", |
112 | 123 | hub_name="hub", authentication_type="SystemAssigned" |
113 | 124 | ) |
| 125 | + |
| 126 | + |
| 127 | +class TestMixedEndpointWarning: |
| 128 | + def test_no_warning_all_device(self, caplog): |
| 129 | + hubs = [ |
| 130 | + {"name": "hub1.device.azure-devices.net"}, |
| 131 | + {"name": "hub2.device.azure-devices.net"}, |
| 132 | + ] |
| 133 | + _warn_mixed_endpoint_types(hubs) |
| 134 | + assert "mixed hostname types" not in caplog.text |
| 135 | + |
| 136 | + def test_no_warning_all_classic(self, caplog): |
| 137 | + hubs = [ |
| 138 | + {"name": "hub1.azure-devices.net"}, |
| 139 | + {"name": "hub2.azure-devices.net"}, |
| 140 | + ] |
| 141 | + _warn_mixed_endpoint_types(hubs) |
| 142 | + assert "mixed hostname types" not in caplog.text |
| 143 | + |
| 144 | + def test_warning_on_mixed(self, caplog): |
| 145 | + import logging |
| 146 | + with caplog.at_level(logging.WARNING): |
| 147 | + hubs = [ |
| 148 | + {"name": "hub1.device.azure-devices.net"}, |
| 149 | + {"name": "hub2.azure-devices.net"}, |
| 150 | + ] |
| 151 | + _warn_mixed_endpoint_types(hubs) |
| 152 | + assert "mixed hostname types" in caplog.text |
| 153 | + |
| 154 | + def test_warning_on_mixed_with_connection_string(self, caplog): |
| 155 | + import logging |
| 156 | + with caplog.at_level(logging.WARNING): |
| 157 | + hubs = [ |
| 158 | + {"name": "hub1.device.azure-devices.net"}, |
| 159 | + {"connectionString": "HostName=hub2.azure-devices.net;SharedAccessKeyName=x;SharedAccessKey=y"}, |
| 160 | + ] |
| 161 | + _warn_mixed_endpoint_types(hubs) |
| 162 | + assert "mixed hostname types" in caplog.text |
| 163 | + |
| 164 | + def test_no_warning_single_hub(self, caplog): |
| 165 | + hubs = [{"name": "hub1.device.azure-devices.net"}] |
| 166 | + _warn_mixed_endpoint_types(hubs) |
| 167 | + assert "mixed hostname types" not in caplog.text |
| 168 | + |
| 169 | + def test_no_warning_empty(self, caplog): |
| 170 | + _warn_mixed_endpoint_types([]) |
| 171 | + assert "mixed hostname types" not in caplog.text |
0 commit comments