@@ -82,7 +82,7 @@ private HttpRequest expectedRequest(ManagedIdentitySourceType source, String res
82
82
headers .put ("Metadata" , "true" );
83
83
break ;
84
84
}
85
- case AzureArc : {
85
+ case AZURE_ARC : {
86
86
endpoint = azureArcEndpoint ;
87
87
88
88
queryParameters .put ("api-version" , Collections .singletonList ("2019-11-01" ));
@@ -129,7 +129,7 @@ void managedIdentityTest_SystemAssigned_SuccessfulResponse(ManagedIdentitySource
129
129
IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
130
130
DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
131
131
132
- lenient (). when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
132
+ when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
133
133
134
134
ManagedIdentityApplication miApp = ManagedIdentityApplication
135
135
.builder (ManagedIdentityId .systemAssigned ())
@@ -152,6 +152,7 @@ void managedIdentityTest_SystemAssigned_SuccessfulResponse(ManagedIdentitySource
152
152
153
153
assertNotNull (result .accessToken ());
154
154
assertEquals (accessToken , result .accessToken ());
155
+ verify (httpClientMock , times (1 )).send (any ());
155
156
}
156
157
157
158
@ ParameterizedTest
@@ -173,6 +174,7 @@ void managedIdentityTest_UserAssigned_SuccessfulResponse(ManagedIdentitySourceTy
173
174
.build ()).get ();
174
175
175
176
assertNotNull (result .accessToken ());
177
+ verify (httpClientMock , times (1 )).send (any ());
176
178
}
177
179
178
180
@ ParameterizedTest
@@ -197,7 +199,7 @@ void managedIdentityTest_UserAssigned_NotSupported(ManagedIdentitySourceType sou
197
199
assertInstanceOf (MsalManagedIdentityException .class , e .getCause ());
198
200
199
201
MsalManagedIdentityException msalMsiException = (MsalManagedIdentityException ) e .getCause ();
200
- assertEquals (ManagedIdentitySourceType . CLOUD_SHELL , msalMsiException .managedIdentitySourceType );
202
+ assertEquals (source , msalMsiException .managedIdentitySourceType );
201
203
assertEquals (MsalError .USER_ASSIGNED_MANAGED_IDENTITY_NOT_SUPPORTED , msalMsiException .errorCode ());
202
204
return ;
203
205
}
@@ -214,8 +216,8 @@ void managedIdentityTest_DifferentScopes_RequestsNewToken(ManagedIdentitySourceT
214
216
IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
215
217
DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
216
218
217
- lenient (). when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
218
- lenient (). when (httpClientMock .send (eq (expectedRequest (source , anotherResource )))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
219
+ when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
220
+ when (httpClientMock .send (eq (expectedRequest (source , anotherResource )))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
219
221
220
222
ManagedIdentityApplication miApp = ManagedIdentityApplication
221
223
.builder (ManagedIdentityId .systemAssigned ())
@@ -235,6 +237,7 @@ void managedIdentityTest_DifferentScopes_RequestsNewToken(ManagedIdentitySourceT
235
237
.build ()).get ();
236
238
237
239
assertNotNull (result .accessToken ());
240
+ verify (httpClientMock , times (2 )).send (any ());
238
241
// TODO: Assert token source to check the token source is IDP and not Cache.
239
242
}
240
243
@@ -244,8 +247,7 @@ void managedIdentityTest_WrongScopes(ManagedIdentitySourceType source, String en
244
247
IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
245
248
DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
246
249
247
- lenient ().when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (500 , getMsiErrorResponse ()));
248
- lenient ().when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (500 , getMsiErrorResponse ()));
250
+ when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (500 , getMsiErrorResponse ()));
249
251
250
252
ManagedIdentityApplication miApp = ManagedIdentityApplication
251
253
.builder (ManagedIdentityId .systemAssigned ())
@@ -267,6 +269,7 @@ void managedIdentityTest_WrongScopes(ManagedIdentitySourceType source, String en
267
269
}
268
270
269
271
fail ("MsalManagedIdentityException is expected but not thrown." );
272
+ verify (httpClientMock , times (1 )).send (any ());
270
273
}
271
274
272
275
@ ParameterizedTest
@@ -275,8 +278,7 @@ void managedIdentity_RequestFailed_NoPayload(ManagedIdentitySourceType source, S
275
278
IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
276
279
DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
277
280
278
- lenient ().when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (500 , "" ));
279
- lenient ().when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (500 , "" ));
281
+ when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (500 , "" ));
280
282
281
283
ManagedIdentityApplication miApp = ManagedIdentityApplication
282
284
.builder (ManagedIdentityId .systemAssigned ())
@@ -298,6 +300,7 @@ void managedIdentity_RequestFailed_NoPayload(ManagedIdentitySourceType source, S
298
300
}
299
301
300
302
fail ("MsalManagedIdentityException is expected but not thrown." );
303
+ verify (httpClientMock , times (1 )).send (any ());
301
304
}
302
305
303
306
@ ParameterizedTest
@@ -306,8 +309,7 @@ void managedIdentity_RequestFailed_NullResponse(ManagedIdentitySourceType source
306
309
IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
307
310
DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
308
311
309
- lenient ().when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (200 , "" ));
310
- lenient ().when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (200 , "" ));
312
+ when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (200 , "" ));
311
313
312
314
ManagedIdentityApplication miApp = ManagedIdentityApplication
313
315
.builder (ManagedIdentityId .systemAssigned ())
@@ -329,6 +331,7 @@ void managedIdentity_RequestFailed_NullResponse(ManagedIdentitySourceType source
329
331
}
330
332
331
333
fail ("MsalManagedIdentityException is expected but not thrown." );
334
+ verify (httpClientMock , times (1 )).send (any ());
332
335
}
333
336
334
337
@ ParameterizedTest
@@ -337,7 +340,7 @@ void managedIdentity_RequestFailed_UnreachableNetwork(ManagedIdentitySourceType
337
340
IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
338
341
DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
339
342
340
- lenient (). when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenThrow (new SocketException ("A socket operation was attempted to an unreachable network." ));
343
+ when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenThrow (new SocketException ("A socket operation was attempted to an unreachable network." ));
341
344
342
345
ManagedIdentityApplication miApp = ManagedIdentityApplication
343
346
.builder (ManagedIdentityId .systemAssigned ())
@@ -359,17 +362,18 @@ void managedIdentity_RequestFailed_UnreachableNetwork(ManagedIdentitySourceType
359
362
}
360
363
361
364
fail ("MsalManagedIdentityException is expected but not thrown." );
365
+ verify (httpClientMock , times (1 )).send (any ());
362
366
}
363
367
364
368
@ Test
365
369
void azureArcManagedIdentity_MissingAuthHeader () throws Exception {
366
- IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (ManagedIdentitySourceType .AzureArc , azureArcEndpoint );
370
+ IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (ManagedIdentitySourceType .AZURE_ARC , azureArcEndpoint );
367
371
DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
368
372
369
373
HttpResponse response = new HttpResponse ();
370
374
response .statusCode (HttpStatus .SC_UNAUTHORIZED );
371
375
372
- lenient (). when (httpClientMock .send (any ())).thenReturn (response );
376
+ when (httpClientMock .send (any ())).thenReturn (response );
373
377
374
378
ManagedIdentityApplication miApp = ManagedIdentityApplication
375
379
.builder (ManagedIdentityId .systemAssigned ())
@@ -385,13 +389,14 @@ void azureArcManagedIdentity_MissingAuthHeader() throws Exception {
385
389
assert (exception .getCause () instanceof MsalManagedIdentityException );
386
390
387
391
MsalManagedIdentityException miException = (MsalManagedIdentityException ) exception .getCause ();
388
- assertEquals (ManagedIdentitySourceType .AzureArc , miException .managedIdentitySourceType );
392
+ assertEquals (ManagedIdentitySourceType .AZURE_ARC , miException .managedIdentitySourceType );
389
393
assertEquals (MsalError .MANAGED_IDENTITY_REQUEST_FAILED , miException .errorCode ());
390
394
assertEquals (MsalErrorMessage .MANAGED_IDENTITY_NO_CHALLENGE_ERROR , miException .getMessage ());
391
395
return ;
392
396
}
393
397
394
398
fail ("MsalManagedIdentityException is expected but not thrown." );
399
+ verify (httpClientMock , times (1 )).send (any ());
395
400
}
396
401
397
402
@ ParameterizedTest
@@ -400,7 +405,7 @@ void managedIdentity_SharedCache(ManagedIdentitySourceType source, String endpoi
400
405
IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
401
406
DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
402
407
403
- lenient (). when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
408
+ when (httpClientMock .send (eq (expectedRequest (source , resource )))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
404
409
405
410
ManagedIdentityApplication miApp1 = ManagedIdentityApplication
406
411
.builder (ManagedIdentityId .systemAssigned ())
@@ -430,18 +435,19 @@ void managedIdentity_SharedCache(ManagedIdentitySourceType source, String endpoi
430
435
// so calling acquireTokenForManagedIdentity with the same parameters in two different ManagedIdentityApplications
431
436
// should return the same token
432
437
assertEquals (resultMiApp1 .accessToken (), resultMiApp2 .accessToken ());
438
+ verify (httpClientMock , times (1 )).send (any ());
433
439
}
434
440
435
441
@ Test
436
442
void azureArcManagedIdentity_InvalidAuthHeader () throws Exception {
437
- IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (ManagedIdentitySourceType .AzureArc , azureArcEndpoint );
443
+ IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (ManagedIdentitySourceType .AZURE_ARC , azureArcEndpoint );
438
444
DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
439
445
440
446
HttpResponse response = new HttpResponse ();
441
447
response .statusCode (HttpStatus .SC_UNAUTHORIZED );
442
448
response .headers ().put ("WWW-Authenticate" , Collections .singletonList ("Basic realm=filepath=somepath" ));
443
449
444
- lenient (). when (httpClientMock .send (any ())).thenReturn (response );
450
+ when (httpClientMock .send (any ())).thenReturn (response );
445
451
446
452
ManagedIdentityApplication miApp = ManagedIdentityApplication
447
453
.builder (ManagedIdentityId .systemAssigned ())
@@ -457,12 +463,13 @@ void azureArcManagedIdentity_InvalidAuthHeader() throws Exception {
457
463
assert (exception .getCause () instanceof MsalManagedIdentityException );
458
464
459
465
MsalManagedIdentityException miException = (MsalManagedIdentityException ) exception .getCause ();
460
- assertEquals (ManagedIdentitySourceType .AzureArc , miException .managedIdentitySourceType );
466
+ assertEquals (ManagedIdentitySourceType .AZURE_ARC , miException .managedIdentitySourceType );
461
467
assertEquals (MsalError .MANAGED_IDENTITY_REQUEST_FAILED , miException .errorCode ());
462
468
assertEquals (MsalErrorMessage .MANAGED_IDENTITY_INVALID_CHALLENGE , miException .getMessage ());
463
469
return ;
464
470
}
465
471
466
472
fail ("MsalManagedIdentityException is expected but not thrown." );
473
+ verify (httpClientMock , times (1 )).send (any ());
467
474
}
468
475
}
0 commit comments