28
28
import org .junit .jupiter .api .Assertions ;
29
29
import org .junit .jupiter .api .BeforeEach ;
30
30
import org .junit .jupiter .api .Test ;
31
+ import org .junit .jupiter .api .TestInfo ;
31
32
import redis .clients .jedis .Jedis ;
33
+ import redis .clients .jedis .exceptions .JedisConnectionException ;
34
+ import redis .clients .jedis .exceptions .JedisDataException ;
32
35
import redis .embedded .RedisServer ;
33
36
34
37
import java .io .IOException ;
@@ -45,13 +48,22 @@ public class RedisMetadataReportTest {
45
48
RedisMetadataReport redisMetadataReport ;
46
49
RedisMetadataReport syncRedisMetadataReport ;
47
50
RedisServer redisServer ;
51
+ URL registryUrl ;
48
52
49
53
@ BeforeEach
50
- public void constructor () throws IOException {
54
+ public void constructor (TestInfo testInfo ) throws IOException {
51
55
int redisPort = NetUtils .getAvailablePort ();
52
- this .redisServer = new RedisServer (redisPort );
56
+ String methodName = testInfo .getTestMethod ().get ().getName ();
57
+ if ("testAuthRedisMetadata" .equals (methodName ) || ("testWrongAuthRedisMetadata" .equals (methodName ))) {
58
+ String password = "チェリー" ;
59
+ redisServer = RedisServer .builder ().port (redisPort ).setting ("requirepass " + password ).build ();
60
+ registryUrl = URL .valueOf ("redis://username:" + password + "@localhost:" + redisPort );
61
+ } else {
62
+ redisServer = RedisServer .builder ().port (redisPort ).build ();
63
+ registryUrl = URL .valueOf ("redis://localhost:" + redisPort );
64
+ }
65
+
53
66
this .redisServer .start ();
54
- URL registryUrl = URL .valueOf ("redis://localhost:" + redisPort );
55
67
redisMetadataReport = (RedisMetadataReport ) new RedisMetadataReportFactory ().createMetadataReport (registryUrl );
56
68
URL asyncRegistryUrl = URL .valueOf ("redis://localhost:" + redisPort + "?" + SYNC_REPORT_KEY + "=true" );
57
69
syncRedisMetadataReport = (RedisMetadataReport ) new RedisMetadataReportFactory ().createMetadataReport (registryUrl );
@@ -173,4 +185,23 @@ private MetadataIdentifier storeConsumer(RedisMetadataReport redisMetadataReport
173
185
return consumerMetadataIdentifier ;
174
186
}
175
187
188
+ @ Test
189
+ public void testAuthRedisMetadata () throws ClassNotFoundException {
190
+ testStoreProvider (redisMetadataReport , "1.0.0.redis.md.p1" , 3000 );
191
+ }
192
+
193
+ @ Test
194
+ public void testWrongAuthRedisMetadata () throws ClassNotFoundException {
195
+ registryUrl = registryUrl .setPassword ("123456" );
196
+ redisMetadataReport = (RedisMetadataReport ) new RedisMetadataReportFactory ().createMetadataReport (registryUrl );
197
+ try {
198
+ testStoreProvider (redisMetadataReport , "1.0.0.redis.md.p1" , 3000 );
199
+ } catch (RpcException e ) {
200
+ if (e .getCause () instanceof JedisConnectionException && e .getCause ().getCause () instanceof JedisDataException ) {
201
+ Assertions .assertEquals ("ERR invalid password" , e .getCause ().getCause ().getMessage ());
202
+ } else {
203
+ Assertions .fail ("no invalid password exception!" );
204
+ }
205
+ }
206
+ }
176
207
}
0 commit comments