Skip to content

Commit 722f9c5

Browse files
committed
Fix tests
1 parent 3c28d1f commit 722f9c5

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ManagedIdentityParameters.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public Set<String> scopes() {
3030
@Override
3131
public ClaimsRequest claims() {
3232
if (claims == null || claims.isEmpty()) {
33-
throw new MsalClientException("Claims cannot be null or empty",
34-
AuthenticationErrorCode.INVALID_JSON);
33+
return null;
3534
}
3635

3736
try {
@@ -108,6 +107,8 @@ public ManagedIdentityParametersBuilder forceRefresh(boolean forceRefresh) {
108107
* @return this builder instance
109108
*/
110109
public ManagedIdentityParametersBuilder claims(String claims) {
110+
ParameterValidationUtils.validateNotBlank("claims", claims);
111+
111112
this.claims = claims;
112113
return this;
113114
}

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTestDataProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ public static Stream<Arguments> createDataGetSource() {
118118
public static Stream<Arguments> createInvalidClaimsData() {
119119
return Stream.of(
120120
Arguments.of("invalid json format"),
121-
Arguments.of("{\"access_token\": }"),
122-
Arguments.of("")
121+
Arguments.of("{\"access_token\": }")
123122
);
124123
}
125124
}

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,13 +738,47 @@ void managedIdentity_InvalidClaims(String claimsJson) throws Exception {
738738

739739
ExecutionException ex = assertThrows(ExecutionException.class, future::get);
740740
assertInstanceOf(MsalClientException.class, ex.getCause());
741+
741742
MsalClientException msalException = (MsalClientException) ex.getCause();
742743
assertEquals(AuthenticationErrorCode.INVALID_JSON, msalException.errorCode());
743744

744745
// Verify no HTTP requests were made for invalid claims
745746
verify(httpClientMock, never()).send(any());
746747
}
747748

749+
@Test
750+
void managedIdentityTest_WithEmptyClaims() throws Exception {
751+
IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper(APP_SERVICE, appServiceEndpoint);
752+
ManagedIdentityApplication.setEnvironmentVariables(environmentVariables);
753+
DefaultHttpClient httpClientMock = mock(DefaultHttpClient.class);
754+
755+
miApp = ManagedIdentityApplication
756+
.builder(ManagedIdentityId.systemAssigned())
757+
.httpClient(httpClientMock)
758+
.build();
759+
760+
try {
761+
miApp.acquireTokenForManagedIdentity(
762+
ManagedIdentityParameters.builder(resource)
763+
.claims("")
764+
.build());
765+
} catch (Exception exception) {
766+
assert(exception instanceof IllegalArgumentException);
767+
}
768+
769+
try {
770+
miApp.acquireTokenForManagedIdentity(
771+
ManagedIdentityParameters.builder(resource)
772+
.claims(null)
773+
.build());
774+
} catch (Exception exception) {
775+
assert(exception instanceof IllegalArgumentException);
776+
}
777+
778+
// Verify no HTTP requests were made for invalid claims
779+
verify(httpClientMock, never()).send(any());
780+
}
781+
748782
@Nested
749783
class AzureArc {
750784

0 commit comments

Comments
 (0)