Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dapr/conf/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ def _set_scheme(self):

if self._parsed_url.scheme in ['http', 'https']:
self._scheme = URIParseConfig.DEFAULT_SCHEME
tls = str(self._parsed_url.scheme == 'https').lower()
warn(
'http and https schemes are deprecated for grpc, use myhost?tls=false or myhost?tls=true instead'
f'http and https schemes are deprecated for grpc, use '
f'{self._hostname}:{self._parsed_url.port or URIParseConfig.DEFAULT_PORT}?tls={tls} instead',
DeprecationWarning,
stacklevel=3,
)
return

Expand Down
24 changes: 24 additions & 0 deletions tests/conf/helpers_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
import unittest
import warnings

from dapr.conf.helpers import GrpcEndpoint


class DaprClientHelpersTests(unittest.TestCase):
def test_http_scheme_deprecation_keeps_endpoint_and_points_to_caller(self):
for scheme, port, secure in [('http', 80, False), ('https', 443, True)]:
with self.subTest(scheme=scheme):
with self.assertWarns(DeprecationWarning) as warning:
endpoint = GrpcEndpoint(f'{scheme}://host:{port}')
self.assertIn('helpers_test.py', warning.filename)
self.assertIn(f'host:{port}?tls={str(secure).lower()}', str(warning.warning))
self.assertEqual(endpoint.hostname, 'host')
self.assertEqual(endpoint.port_as_int, port)
self.assertEqual(endpoint.tls, secure)
self.assertEqual(endpoint.endpoint, f'dns:host:{port}')

with self.assertRaises(ValueError):
GrpcEndpoint('https://host:443?tls=false')

def test_http_scheme_emits_only_a_deprecation_warning(self):
for scheme, port in [('http', 80), ('https', 443)]:
with self.subTest(scheme=scheme):
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter('always')
GrpcEndpoint(f'{scheme}://host:{port}')
self.assertEqual([warning.category for warning in caught], [DeprecationWarning])

def test_parse_grpc_endpoint(self):
testcases = [
# Port only
Expand Down
Loading