Skip to content

Commit

Permalink
ERR invalid password when creating a RedisURI with a username #131
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Sep 8, 2015
1 parent f90ee8d commit 56fc38d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/com/lambdaworks/redis/RedisURI.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,16 @@ public static RedisURI create(URI uri) {
String password = userInfo;
if (password.startsWith(":")) {
password = password.substring(1);
} else {

int index = password.indexOf(':');
if (index > 0) {
password = password.substring(index + 1);
}
}
if (password != null && !password.equals("")) {
builder.withPassword(password);
}
builder.withPassword(password);
}

if (isNotEmpty(uri.getPath()) && builder.redisURI.getSocket() == null) {
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/lambdaworks/redis/RedisURIBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ public void redisFromUrl() throws Exception {
assertThat(result.isSsl()).isFalse();
}

@Test
public void redisFromUrlNoPassword() throws Exception {
RedisURI redisURI = RedisURI.create("redis://localhost:1234/5");
assertThat(redisURI.getPassword()).isNull();

redisURI = RedisURI.create("redis://h:@localhost.com:14589");
assertThat(redisURI.getPassword()).isNull();

}

@Test
public void redisFromUrlPassword() throws Exception {
RedisURI redisURI = RedisURI.create("redis://h:[email protected]:14589");
assertThat(redisURI.getPassword()).isEqualTo("password".toCharArray());
}

@Test
public void redisSslFromUrl() throws Exception {
RedisURI result = RedisURI.create(RedisURI.URI_SCHEME_REDIS_SECURE + "://:password@localhost/1");
Expand Down Expand Up @@ -129,4 +145,5 @@ public void redisSocketWithPassword() throws Exception {
assertThat(result.getPort()).isEqualTo(0);
assertThat(result.isSsl()).isFalse();
}

}

0 comments on commit 56fc38d

Please sign in to comment.