-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43994 from sberyozkin/oidc_token_introspection_ex…
…pired_token Check expiry of the cached OIDC token introspections
- Loading branch information
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...sions/oidc/runtime/src/test/java/io/quarkus/oidc/runtime/TokenIntrospectionCacheTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.quarkus.oidc.runtime; | ||
|
||
import static org.awaitility.Awaitility.await; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.oidc.TokenIntrospection; | ||
import io.quarkus.oidc.TokenIntrospectionCache; | ||
|
||
public class TokenIntrospectionCacheTest { | ||
TokenIntrospectionCache cache = new DefaultTokenIntrospectionUserInfoCache(createOidcConfig(), null); | ||
|
||
@Test | ||
public void testExpiredIntrospection() { | ||
|
||
TokenIntrospection introspectionValidFor10secs = new TokenIntrospection( | ||
"{\"active\": true," | ||
+ "\"exp\":" + (System.currentTimeMillis() / 1000 + 10) + "}"); | ||
TokenIntrospection introspectionValidFor3secs = new TokenIntrospection( | ||
"{\"active\": true," | ||
+ "\"exp\":" + (System.currentTimeMillis() / 1000 + 3) + "}"); | ||
cache.addIntrospection("tokenValidFor10secs", introspectionValidFor10secs, null, null); | ||
cache.addIntrospection("tokenValidFor3secs", introspectionValidFor3secs, null, null); | ||
|
||
assertNotNull(cache.getIntrospection("tokenValidFor10secs", null, null).await().indefinitely()); | ||
assertNotNull(cache.getIntrospection("tokenValidFor3secs", null, null).await().indefinitely()); | ||
|
||
await().atMost(Duration.ofSeconds(5)).pollInterval(1, TimeUnit.SECONDS) | ||
.until(new Callable<Boolean>() { | ||
|
||
@Override | ||
public Boolean call() throws Exception { | ||
return cache.getIntrospection("tokenValidFor3secs", null, null).await().indefinitely() == null; | ||
} | ||
|
||
}); | ||
|
||
assertNotNull(cache.getIntrospection("tokenValidFor10secs", null, null).await().indefinitely()); | ||
assertNull(cache.getIntrospection("tokenValidFor3secs", null, null).await().indefinitely()); | ||
} | ||
|
||
private static OidcConfig createOidcConfig() { | ||
OidcConfig cfg = new OidcConfig(); | ||
cfg.tokenCache.maxSize = 2; | ||
return cfg; | ||
} | ||
} |