Skip to content

Add check for missing IdentityProvider configuration. #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public TokenAuthConfig build() {
throw new RedisEntraIDException(
"Cannot have both customEntraIdAuthenticationSupplier and ServicePrincipal/ManagedIdentity!");
}
if (this.customEntraIdAuthenticationSupplier == null && spi == null && mii == null) {
throw new RedisEntraIDException(
"Missing configuration. One of customEntraIdAuthenticationSupplier, ServicePrincipal or ManagedIdentity must be configured!");
}

if (spi != null) {
super.identityProviderConfig(
new EntraIDIdentityProviderConfig(spi, scopes, tokenRequestExecTimeoutInMs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;

import com.microsoft.aad.msal4j.IAccount;
import com.microsoft.aad.msal4j.ITenantProfile;
import org.awaitility.Awaitility;
import org.awaitility.Durations;
import org.junit.Test;
Expand Down Expand Up @@ -64,6 +66,7 @@
import redis.clients.authentication.entraid.EntraIDTokenAuthConfigBuilder;
import redis.clients.authentication.entraid.JWToken;
import redis.clients.authentication.entraid.ManagedIdentityInfo;
import redis.clients.authentication.entraid.RedisEntraIDException;
import redis.clients.authentication.entraid.ServicePrincipalInfo;
import redis.clients.authentication.entraid.ManagedIdentityInfo.UserManagedIdentityType;

Expand Down Expand Up @@ -143,6 +146,28 @@ public void testConfigBuilder() {
}
}

@Test
public void testConfigBuilderThrowsErrorIfMissconfigured() {

// Missing Configuration
assertThrows(RedisEntraIDException.class,() -> EntraIDTokenAuthConfigBuilder.builder().build());

// spi & mpi configured
assertThrows(RedisEntraIDException.class,() -> EntraIDTokenAuthConfigBuilder.builder()
.clientId("clientid")
.secret("secret")
.systemAssignedManagedIdentity()
.build());

// spi || mpi && customEntraIdAuthenticationSupplier configured
assertThrows(RedisEntraIDException.class,() -> EntraIDTokenAuthConfigBuilder.builder()
.clientId("clientid")
.secret("secret")
.customEntraIdAuthenticationSupplier(() -> mock(IAuthenticationResult.class))
.build());
}


// T.1.2
// Implement a stubbed IdentityProvider and verify that the TokenManager works normally and handles:
// network errors or other exceptions thrown from the IdentityProvider
Expand Down Expand Up @@ -529,6 +554,7 @@ public void renewalTimingConfigTest() {
int maxAttemptsToRetry = 6;
int tokenRequestExecTimeoutInMs = 401;
TokenAuthConfig tokenAuthConfig = EntraIDTokenAuthConfigBuilder.builder()
.clientId("testClientId").secret("testSecret")
.expirationRefreshRatio(refreshRatio).delayInMsToRetry(delayInMsToRetry)
.lowerRefreshBoundMillis(lowerRefreshBoundMillis)
.maxAttemptsToRetry(maxAttemptsToRetry)
Expand Down
Loading