Skip to content

Commit b63108e

Browse files
authored
Fixed bug in sip routing. SDK shouldnt send empty patch. (Azure#27919)
* Fixed bug in sip routing. SDK shouldnt send empty patch. * Changing client for new async testcase to be non-managed identity.
1 parent b37bb29 commit b63108e

File tree

6 files changed

+161
-8
lines changed

6 files changed

+161
-8
lines changed

sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/_sip_routing_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@ def set_trunks(
206206
if x.fqdn not in [o.fqdn for o in trunks]:
207207
config.trunks[x.fqdn] = None
208208

209-
self._rest_service.patch_sip_configuration(
210-
body=config, **kwargs
211-
)
209+
if len(config.trunks) > 0:
210+
self._rest_service.patch_sip_configuration(
211+
body=config, **kwargs
212+
)
212213

213214
@distributed_trace
214215
def set_routes(

sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/siprouting/aio/_sip_routing_client_async.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,10 @@ async def set_trunks(
210210
if x.fqdn not in [o.fqdn for o in trunks]:
211211
config.trunks[x.fqdn] = None
212212

213-
await self._rest_service.patch_sip_configuration(
214-
body=config, **kwargs
215-
)
213+
if len(config.trunks) > 0:
214+
await self._rest_service.patch_sip_configuration(
215+
body=config, **kwargs
216+
)
216217

217218
@distributed_trace_async
218219
async def set_routes(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "https://sanitized.communication.azure.com/sip?api-version=2021-05-01-preview",
5+
"RequestMethod": "GET",
6+
"RequestHeaders": {
7+
"Accept": "application/json",
8+
"Accept-Encoding": "gzip, deflate",
9+
"Connection": "keep-alive",
10+
"User-Agent": "azsdk-python-communication-phonenumbers/1.1.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
11+
"x-ms-content-sha256": "sanitized",
12+
"x-ms-date": "sanitized",
13+
"x-ms-return-client-request-id": "true"
14+
},
15+
"RequestBody": null,
16+
"StatusCode": 200,
17+
"ResponseHeaders": {
18+
"api-supported-versions": "2021-05-01-preview, 2022-09-01-preview",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Date": "sanitized",
21+
"MS-CV": "sanitized",
22+
"Strict-Transport-Security": "max-age=2592000",
23+
"Transfer-Encoding": "chunked",
24+
"X-Azure-Ref": "sanitized",
25+
"X-Cache": "CONFIG_NOCACHE",
26+
"X-Processing-Time": "182ms"
27+
},
28+
"ResponseBody": {
29+
"trunks": {},
30+
"routes": []
31+
}
32+
},
33+
{
34+
"RequestUri": "https://sanitized.communication.azure.com/sip?api-version=2021-05-01-preview",
35+
"RequestMethod": "GET",
36+
"RequestHeaders": {
37+
"Accept": "application/json",
38+
"Accept-Encoding": "gzip, deflate",
39+
"Connection": "keep-alive",
40+
"User-Agent": "azsdk-python-communication-phonenumbers/1.1.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
41+
"x-ms-content-sha256": "sanitized",
42+
"x-ms-date": "sanitized",
43+
"x-ms-return-client-request-id": "true"
44+
},
45+
"RequestBody": null,
46+
"StatusCode": 200,
47+
"ResponseHeaders": {
48+
"api-supported-versions": "2021-05-01-preview, 2022-09-01-preview",
49+
"Content-Type": "application/json; charset=utf-8",
50+
"Date": "sanitized",
51+
"MS-CV": "sanitized",
52+
"Strict-Transport-Security": "max-age=2592000",
53+
"Transfer-Encoding": "chunked",
54+
"X-Azure-Ref": "sanitized",
55+
"X-Cache": "CONFIG_NOCACHE",
56+
"X-Processing-Time": "279ms"
57+
},
58+
"ResponseBody": {
59+
"trunks": {},
60+
"routes": []
61+
}
62+
}
63+
],
64+
"Variables": {}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "https://sanitized.communication.azure.com/sip?api-version=2021-05-01-preview",
5+
"RequestMethod": "GET",
6+
"RequestHeaders": {
7+
"Accept": "application/json",
8+
"Accept-Encoding": "gzip, deflate",
9+
"Content-Length": "0",
10+
"User-Agent": "azsdk-python-communication-phonenumbers/1.1.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
11+
"x-ms-content-sha256": "sanitized",
12+
"x-ms-date": "sanitized",
13+
"x-ms-return-client-request-id": "true"
14+
},
15+
"RequestBody": null,
16+
"StatusCode": 200,
17+
"ResponseHeaders": {
18+
"api-supported-versions": "2021-05-01-preview, 2022-09-01-preview",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Date": "sanitized",
21+
"MS-CV": "sanitized",
22+
"Strict-Transport-Security": "max-age=2592000",
23+
"Transfer-Encoding": "chunked",
24+
"X-Azure-Ref": "sanitized",
25+
"X-Cache": "CONFIG_NOCACHE",
26+
"X-Processing-Time": "270ms"
27+
},
28+
"ResponseBody": {
29+
"trunks": {},
30+
"routes": []
31+
}
32+
},
33+
{
34+
"RequestUri": "https://sanitized.communication.azure.com/sip?api-version=2021-05-01-preview",
35+
"RequestMethod": "GET",
36+
"RequestHeaders": {
37+
"Accept": "application/json",
38+
"Accept-Encoding": "gzip, deflate",
39+
"Content-Length": "0",
40+
"User-Agent": "azsdk-python-communication-phonenumbers/1.1.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
41+
"x-ms-content-sha256": "sanitized",
42+
"x-ms-date": "sanitized",
43+
"x-ms-return-client-request-id": "true"
44+
},
45+
"RequestBody": null,
46+
"StatusCode": 200,
47+
"ResponseHeaders": {
48+
"api-supported-versions": "2021-05-01-preview, 2022-09-01-preview",
49+
"Content-Type": "application/json; charset=utf-8",
50+
"Date": "sanitized",
51+
"MS-CV": "sanitized",
52+
"Strict-Transport-Security": "max-age=2592000",
53+
"Transfer-Encoding": "chunked",
54+
"X-Azure-Ref": "sanitized",
55+
"X-Cache": "CONFIG_NOCACHE",
56+
"X-Processing-Time": "76ms"
57+
},
58+
"ResponseBody": {
59+
"trunks": {},
60+
"routes": []
61+
}
62+
}
63+
],
64+
"Variables": {}
65+
}

sdk/communication/azure-communication-phonenumbers/test/test_sip_routing_client_e2e.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
6+
from azure.core.exceptions import HttpResponseError
77
from phone_numbers_testcase import PhoneNumbersTestCase
88
from _shared.utils import create_token_credential, get_http_logging_policy
99
from sip_routing_helper import get_user_domain, assert_trunks_are_equal, assert_routes_are_equal
@@ -79,6 +79,16 @@ def test_set_trunks_from_managed_identity(self, **kwargs):
7979
assert result_trunks is not None, "No trunks were returned."
8080
assert_trunks_are_equal(result_trunks,[self.additional_trunk])
8181

82+
@recorded_by_proxy
83+
def test_set_trunks_empty_list(self, **kwargs):
84+
"""Verification of bug fix. SDK shouldn't send empty PATCH, otherwise it will receive exception.
85+
This situation occurs, when sending empty trunks list to already empty trunk configuration."""
86+
try:
87+
self._sip_routing_client.set_trunks([])
88+
self._sip_routing_client.set_trunks([])
89+
except HttpResponseError as exception:
90+
assert False, "Trying to set empty trunks list returned Http error: " + str(exception.status_code) + ", message: " + exception.message
91+
8292
@recorded_by_proxy
8393
def test_set_routes(self, **kwargs):
8494
self._prepare_test()

sdk/communication/azure-communication-phonenumbers/test/test_sip_routing_client_e2e_async.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
76
import pytest
7+
from azure.core.exceptions import HttpResponseError
88
from phone_numbers_testcase import PhoneNumbersTestCase
99
from devtools_testutils.aio import recorded_by_proxy_async
1010
from _shared.utils import async_create_token_credential, get_http_logging_policy
@@ -88,6 +88,17 @@ async def test_set_trunks_from_managed_identity(self):
8888
result_trunks = await self._sip_routing_client.get_trunks()
8989
assert result_trunks is not None, "No trunks were returned."
9090
assert_trunks_are_equal(result_trunks,[self.additional_trunk]), "Trunks are not equal."
91+
92+
@recorded_by_proxy_async
93+
async def test_set_trunks_empty_list(self):
94+
"""Verification of bug fix. SDK shouldn't send empty PATCH, otherwise it will receive exception.
95+
This situation occurs, when sending empty trunks list to already empty trunk configuration."""
96+
async with self._sip_routing_client:
97+
try:
98+
await self._sip_routing_client.set_trunks([])
99+
await self._sip_routing_client.set_trunks([])
100+
except HttpResponseError as exception:
101+
assert False, "Trying to set empty trunks list returned Http error: " + str(exception.status_code) + ", message: " + exception.message
91102

92103
@recorded_by_proxy_async
93104
async def test_set_routes(self):

0 commit comments

Comments
 (0)