@@ -1336,6 +1336,66 @@ - (void)testAcquireTokenSilent_when429ThrottledErrorReturned_shouldReturnAllHead
13361336 [self waitForExpectationsWithTimeout: 1.0 handler: nil ];
13371337}
13381338
1339+
1340+ - (void )testAcquireTokenSilent_when403HttpCodeReturned_shouldReturnMSIDErrorUnexpectedHttpResponseInUnderlyingError
1341+ {
1342+ MSIDRequestParameters *silentParameters = [self silentRequestParameters ];
1343+ MSIDDefaultTokenCacheAccessor *tokenCache = self.tokenCache ;
1344+
1345+ [self saveExpiredTokensInCache: tokenCache configuration: silentParameters.msidConfiguration];
1346+ silentParameters.accountIdentifier = [[MSIDAccountIdentifier alloc ] initWithDisplayableId: DEFAULT_TEST_ID_TOKEN_USERNAME homeAccountId: DEFAULT_TEST_HOME_ACCOUNT_ID];
1347+
1348+ NSString *authority = DEFAULT_TEST_AUTHORITY_GUID;
1349+ MSIDTestURLResponse *discoveryResponse = [MSIDTestURLResponse discoveryResponseForAuthority: authority];
1350+ [MSIDTestURLSession addResponse: discoveryResponse];
1351+
1352+ MSIDTestURLResponse *oidcResponse = [MSIDTestURLResponse oidcResponseForAuthority: authority];
1353+ [MSIDTestURLSession addResponse: oidcResponse];
1354+
1355+ NSMutableDictionary *reqHeaders = [[MSIDTestURLResponse msidDefaultRequestHeaders ] mutableCopy ];
1356+ [reqHeaders setObject: @" application/x-www-form-urlencoded" forKey: @" Content-Type" ];
1357+
1358+ MSIDTestURLResponse *errorTokenResponse =
1359+ [MSIDTestURLResponse requestURLString: DEFAULT_TEST_TOKEN_ENDPOINT_GUID
1360+ requestHeaders: reqHeaders
1361+ requestParamsBody: @{ @" client_id" : @" my_client_id" ,
1362+ @" scope" : @" user.read tasks.read openid profile offline_access" ,
1363+ @" grant_type" : @" refresh_token" ,
1364+ @" refresh_token" : DEFAULT_TEST_REFRESH_TOKEN,
1365+ MSID_OAUTH2_REDIRECT_URI : [[self silentRequestParameters ] redirectUri ],
1366+ @" client_info" : @" 1" }
1367+ responseURLString: DEFAULT_TEST_TOKEN_ENDPOINT_GUID
1368+ responseCode: 403
1369+ httpHeaderFields: @{@" Retry-After" : @" 256" ,
1370+ @" Other-Header-Field" : @" Other header field"
1371+ }
1372+ dictionaryAsJSON: nil ];
1373+
1374+ [errorTokenResponse->_requestHeaders removeObjectForKey: @" Content-Length" ];
1375+
1376+ [MSIDTestURLSession addResponse: errorTokenResponse];
1377+
1378+ MSIDDefaultSilentTokenRequest *silentRequest = [[MSIDDefaultSilentTokenRequest alloc ] initWithRequestParameters: silentParameters
1379+ forceRefresh: NO
1380+ oauthFactory: [MSIDAADV2Oauth2Factory new ]
1381+ tokenResponseValidator: [MSIDDefaultTokenResponseValidator new ]
1382+ tokenCache: tokenCache
1383+ accountMetadataCache: self .accountMetadataCache];
1384+
1385+ XCTestExpectation *expectation = [self expectationWithDescription: @" silent request" ];
1386+
1387+ [silentRequest executeRequestWithCompletion: ^(MSIDTokenResult * _Nullable result, NSError * _Nullable error) {
1388+
1389+ XCTAssertNotNil (error);
1390+ XCTAssertNil (result);
1391+ XCTAssertEqual (error.code , MSIDErrorServerUnhandledResponse);
1392+ XCTAssertEqualObjects (error.domain , MSIDHttpErrorCodeDomain);
1393+ XCTAssertEqualObjects (error.userInfo [MSIDHTTPResponseCodeKey], @" 403" );
1394+ [expectation fulfill ];
1395+ }];
1396+
1397+ [self waitForExpectationsWithTimeout: 1.0 handler: nil ];
1398+ }
13391399- (void )testAcquireTokenSilent_whenTokenEndpointInDifferentCloud_shouldReturnInteractionRequired
13401400{
13411401 // Prepare RT in cache
0 commit comments