1
1
import json
2
2
import os
3
+ import sys
3
4
import time
4
5
import unittest
5
6
try :
@@ -141,7 +142,7 @@ def test_unified_api_service_should_ignore_unnecessary_client_id(self):
141
142
{"ManagedIdentityIdType" : "ClientId" , "Id" : "foo" },
142
143
token_cache = TokenCache ()))
143
144
144
- def test_sf_service_error_should_be_normalized (self ):
145
+ def test_sf_error_should_be_normalized (self ):
145
146
raw_error = '''
146
147
{"error": {
147
148
"correlationId": "foo",
@@ -163,18 +164,33 @@ def test_sf_service_error_should_be_normalized(self):
163
164
"IDENTITY_ENDPOINT" : "http://localhost/token" ,
164
165
"IMDS_ENDPOINT" : "http://localhost" ,
165
166
})
167
+ @patch (
168
+ "builtins.open" if sys .version_info .major >= 3 else "__builtin__.open" ,
169
+ mock_open (read_data = "secret" )
170
+ )
166
171
class ArcTestCase (ClientTestCase ):
172
+ challenge = MinimalResponse (status_code = 401 , text = "" , headers = {
173
+ "WWW-Authenticate" : "Basic realm=/tmp/foo" ,
174
+ })
167
175
168
- @patch ("builtins.open" , mock_open (read_data = "secret" ))
169
176
def test_happy_path (self ):
170
177
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 :
179
184
super (ArcTestCase , self )._test_happy_path (self .app , mocked_method )
180
185
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