@@ -92,6 +92,7 @@ def env_helper_mock():
9292 AZURE_SEARCH_SEMANTIC_SEARCH_CONFIG
9393 )
9494 env_helper .SHOULD_STREAM = True
95+ env_helper .AZURE_AUTH_TYPE = "keys"
9596 env_helper .is_auth_type_keys .return_value = True
9697 env_helper .CONVERSATION_FLOW = ConversationFlow .CUSTOM .value
9798
@@ -128,25 +129,24 @@ def test_returns_speech_token_using_keys(
128129 timeout = 5 ,
129130 )
130131
131- @patch ("create_app.CognitiveServicesManagementClient " )
132+ @patch ("create_app.get_azure_credential " )
132133 @patch ("create_app.requests" )
133134 def test_returns_speech_token_using_rbac (
134135 self ,
135136 requests : MagicMock ,
136- CognitiveServicesManagementClientMock : MagicMock ,
137+ get_azure_credential_mock : MagicMock ,
137138 env_helper_mock : MagicMock ,
138139 client : FlaskClient ,
139140 ):
140141 """Test that the speech token is returned correctly when using RBAC."""
141142 # given
143+ env_helper_mock .AZURE_AUTH_TYPE = "rbac"
142144 env_helper_mock .AZURE_SPEECH_KEY = None
145+ env_helper_mock .MANAGED_IDENTITY_CLIENT_ID = "mock-client-id"
143146
144- mock_cognitive_services_client_mock = (
145- CognitiveServicesManagementClientMock .return_value
146- )
147- mock_cognitive_services_client_mock .accounts .list_keys .return_value = MagicMock (
148- key1 = "mock-key1" , key2 = "mock-key2"
149- )
147+ mock_credential = MagicMock ()
148+ mock_credential .get_token .return_value = MagicMock (token = "mock-aad-token" )
149+ get_azure_credential_mock .return_value = mock_credential
150150
151151 mock_response : MagicMock = requests .post .return_value
152152 mock_response .text = "speech-token"
@@ -163,10 +163,14 @@ def test_returns_speech_token_using_rbac(
163163 "languages" : AZURE_SPEECH_RECOGNIZER_LANGUAGES ,
164164 }
165165
166+ get_azure_credential_mock .assert_called_once_with ("mock-client-id" )
167+ mock_credential .get_token .assert_called_once_with (
168+ "https://cognitiveservices.azure.com/.default"
169+ )
166170 requests .post .assert_called_once_with (
167171 f"{ AZURE_SPEECH_REGION_ENDPOINT } sts/v1.0/issueToken" ,
168172 headers = {
169- "Ocp-Apim-Subscription-Key " : "mock-key1 " ,
173+ "Authorization " : "Bearer mock-aad-token " ,
170174 },
171175 timeout = 5 ,
172176 )
0 commit comments