DATAREDIS-1046 - Use ACL authentication when username is configured.
Upgrade to Redis 6 for tests. Introduce support for username in configurations that support authentication. Original Pull Request: #558
This commit is contained in:
committed by
Christoph Strobl
parent
da5bab1fb2
commit
d97c5df130
@@ -41,6 +41,7 @@ public class RedisTestProfileValueSource implements ProfileValueSource {
|
||||
private static final String REDIS_30 = "3.0";
|
||||
private static final String REDIS_32 = "3.2";
|
||||
private static final String REDIS_50 = "5.0";
|
||||
private static final String REDIS_60 = "6.0";
|
||||
private static final String REDIS_VERSION_KEY = "redisVersion";
|
||||
|
||||
private static RedisTestProfileValueSource INSTANCE;
|
||||
@@ -97,6 +98,10 @@ public class RedisTestProfileValueSource implements ProfileValueSource {
|
||||
return System.getProperty(key);
|
||||
}
|
||||
|
||||
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_60)) >= 0) {
|
||||
return REDIS_60;
|
||||
}
|
||||
|
||||
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_50)) >= 0) {
|
||||
return REDIS_50;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.connection.jedis;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
|
||||
/**
|
||||
* Integration tests for Redis 6 ACL.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class JedisAclIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
assumeTrue(RedisTestProfileValueSource.atLeast("redisVersion", "6.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldConnectWithDefaultAuthentication() {
|
||||
|
||||
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6382);
|
||||
standaloneConfiguration.setPassword("foobared");
|
||||
|
||||
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(standaloneConfiguration);
|
||||
connectionFactory.afterPropertiesSet();
|
||||
|
||||
RedisConnection connection = connectionFactory.getConnection();
|
||||
|
||||
assertThat(connection.ping()).isEqualTo("PONG");
|
||||
connection.close();
|
||||
|
||||
connectionFactory.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1046
|
||||
public void shouldConnectStandaloneWithAclAuthentication() {
|
||||
|
||||
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6382);
|
||||
standaloneConfiguration.setUsername("spring");
|
||||
standaloneConfiguration.setPassword("data");
|
||||
|
||||
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(standaloneConfiguration);
|
||||
connectionFactory.afterPropertiesSet();
|
||||
|
||||
RedisConnection connection = connectionFactory.getConnection();
|
||||
|
||||
assertThat(connection.ping()).isEqualTo("PONG");
|
||||
connection.close();
|
||||
|
||||
connectionFactory.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1046
|
||||
public void shouldConnectStandaloneWithAclAuthenticationAndPooling() {
|
||||
|
||||
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6382);
|
||||
standaloneConfiguration.setUsername("spring");
|
||||
standaloneConfiguration.setPassword("data");
|
||||
|
||||
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(standaloneConfiguration);
|
||||
connectionFactory.setUsePool(true);
|
||||
connectionFactory.afterPropertiesSet();
|
||||
|
||||
RedisConnection connection = connectionFactory.getConnection();
|
||||
|
||||
assertThat(connection.ping()).isEqualTo("PONG");
|
||||
connection.close();
|
||||
|
||||
connectionFactory.destroy();
|
||||
}
|
||||
}
|
||||
@@ -22,24 +22,22 @@ import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Integration test of {@link AuthenticatingRedisClient}. Enable requirepass and comment out the @Ignore to run.
|
||||
* Integration test of {@link AuthenticatingRedisClient}.
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@Ignore("Redis must have requirepass set to run this test")
|
||||
public class AuthenticatingRedisClientTests {
|
||||
|
||||
private RedisClient client;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
client = new AuthenticatingRedisClient("localhost", "foo");
|
||||
client = new AuthenticatingRedisClient("localhost", 6382, "foobared");
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -63,7 +61,7 @@ public class AuthenticatingRedisClientTests {
|
||||
client.shutdown();
|
||||
}
|
||||
|
||||
RedisClient badClient = new AuthenticatingRedisClient("localhost", "notthepassword");
|
||||
RedisClient badClient = new AuthenticatingRedisClient("localhost", 6382, "notthepassword");
|
||||
badClient.connect();
|
||||
}
|
||||
|
||||
|
||||
@@ -171,16 +171,6 @@ public class DefaultLettucePoolTests {
|
||||
pool.getResource();
|
||||
}
|
||||
|
||||
@Test(expected = PoolException.class)
|
||||
public void testCreateWithPasswordNoPassword() {
|
||||
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.setPassword("notthepassword");
|
||||
pool.afterPropertiesSet();
|
||||
pool.getResource();
|
||||
}
|
||||
|
||||
@Ignore("Redis must have requirepass set to run this test")
|
||||
@Test
|
||||
public void testCreatePassword() {
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.RedisStaticMasterReplicaConfiguration;
|
||||
|
||||
/**
|
||||
* Integration tests for Redis 6 ACL.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class LettuceAclIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
assumeTrue(RedisTestProfileValueSource.atLeast("redisVersion", "6.0"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1046
|
||||
public void shouldConnectWithDefaultAuthentication() {
|
||||
|
||||
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6382);
|
||||
standaloneConfiguration.setPassword("foobared");
|
||||
|
||||
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(standaloneConfiguration);
|
||||
connectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
connectionFactory.afterPropertiesSet();
|
||||
|
||||
RedisConnection connection = connectionFactory.getConnection();
|
||||
|
||||
assertThat(connection.ping()).isEqualTo("PONG");
|
||||
connection.close();
|
||||
|
||||
connectionFactory.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1046
|
||||
public void shouldConnectStandaloneWithAclAuthentication() {
|
||||
|
||||
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6382);
|
||||
standaloneConfiguration.setUsername("spring");
|
||||
standaloneConfiguration.setPassword("data");
|
||||
|
||||
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(standaloneConfiguration);
|
||||
connectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
connectionFactory.afterPropertiesSet();
|
||||
|
||||
RedisConnection connection = connectionFactory.getConnection();
|
||||
|
||||
assertThat(connection.ping()).isEqualTo("PONG");
|
||||
connection.close();
|
||||
|
||||
connectionFactory.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1046
|
||||
@Ignore("https://github.com/lettuce-io/lettuce-core/issues/1406")
|
||||
public void shouldConnectMasterReplicaWithAclAuthentication() {
|
||||
|
||||
RedisStaticMasterReplicaConfiguration masterReplicaConfiguration = new RedisStaticMasterReplicaConfiguration(
|
||||
"localhost", 6382);
|
||||
masterReplicaConfiguration.setUsername("spring");
|
||||
masterReplicaConfiguration.setPassword("data");
|
||||
|
||||
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(masterReplicaConfiguration);
|
||||
connectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
connectionFactory.afterPropertiesSet();
|
||||
|
||||
RedisConnection connection = connectionFactory.getConnection();
|
||||
|
||||
assertThat(connection.ping()).isEqualTo("PONG");
|
||||
connection.close();
|
||||
|
||||
connectionFactory.destroy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user