Skip to content

Commit

Permalink
[Communication] Fix async identity client decode - url bug (Azure#15894)
Browse files Browse the repository at this point in the history
* Remove redundant decorators; skip managed identity test

* add isasync optional param for get auth policy

* Enable async managed identity test

* Force decoding url in async client

Co-authored-by: turalf <[email protected]>
  • Loading branch information
turalf and turalf authored Dec 22, 2020
1 parent 5b1777e commit e43995b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
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

0 comments on commit e43995b

Please sign in to comment.