Skip to content

Test support for DefaultAzureCredential #4113

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
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<dependency>
<groupId>redis.clients.authentication</groupId>
<artifactId>redis-authx-core</artifactId>
<version>0.1.1-beta1</version>
<version>0.1.1-beta2</version>
</dependency>

<!-- Optional dependencies -->
Expand Down Expand Up @@ -159,7 +159,7 @@
<dependency>
<groupId>redis.clients.authentication</groupId>
<artifactId>redis-authx-entraid</artifactId>
<version>0.1.1-beta1</version>
<version>0.1.1-beta2</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.azure.identity.DefaultAzureCredential;
import com.azure.identity.DefaultAzureCredentialBuilder;

import redis.clients.authentication.core.IdentityProvider;
import redis.clients.authentication.core.IdentityProviderConfig;
import redis.clients.authentication.core.SimpleToken;
import redis.clients.authentication.core.Token;
import redis.clients.authentication.core.TokenAuthConfig;
import redis.clients.authentication.entraid.AzureTokenAuthConfigBuilder;
import redis.clients.authentication.entraid.EntraIDIdentityProvider;
import redis.clients.authentication.entraid.EntraIDIdentityProviderConfig;
import redis.clients.authentication.entraid.EntraIDTokenAuthConfigBuilder;
Expand Down Expand Up @@ -378,4 +382,22 @@ private void triggerNetworkFailure() {
}
log.info("Action id: {}", actionResponse.getActionId());
}

@Test
public void withDefaultCredentials_azureCredentialsIntegrationTest() {
DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
TokenAuthConfig tokenAuthConfig = AzureTokenAuthConfigBuilder.builder()
.defaultAzureCredential(credential).tokenRequestExecTimeoutInMs(2000)
.build();

DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder()
.authXManager(new AuthXManager(tokenAuthConfig)).build();

try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) {
String key = UUID.randomUUID().toString();
jedis.set(key, "value");
assertEquals("value", jedis.get(key));
jedis.del(key);
Comment on lines +396 to +400
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about verifying the actual username logged in e.g. (acl whoami)
Clearer intent that we are testing auth, and prevent to some degree green test if server does not require auth

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean the username in the jedisConfig instance or hardcoding some user on specific to azure env ?
First would be the same since it already uses the one in config,, latter is kind of future maintenance issue in case of changing config or working in another setup.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can extract the expeced user from the AuthXManager used and validate that the connection is actually using it

AuthXManager manager = new AuthXManager(tokenAuthConfig);
manager.get().getUser()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggivo , sorry i just saw this one. i think both solutions does good enough for the test. What you suggest also confirms the endpoint configuration is the right one in the test setup. Would you like me to drop another PR ?

}
}
}
Loading