-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add unit and integration tests - add executor to shutdown in TokenManager (review from Ivo)
- Loading branch information
Showing
7 changed files
with
491 additions
and
158 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
entraid/src/test/java/redis/clients/authentication/EntraIDIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package redis.clients.authentication; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
import java.net.MalformedURLException; | ||
import org.junit.Test; | ||
import redis.clients.authentication.core.Token; | ||
import redis.clients.authentication.entraid.EntraIDIdentityProvider; | ||
import redis.clients.authentication.entraid.ServicePrincipalInfo; | ||
|
||
public class EntraIDIntegrationTests { | ||
|
||
|
||
@Test | ||
public void requestTokenWithSecret() throws MalformedURLException { | ||
TestContext testCtx = TestContext.DEFAULT; | ||
ServicePrincipalInfo servicePrincipalInfo = new ServicePrincipalInfo( | ||
testCtx.getClientId(), testCtx.getClientSecret(), | ||
testCtx.getAuthority()); | ||
Token token = new EntraIDIdentityProvider(servicePrincipalInfo, | ||
testCtx.getRedisScopes()).requestToken(); | ||
|
||
assertNotNull(token.getValue()); | ||
} | ||
|
||
@Test | ||
public void requestTokenWithCert() throws MalformedURLException { | ||
TestContext testCtx = TestContext.DEFAULT; | ||
ServicePrincipalInfo servicePrincipalInfo = new ServicePrincipalInfo( | ||
testCtx.getClientId(), testCtx.getPrivateKey(), testCtx.getCert(), | ||
testCtx.getAuthority()); | ||
Token token = new EntraIDIdentityProvider(servicePrincipalInfo, | ||
testCtx.getRedisScopes()).requestToken(); | ||
assertNotNull(token.getValue()); | ||
} | ||
|
||
} |
120 changes: 102 additions & 18 deletions
120
entraid/src/test/java/redis/clients/authentication/RedisEntraIDIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,120 @@ | ||
package redis.clients.authentication; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertEquals; | ||
import java.util.UUID; | ||
|
||
import java.net.MalformedURLException; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import redis.clients.authentication.core.Token; | ||
import redis.clients.authentication.entraid.EntraIDIdentityProvider; | ||
import redis.clients.authentication.entraid.ServicePrincipalInfo; | ||
import redis.clients.authentication.core.TokenAuthConfig; | ||
import redis.clients.authentication.entraid.EntraIDTokenAuthConfigBuilder; | ||
import redis.clients.authentication.entraid.ManagedIdentityInfo.UserManagedIdentityType; | ||
import redis.clients.jedis.DefaultJedisClientConfig; | ||
import redis.clients.jedis.HostAndPort; | ||
import redis.clients.jedis.JedisPooled; | ||
|
||
public class RedisEntraIDIntegrationTests { | ||
private static final Logger log = LoggerFactory | ||
.getLogger(RedisEntraIDIntegrationTests.class); | ||
|
||
private static TestContext testCtx; | ||
private static EndpointConfig endpointConfig; | ||
private static HostAndPort hnp; | ||
|
||
@BeforeClass | ||
public static void before() { | ||
try { | ||
testCtx = TestContext.DEFAULT; | ||
endpointConfig = testCtx.getRedisEndpoint("standalone-entraid-acl1"); | ||
hnp = endpointConfig.getHostAndPort(); | ||
} catch (IllegalArgumentException e) { | ||
log.warn("Skipping test because no Redis endpoint is configured"); | ||
org.junit.Assume.assumeTrue(false); | ||
} | ||
} | ||
|
||
// T.1.1 | ||
// Verify authentication using Azure AD with managed identities | ||
@Test | ||
public void withUserAssignedId_azureManagedIdentityIntegrationTest() { | ||
TokenAuthConfig tokenAuthConfig = EntraIDTokenAuthConfigBuilder.builder() | ||
.clientId(testCtx.getClientId()) | ||
.userAssignedManagedIdentity(UserManagedIdentityType.CLIENT_ID, | ||
"userManagedAuthxId") | ||
.authority(testCtx.getAuthority()).scopes(testCtx.getRedisScopes()) | ||
.build(); | ||
|
||
DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder() | ||
.tokenAuthConfig(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); | ||
} | ||
} | ||
|
||
// T.1.1 | ||
// Verify authentication using Azure AD with managed identities | ||
@Test | ||
public void requestTokenWithSecret() throws MalformedURLException { | ||
TestContext testCtx = TestContext.DEFAULT; | ||
public void withSystemAssignedId_azureManagedIdentityIntegrationTest() { | ||
TokenAuthConfig tokenAuthConfig = EntraIDTokenAuthConfigBuilder.builder() | ||
.clientId(testCtx.getClientId()).systemAssignedManagedIdentity() | ||
.authority(testCtx.getAuthority()).scopes(testCtx.getRedisScopes()) | ||
.build(); | ||
|
||
Token token = new EntraIDIdentityProvider( | ||
new ServicePrincipalInfo(testCtx.getClientId(), | ||
testCtx.getClientSecret(), testCtx.getAuthority()), | ||
testCtx.getRedisScopes()).requestToken(); | ||
DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder() | ||
.tokenAuthConfig(tokenAuthConfig).build(); | ||
|
||
assertNotNull(token.getValue()); | ||
try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) { | ||
String key = UUID.randomUUID().toString(); | ||
jedis.set(key, "value"); | ||
assertEquals("value", jedis.get(key)); | ||
jedis.del(key); | ||
} | ||
} | ||
|
||
// T.1.1 | ||
// Verify authentication using Azure AD with service principals | ||
@Test | ||
public void requestTokenWithCert() throws MalformedURLException { | ||
TestContext testCtx = TestContext.DEFAULT; | ||
public void withSecret_azureServicePrincipalIntegrationTest() { | ||
TokenAuthConfig tokenAuthConfig = EntraIDTokenAuthConfigBuilder.builder() | ||
.clientId(testCtx.getClientId()).secret(testCtx.getClientSecret()) | ||
.authority(testCtx.getAuthority()).scopes(testCtx.getRedisScopes()) | ||
.build(); | ||
|
||
Token token = new EntraIDIdentityProvider(new ServicePrincipalInfo( | ||
testCtx.getClientId(), testCtx.getPrivateKey(), testCtx.getCert(), | ||
testCtx.getAuthority()), testCtx.getRedisScopes()).requestToken(); | ||
DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder() | ||
.tokenAuthConfig(tokenAuthConfig).build(); | ||
|
||
assertNotNull(token.getValue()); | ||
try (JedisPooled jedis = new JedisPooled(hnp, jedisConfig)) { | ||
String key = UUID.randomUUID().toString(); | ||
jedis.set(key, "value"); | ||
assertEquals("value", jedis.get(key)); | ||
jedis.del(key); | ||
} | ||
} | ||
|
||
// T.1.1 | ||
// Verify authentication using Azure AD with service principals | ||
@Test | ||
public void withCertificate_azureServicePrincipalIntegrationTest() { | ||
TokenAuthConfig tokenAuthConfig = EntraIDTokenAuthConfigBuilder.builder() | ||
.clientId(testCtx.getClientId()).secret(testCtx.getClientSecret()) | ||
.authority(testCtx.getAuthority()).scopes(testCtx.getRedisScopes()) | ||
.build(); | ||
|
||
DefaultJedisClientConfig jedisConfig = DefaultJedisClientConfig.builder() | ||
.tokenAuthConfig(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); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.