Skip to content

Commit

Permalink
Merge pull request #44835 from sberyozkin/oidc_security_userinfo_test
Browse files Browse the repository at this point in the history
Add OidcTestSecurityAugmentor UserInfo unit test
  • Loading branch information
sberyozkin authored Nov 29, 2024
2 parents b0c3678 + a576c24 commit ca98b70
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.test.security.oidc;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -73,4 +74,31 @@ public String getName() {
assertEquals("2", map.getString("b"));
}

@Test
@OidcSecurity(userinfo = {
@UserInfo(key = "sub", value = "subject")
})
public void testUserInfo() throws Exception {
SecurityIdentity identity = QuarkusSecurityIdentity.builder()
.setPrincipal(new Principal() {
@Override
public String getName() {
return "alice";
}

})
.build();

OidcTestSecurityIdentityAugmentor augmentor = new OidcTestSecurityIdentityAugmentor(Optional.of("https://issuer.org"));

Annotation[] annotations = OidcTestSecurityIdentityAugmentorTest.class.getMethod("testUserInfo").getAnnotations();
SecurityIdentity augmentedIdentity = augmentor.augment(identity, annotations);
JsonWebToken jwt = (JsonWebToken) augmentedIdentity.getPrincipal();
assertEquals("alice", jwt.getName());

io.quarkus.oidc.UserInfo userInfo = augmentedIdentity.getAttribute("userinfo");
assertNotNull(userInfo);
assertEquals("subject", userInfo.getSubject());
}

}

0 comments on commit ca98b70

Please sign in to comment.