Skip to content

Commit

Permalink
beef up test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelandis committed Nov 6, 2023
1 parent 24a746f commit 89519b1
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,24 @@ public void testJwtAuthcRealmAuthcAuthzWithEmptyRoles() throws Exception {
doMultipleAuthcAuthzAndVerifySuccess(jwtIssuerAndRealm.realm(), user, jwt, clientSecret, jwtAuthcCount);
}

// this test is mostly a duplicate of others tests but this test guarantees the cache is used which invoke downstream assertions
// https://github.com/elastic/elasticsearch/issues/101752
public void testJwtCache() throws Exception {
jwtIssuerAndRealms = generateJwtIssuerRealmPairs(1, 1, 1, 1, 1, 1, 99, false);
JwtRealm realm = jwtIssuerAndRealms.get(0).realm();
realm.expireAll();
assertThat(realm.getJwtCache().count(), is(0));
final JwtIssuerAndRealm jwtIssuerAndRealm = randomJwtIssuerRealmPair();
final User user = randomUser(jwtIssuerAndRealm.issuer());
final SecureString jwt = randomJwt(jwtIssuerAndRealm, user);
final SecureString clientSecret = JwtRealmInspector.getClientAuthenticationSharedSecret(jwtIssuerAndRealm.realm());
doMultipleAuthcAuthzAndVerifySuccess(jwtIssuerAndRealm.realm(), user, jwt, clientSecret, 10);
for (int i = 1; i <= randomIntBetween(2, 10); i++) {
User user = randomUser(jwtIssuerAndRealm.issuer());
doMultipleAuthcAuthzAndVerifySuccess(
jwtIssuerAndRealm.realm(),
user,
randomJwt(jwtIssuerAndRealm, user),
clientSecret,
randomIntBetween(2, 10)
);
assertThat(realm.getJwtCache().count(), is(i));
}
}

/**
Expand Down

0 comments on commit 89519b1

Please sign in to comment.