Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Communication] Fix async identity client decode - url bug #15894

Merged
merged 4 commits into from
Dec 22, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def create_access_token(token):

def get_authentication_policy(
endpoint, # type: str
credential # type: TokenCredential or str
credential, # type: TokenCredential or str
is_async=False, # type: bool
):
# type: (...) -> BearerTokenCredentialPolicy or HMACCredentialPolicy
"""Returns the correct authentication policy based
Expand All @@ -81,6 +82,8 @@ def get_authentication_policy(
:type endpoint: str
:param credential: The credential we use to authenticate to the service
:type credential: TokenCredential or str
:param isAsync: For async clients there is a need to decode the url
:type bool: isAsync or str

:rtype: ~azure.core.pipeline.policies.BearerTokenCredentialPolicy
~HMACCredentialsPolicy
Expand All @@ -94,7 +97,7 @@ def get_authentication_policy(
credential, "https://communication.azure.com//.default")
if isinstance(credential, str):
from .._shared.policy import HMACCredentialsPolicy
return HMACCredentialsPolicy(endpoint, credential)
return HMACCredentialsPolicy(endpoint, credential, decode_url=is_async)

raise TypeError("Unsupported credential: {}. Use an access token string to use HMACCredentialsPolicy"
"or a token credential from azure.identity".format(type(credential)))
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
self._endpoint = endpoint
self._identity_service_client = CommunicationIdentityClientGen(
self._endpoint,
authentication_policy=get_authentication_policy(endpoint, credential),
authentication_policy=get_authentication_policy(endpoint, credential, is_async=True),
sdk_moniker=SDK_MONIKER,
**kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def setUp(self):

@ResourceGroupPreparer(random_name_enabled=True)
@CommunicationServicePreparer()
@pytest.mark.asyncio
@AsyncCommunicationTestCase.await_prepared_test
async def test_create_user_from_managed_identity(self, connection_string):
endpoint, access_key = parse_connection_str(connection_string)
from devtools_testutils import is_live
Expand All @@ -48,8 +46,6 @@ async def test_create_user_from_managed_identity(self, connection_string):

@ResourceGroupPreparer(random_name_enabled=True)
@CommunicationServicePreparer()
@pytest.mark.asyncio
@AsyncCommunicationTestCase.await_prepared_test
async def test_create_user(self, connection_string):
identity_client = CommunicationIdentityClient.from_connection_string(connection_string)
async with identity_client:
Expand All @@ -59,8 +55,6 @@ async def test_create_user(self, connection_string):

@ResourceGroupPreparer(random_name_enabled=True)
@CommunicationServicePreparer()
@pytest.mark.asyncio
@AsyncCommunicationTestCase.await_prepared_test
async def test_issue_token(self, connection_string):
identity_client = CommunicationIdentityClient.from_connection_string(connection_string)
async with identity_client:
Expand All @@ -72,8 +66,6 @@ async def test_issue_token(self, connection_string):

@ResourceGroupPreparer(random_name_enabled=True)
@CommunicationServicePreparer()
@pytest.mark.asyncio
@AsyncCommunicationTestCase.await_prepared_test
async def test_revoke_tokens(self, connection_string):
identity_client = CommunicationIdentityClient.from_connection_string(connection_string)
async with identity_client:
Expand All @@ -86,8 +78,6 @@ async def test_revoke_tokens(self, connection_string):

@ResourceGroupPreparer(random_name_enabled=True)
@CommunicationServicePreparer()
@pytest.mark.asyncio
@AsyncCommunicationTestCase.await_prepared_test
async def test_delete_user(self, connection_string):
identity_client = CommunicationIdentityClient.from_connection_string(connection_string)
async with identity_client:
Expand Down