vert-x3 / vertx-redis-client

Redis client for Vert.x
http://vertx.io
Apache License 2.0
131 stars 119 forks source link

Specified username login failed #348

Closed leotu closed 2 years ago

leotu commented 2 years ago

Questions

Log in to Redis instead of using the default user, use the specified username connected failed

For example: app.redislabs.com Would create specified username & password

Version

  <artifactId>vertx-redis-client</artifactId>
  <version>4.3.2</version>

Context

Redis.createClient

redis://[username:password@][host][:port][/database]

Maybe some problem at:

Redis ACL (https://redis.io/docs/manual/security/acl/)

AUTH <username> <password>

Steps to reproduce

  1. Test Code
class TestRedisClient {
    private static final Logger log = LoggerFactory.getLogger(TestRedisClient.class);

    @Test
    void test() {
        log.debug("Begin...");
        CountDownLatch latch = new CountDownLatch(1);
        try {
            Vertx vertx = Vertx.vertx();

            String username = URLEncoder.encode("xxx", StandardCharsets.UTF_8);
            String password = URLEncoder.encode("zzz", StandardCharsets.UTF_8);

            String connectionString = "redis://" + username + ":" + password + "@redis-10770.c60.us-west-1-2.ec2.cloud.redislabs.com:10770/0";

           Redis.createClient(vertx, connectionString)
                    .connect()
                    .onSuccess(conn -> {
                        log.debug("onSuccess, conn: {}", conn);
                        latch.countDown();
                    })
                    .onFailure(err -> {
                        log.error("onFailure", err);
                        latch.countDown();
                    });

            log.debug("Before await");
            latch.await();
            log.debug("After await");
        } catch (Exception e) {
            log.error(e.toString());
        } finally {
            log.debug("End.");
        }
    }
}
  1. Console error log
23:03:43.231 DEBUG [main] [com.xgosh.test.TestRedisClient:20,test()] Begin...
23:03:43.484 DEBUG [main] [com.xgosh.test.TestRedisClient:39,test()] Before await
23:03:44.245 ERROR [vert.x-eventloop-thread-0] [com.xgosh.test.TestRedisClient:35,lambda$1()] onFailure: WRONGPASS invalid username-password pair

23:03:44.247 DEBUG [main] [com.xgosh.test.TestRedisClient:41,test()] After await
23:03:44.247 DEBUG [main] [com.xgosh.test.TestRedisClient:45,test()] End.

Extra Info

截圖 2022-09-16 22 30 36 截圖 2022-09-16 22 31 10
pmlopes commented 2 years ago

@leotu ~are you encoding the username / password special chars in URL format?~ If that still doesn't work can you privately provide a test account for me to test and debug the issue?

leotu commented 2 years ago

@pmlopes

I create new account for your

String username = URLEncoder.encode("demo", StandardCharsets.UTF_8);
String password = URLEncoder.encode("demo123~X", StandardCharsets.UTF_8);

String connectionString = "redis://" + username + ":" + password + "@redis-14177.c11.us-east-1-2.ec2.cloud.redislabs.com:14177/0";

// "redis://demo:demo123%7EX@redis-14177.c11.us-east-1-2.ec2.cloud.redislabs.com:14177/0"
pmlopes commented 2 years ago

@leotu I'm running the test with the latest git code and I can connect and execute commands such as INFO. I believe the issue was fixed on ac116b7bb7999593e787804a76cd55fb2291c3c6 and 22ce171a1682cf086b7160b9294f53db000db713

leotu commented 2 years ago

Great !

I face this problem when that I run Quarkus version "2.12.2.Final", but it includes "vertx-redis-client" version "4.3.2". (redis-reference)