This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/2.1 by this push:
     new 523ec44b61 fixes test failure for AuthenticationTokenSecretManager 
(#4997)
523ec44b61 is described below

commit 523ec44b613f3335c8fa293a6f619a0e37aa2723
Author: Keith Turner <ktur...@apache.org>
AuthorDate: Thu Oct 17 20:25:29 2024 -0400

    fixes test failure for AuthenticationTokenSecretManager (#4997)
    
    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)
    ```
---
 .../security/delegation/AuthenticationTokenSecretManager.java  | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git 
a/server/base/src/main/java/org/apache/accumulo/server/security/delegation/AuthenticationTokenSecretManager.java
 
b/server/base/src/main/java/org/apache/accumulo/server/security/delegation/AuthenticationTokenSecretManager.java
index 52d73553ae..a6d24b96cd 100644
--- 
a/server/base/src/main/java/org/apache/accumulo/server/security/delegation/AuthenticationTokenSecretManager.java
+++ 
b/server/base/src/main/java/org/apache/accumulo/server/security/delegation/AuthenticationTokenSecretManager.java
@@ -82,7 +82,7 @@ public class AuthenticationTokenSecretManager extends 
SecretManager<Authenticati
       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);
@@ -104,8 +104,7 @@ public class AuthenticationTokenSecretManager extends 
SecretManager<Authenticati
     return createPassword(identifier);
   }
 
-  private long calculateExpirationDate() {
-    long now = System.currentTimeMillis();
+  private long calculateExpirationDate(long now) {
     long expiration = now + tokenMaxLifetime;
     // Catch overflow
     if (expiration < now) {
@@ -123,11 +122,12 @@ public class AuthenticationTokenSecretManager extends 
SecretManager<Authenticati
     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());
   }

Reply via email to