Skip to content

Commit 04f4293

Browse files
committed
always secure
1 parent c6692ce commit 04f4293

File tree

3 files changed

+4
-47
lines changed

3 files changed

+4
-47
lines changed

azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/grpcClient.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def create_client(
3333
service_stub: Type[Any],
3434
address: str,
3535
grpc_max_message_length: int = 4 * 1024 * 1024,
36-
secure: bool = False,
3736
root_certificates: Optional[bytes] = None,
3837
) -> Any:
3938
"""
@@ -43,7 +42,6 @@ def create_client(
4342
service_stub: The generated service stub class (e.g. `MyServiceStub`).
4443
address: The server address (e.g., "localhost:50051").
4544
grpc_max_message_length: Max message size for send/receive.
46-
secure: If True, use a secure channel; otherwise, insecure.
4745
root_certificates: Optional root certificates for TLS.
4846
4947
Returns:
@@ -56,12 +54,9 @@ def create_client(
5654
]
5755

5856
try:
59-
if secure:
60-
credentials = grpc.ssl_channel_credentials(
61-
root_certificates=root_certificates)
62-
channel = grpc.secure_channel(address, credentials, options=options)
63-
else:
64-
channel = grpc.insecure_channel(address, options=options)
57+
credentials = grpc.ssl_channel_credentials(
58+
root_certificates=root_certificates)
59+
channel = grpc.secure_channel(address, credentials, options=options)
6560
except Exception as e:
6661
raise GrpcChannelError(f"Failed to create gRPC channel. URL: {address},"
6762
f" Options: {options}, Error: {e}")

azurefunctions-extensions-bindings-servicebus/azurefunctions/extensions/bindings/servicebus/serviceBusMessageActions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) .NET Foundation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import threading
45

56
from typing import Optional
@@ -51,7 +52,6 @@ def __init__(self) -> None:
5152
service_stub=SettlementStub,
5253
address=self._uri,
5354
grpc_max_message_length=self._grpc_max_message_length,
54-
secure=True,
5555
)
5656

5757
@classmethod

azurefunctions-extensions-bindings-servicebus/tests/test_grpc_client.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,6 @@ def __init__(self, channel):
1919

2020

2121
class TestGrpcClient(unittest.TestCase):
22-
def test_create_client_insecure_channel(self):
23-
with patch("azurefunctions.extensions.bindings.servicebus.grpcClient.grpc.insecure_channel") as mock_insecure: # noqa
24-
fake_channel = MagicMock()
25-
mock_insecure.return_value = fake_channel
26-
27-
client = GrpcClientFactory.create_client(
28-
service_stub=DummyStub,
29-
address="localhost:1234",
30-
grpc_max_message_length=1024,
31-
secure=False,
32-
)
33-
34-
mock_insecure.assert_called_once()
35-
args, kwargs = mock_insecure.call_args
36-
assert args[0] == "localhost:1234"
37-
assert ("grpc.max_send_message_length", 1024) in kwargs["options"]
38-
assert ("grpc.max_receive_message_length", 1024) in kwargs["options"]
39-
40-
assert isinstance(client, DummyStub)
41-
assert client._channel == fake_channel
42-
4322
def test_create_client_secure_channel_with_root_certs(self):
4423
with (patch("azurefunctions.extensions.bindings.servicebus.grpcClient.grpc.secure_channel") as mock_secure, # noqa
4524
patch("azurefunctions.extensions.bindings.servicebus.grpcClient.grpc.ssl_channel_credentials") as mock_creds): # noqa
@@ -52,7 +31,6 @@ def test_create_client_secure_channel_with_root_certs(self):
5231
service_stub=DummyStub,
5332
address="securehost:9999",
5433
grpc_max_message_length=2048,
55-
secure=True,
5634
root_certificates=b"fakecerts",
5735
)
5836

@@ -67,21 +45,6 @@ def test_create_client_secure_channel_with_root_certs(self):
6745
assert isinstance(client, DummyStub)
6846
assert client._channel == fake_channel
6947

70-
@patch("azurefunctions.extensions.bindings.servicebus.grpcClient."
71-
"grpc.insecure_channel")
72-
def test_create_client_raises_on_insecure_channel_failure(self,
73-
mock_insecure_channel):
74-
# Arrange: force grpc.insecure_channel to throw
75-
mock_insecure_channel.side_effect = RuntimeError("connection failed")
76-
77-
# Act + Assert
78-
with self.assertRaises(GrpcChannelError) as ctx:
79-
GrpcClientFactory.create_client(DummyStub, "localhost:1234", secure=False)
80-
81-
# Ensure exception contains useful context
82-
self.assertIn("Failed to create gRPC channel", str(ctx.exception))
83-
self.assertIn("localhost:1234", str(ctx.exception))
84-
8548
@patch("azurefunctions.extensions.bindings.servicebus.grpcClient."
8649
"grpc.secure_channel")
8750
@patch("azurefunctions.extensions.bindings.servicebus.grpcClient."
@@ -96,7 +59,6 @@ def test_create_client_raises_on_secure_channel_failure(self,
9659
with self.assertRaises(GrpcChannelError) as ctx:
9760
GrpcClientFactory.create_client(DummyStub,
9861
"localhost:5678",
99-
secure=True,
10062
root_certificates=b"dummy")
10163

10264
self.assertIn("Failed to create gRPC channel", str(ctx.exception))

0 commit comments

Comments
 (0)