-
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.
Align behavior for getDeferredIdentity and getIdentity in TestIdentit…
…yAssociation Signed-off-by: Christian von Atzigen <[email protected]>
- Loading branch information
1 parent
4dd3936
commit 81fb692
Showing
4 changed files
with
103 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,14 +26,14 @@ public class TestSecurityLazyAuthTest { | |
@TestSecurity(user = "user1", roles = "viewer") | ||
public void testWithDummyUser() { | ||
RestAssured.when().get("test-security").then() | ||
.body(is("user1:user1:user1")); | ||
.body(is("user1:user1:user1:user1")); | ||
} | ||
|
||
@Test | ||
@TestSecurityMetaAnnotation | ||
public void testJwtWithDummyUser() { | ||
RestAssured.when().get("test-security-oidc").then() | ||
.body(is("userOidc:userOidc:userOidc:viewer:[email protected]:subject:aud")); | ||
.body(is("userOidc:userOidc:userOidc:userOidc:viewer:[email protected]:subject:aud")); | ||
} | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
|
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
90 changes: 90 additions & 0 deletions
90
...ramework/security/src/test/java/io/quarkus/test/security/TestIdentityAssociationTest.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,90 @@ | ||
package io.quarkus.test.security; | ||
|
||
import static io.quarkus.security.runtime.QuarkusSecurityIdentity.builder; | ||
import static org.junit.jupiter.api.Assertions.assertSame; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.runtime.BlockingOperationControl; | ||
import io.quarkus.runtime.IOThreadDetector; | ||
import io.quarkus.security.identity.SecurityIdentity; | ||
import io.quarkus.security.runtime.QuarkusPrincipal; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class TestIdentityAssociationTest { | ||
|
||
TestIdentityAssociation sut; | ||
|
||
@BeforeEach | ||
void init() { | ||
sut = new TestIdentityAssociation(); | ||
sut.delegate = new DelegateSecurityIdentityAssociation(); | ||
|
||
BlockingOperationControl.setIoThreadDetector(new IOThreadDetector[0]); | ||
} | ||
|
||
@Test | ||
void useDelegateIfTestIdentityIsNull() { | ||
// create anonymous identity | ||
SecurityIdentity mockedIdentity = builder().setAnonymous(true).build(); | ||
Uni<SecurityIdentity> mockedIdentityUni = Uni.createFrom().item(mockedIdentity); | ||
sut.setIdentity(mockedIdentity); | ||
sut.setIdentity(mockedIdentityUni); | ||
|
||
// reset testIdentity | ||
sut.setTestIdentity(null); | ||
|
||
// get identity direct + deferred | ||
SecurityIdentity deferred = sut.getDeferredIdentity().await().indefinitely(); | ||
SecurityIdentity identity = sut.getIdentity(); | ||
|
||
// must be the same instance | ||
assertSame(identity, deferred, "Must be same instance directly and deferred"); | ||
assertSame(mockedIdentity, identity, "Expected delegate. (TestIdentity is null)"); | ||
} | ||
|
||
@Test | ||
void useTestIdentityIfDelegateIsAnonymous() { | ||
// create anonymous identity | ||
SecurityIdentity mockedIdentity = builder().setAnonymous(true).build(); | ||
Uni<SecurityIdentity> mockedIdentityUni = Uni.createFrom().item(mockedIdentity); | ||
// create test identity | ||
SecurityIdentity mockedTestIdentity = builder().setPrincipal(new QuarkusPrincipal("test-identity")).build(); | ||
sut.setIdentity(mockedIdentity); | ||
sut.setIdentity(mockedIdentityUni); | ||
|
||
// reset testIdentity | ||
sut.setTestIdentity(mockedTestIdentity); | ||
|
||
// get identity direct + deferred | ||
SecurityIdentity deferred = sut.getDeferredIdentity().await().indefinitely(); | ||
SecurityIdentity identity = sut.getIdentity(); | ||
|
||
// must be the same instance | ||
assertSame(identity, deferred, "Must be same instance directly and deferred"); | ||
assertSame(mockedTestIdentity, identity, "Expected testIdentity. (Delegate is anonymous)"); | ||
} | ||
|
||
@Test | ||
void useDelegateIfNotAnonymous() { | ||
// create identity with principal | ||
SecurityIdentity mockedIdentity = builder().setPrincipal(new QuarkusPrincipal("delegate")).build(); | ||
Uni<SecurityIdentity> mockedIdentityUni = Uni.createFrom().item(mockedIdentity); | ||
// create test identity | ||
SecurityIdentity mockedTestIdentity = builder().setPrincipal(new QuarkusPrincipal("test-identity")).build(); | ||
sut.setIdentity(mockedIdentity); | ||
sut.setIdentity(mockedIdentityUni); | ||
|
||
// reset testIdentity | ||
sut.setTestIdentity(mockedTestIdentity); | ||
|
||
// get identity direct + deferred | ||
SecurityIdentity deferred = sut.getDeferredIdentity().await().indefinitely(); | ||
SecurityIdentity identity = sut.getIdentity(); | ||
|
||
// must be the same instance | ||
assertSame(identity, deferred, "Must be same instance directly and deferred"); | ||
assertSame(mockedIdentity, identity, "Expected delegate. (Delegate is not anonymous)"); | ||
} | ||
} |