Skip to content

Commit

Permalink
review from @ggivo
Browse files Browse the repository at this point in the history
- use getuser instead oid from Token
  • Loading branch information
atakavci committed Dec 12, 2024
1 parent 2175c15 commit 86cf6f6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void start() {
try {
safeStarter.get();
} catch (InterruptedException | ExecutionException e) {
log.error("AuthXManager failed to start!", e);
throw new JedisAuthenticationException("AuthXManager failed to start!",
(e instanceof ExecutionException) ? e.getCause() : e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TokenCredentials implements RedisCredentials {
private final char[] password;

public TokenCredentials(Token token) {
user = token.tryGet("oid");
user = token.getUser();
password = token.getValue().toCharArray();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -96,8 +95,8 @@ public void testJedisConfig() {
assertNotNull(mock);
doAnswer(invocation -> {
counter.incrementAndGet();
return new SimpleToken("token1", System.currentTimeMillis() + 5 * 60 * 1000,
System.currentTimeMillis(), Collections.singletonMap("oid", "default"));
return new SimpleToken("default", "token1", System.currentTimeMillis() + 5 * 60 * 1000,
System.currentTimeMillis(), null);
}).when(mock).requestToken();
})) {

Expand Down Expand Up @@ -312,9 +311,8 @@ public void connectionAuthWithExpiredTokenTest() {
jedis.del(key);
}

token
.set(new SimpleToken("token1", System.currentTimeMillis() - 1, System.currentTimeMillis(),
Collections.singletonMap("oid", idp.requestToken().tryGet("oid"))));
token.set(new SimpleToken(idp.requestToken().getUser(), "token1",
System.currentTimeMillis() - 1, System.currentTimeMillis(), null));

JedisAccessControlException aclException = assertThrows(JedisAccessControlException.class,
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public IdentityProvider getProvider() {
return new IdentityProvider() {
@Override
public Token requestToken() {
return new SimpleToken("cluster", System.currentTimeMillis() + 5 * 1000,
System.currentTimeMillis(),
Collections.singletonMap("oid", "default"));
return new SimpleToken("default", "cluster",
System.currentTimeMillis() + 5 * 1000, System.currentTimeMillis(),
null);
}
};
}
Expand Down Expand Up @@ -77,9 +77,9 @@ public IdentityProvider getProvider() {
return new IdentityProvider() {
@Override
public Token requestToken() {
return new SimpleToken("cluster", System.currentTimeMillis() + 5 * 1000,
System.currentTimeMillis(),
Collections.singletonMap("oid", "default"));
return new SimpleToken("default", "cluster",
System.currentTimeMillis() + 5 * 1000, System.currentTimeMillis(),
null);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static org.hamcrest.Matchers.contains;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -64,8 +63,8 @@ public void testJedisPooledForInitialAuth() {

IdentityProvider idProvider = mock(IdentityProvider.class);
when(idProvider.requestToken())
.thenReturn(new SimpleToken(password, System.currentTimeMillis() + 100000,
System.currentTimeMillis(), Collections.singletonMap("oid", user)));
.thenReturn(new SimpleToken(user, password, System.currentTimeMillis() + 100000,
System.currentTimeMillis(), null));

IdentityProviderConfig idProviderConfig = mock(IdentityProviderConfig.class);
when(idProviderConfig.getProvider()).thenReturn(idProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void withExpirationRefreshRatio_testJedisAuthXManagerTriggersEvict() thro

IdentityProvider idProvider = mock(IdentityProvider.class);
when(idProvider.requestToken())
.thenReturn(new SimpleToken("password", System.currentTimeMillis() + 1000,
.thenReturn(new SimpleToken("default","password", System.currentTimeMillis() + 1000,
System.currentTimeMillis(), Collections.singletonMap("oid", "default")));

TokenManager tokenManager = new TokenManager(idProvider,
Expand All @@ -88,7 +88,7 @@ public void withLowerRefreshBounds_testJedisAuthXManagerTriggersEvict() throws E

IdentityProvider idProvider = mock(IdentityProvider.class);
when(idProvider.requestToken())
.thenReturn(new SimpleToken("password", System.currentTimeMillis() + 1000,
.thenReturn(new SimpleToken("default","password", System.currentTimeMillis() + 1000,
System.currentTimeMillis(), Collections.singletonMap("oid", "default")));

TokenManager tokenManager = new TokenManager(idProvider,
Expand Down Expand Up @@ -205,7 +205,7 @@ public void testCalculateRenewalDelay() {
public void testAuthXManagerReceivesNewToken()
throws InterruptedException, ExecutionException, TimeoutException {

IdentityProvider identityProvider = () -> new SimpleToken("tokenVal",
IdentityProvider identityProvider = () -> new SimpleToken("user1","tokenVal",
System.currentTimeMillis() + 5 * 1000, System.currentTimeMillis(),
Collections.singletonMap("oid", "user1"));

Expand Down Expand Up @@ -277,7 +277,7 @@ public void testTokenManagerWithFailingTokenRequest()
if (requesLatch.getCount() > 0) {
throw new RuntimeException("Test exception from identity provider!");
}
return new SimpleToken("tokenValX", System.currentTimeMillis() + 50 * 1000,
return new SimpleToken("user1","tokenValX", System.currentTimeMillis() + 50 * 1000,
System.currentTimeMillis(), Collections.singletonMap("oid", "user1"));
});

Expand Down Expand Up @@ -313,7 +313,7 @@ public void testTokenManagerWithHangingTokenRequest()
}
return null;
}
return new SimpleToken("tokenValX", System.currentTimeMillis() + tokenLifetime,
return new SimpleToken("user1","tokenValX", System.currentTimeMillis() + tokenLifetime,
System.currentTimeMillis(), Collections.singletonMap("oid", "user1"));
};

Expand Down

0 comments on commit 86cf6f6

Please sign in to comment.