Skip to content

Commit

Permalink
Add OidcTestSecurityAugmentor UserInfo unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Nov 29, 2024
1 parent 0f88242 commit a576c24
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 a576c24

Please sign in to comment.