11import json
22import os
3+ import sys
34import time
45import unittest
56try :
@@ -141,7 +142,7 @@ def test_unified_api_service_should_ignore_unnecessary_client_id(self):
141142 {"ManagedIdentityIdType" : "ClientId" , "Id" : "foo" },
142143 token_cache = TokenCache ()))
143144
144- def test_sf_service_error_should_be_normalized (self ):
145+ def test_sf_error_should_be_normalized (self ):
145146 raw_error = '''
146147{"error": {
147148 "correlationId": "foo",
@@ -163,18 +164,33 @@ def test_sf_service_error_should_be_normalized(self):
163164 "IDENTITY_ENDPOINT" : "http://localhost/token" ,
164165 "IMDS_ENDPOINT" : "http://localhost" ,
165166})
167+ @patch (
168+ "builtins.open" if sys .version_info .major >= 3 else "__builtin__.open" ,
169+ mock_open (read_data = "secret" )
170+ )
166171class ArcTestCase (ClientTestCase ):
172+ challenge = MinimalResponse (status_code = 401 , text = "" , headers = {
173+ "WWW-Authenticate" : "Basic realm=/tmp/foo" ,
174+ })
167175
168- @patch ("builtins.open" , mock_open (read_data = "secret" ))
169176 def test_happy_path (self ):
170177 with patch .object (self .app ._http_client , "get" , side_effect = [
171- MinimalResponse (status_code = 401 , text = "" , headers = {
172- "WWW-Authenticate" : "Basic realm=/tmp/foo" ,
173- }),
174- MinimalResponse (
175- status_code = 200 ,
176- text = '{"access_token": "AT", "expires_in": "1234", "resource": "R"}' ,
177- ),
178- ]) as mocked_method :
178+ self .challenge ,
179+ MinimalResponse (
180+ status_code = 200 ,
181+ text = '{"access_token": "AT", "expires_in": "1234", "resource": "R"}' ,
182+ ),
183+ ]) as mocked_method :
179184 super (ArcTestCase , self )._test_happy_path (self .app , mocked_method )
180185
186+ def test_arc_error_should_be_normalized (self ):
187+ with patch .object (self .app ._http_client , "get" , side_effect = [
188+ self .challenge ,
189+ MinimalResponse (status_code = 400 , text = "undefined" ),
190+ ]) as mocked_method :
191+ self .assertEqual ({
192+ "error" : "invalid_request" ,
193+ "error_description" : "undefined" ,
194+ }, self .app .acquire_token (resource = "R" ))
195+ self .assertEqual ({}, self .app ._token_cache ._cache )
196+
0 commit comments