Skip to content

Commit

Permalink
fixes test failure for AuthenticationTokenSecretManager
Browse files Browse the repository at this point in the history
AuthenticationTokenSecretManager was calling System.currentTimeMillis()
twice causing the following test sporadic failure. Modified to only get
time once to avoid test failure.

```
[ERROR] org.apache.accumulo.server.security.delegation.AuthenticationTokenSecretManagerTest.testGenerateToken -- Time elapsed: 0.011 s <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <1729199138567> but was: <1729199138568>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:166)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:161)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:632)
	at org.apache.accumulo.server.security.delegation.AuthenticationTokenSecretManagerTest.testGenerateToken(AuthenticationTokenSecretManagerTest.java:174)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
```
  • Loading branch information
keith-turner committed Oct 17, 2024
1 parent b3ec422 commit f4313ca
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private byte[] createPassword(AuthenticationTokenIdentifier identifier,
DelegationTokenConfig cfg) {
long now = System.currentTimeMillis();
identifier.setIssueDate(now);
identifier.setExpirationDate(calculateExpirationDate());
identifier.setExpirationDate(calculateExpirationDate(now));
// Limit the lifetime if the user requests it
if (cfg != null) {
long requestedLifetime = cfg.getTokenLifetime(TimeUnit.MILLISECONDS);
Expand All @@ -104,8 +104,7 @@ private byte[] createPassword(AuthenticationTokenIdentifier identifier,
return createPassword(identifier);
}

private long calculateExpirationDate() {
long now = System.currentTimeMillis();
private long calculateExpirationDate(long now) {
long expiration = now + tokenMaxLifetime;
// Catch overflow
if (expiration < now) {
Expand All @@ -123,11 +122,12 @@ protected byte[] createPassword(AuthenticationTokenIdentifier identifier) {
identifier.setKeyId(secretKey.getKeyId());
identifier.setInstanceId(instanceID);

long now = System.currentTimeMillis();
if (!identifier.isSetIssueDate()) {
identifier.setIssueDate(System.currentTimeMillis());
identifier.setIssueDate(now);
}
if (!identifier.isSetExpirationDate()) {
identifier.setExpirationDate(calculateExpirationDate());
identifier.setExpirationDate(calculateExpirationDate(now));
}
return createPassword(identifier.getBytes(), secretKey.getKey());
}
Expand Down

0 comments on commit f4313ca

Please sign in to comment.