-
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.
Validate Startup observers are not secured with RBAC annotations
- Loading branch information
1 parent
d110270
commit cc4f5ac
Showing
3 changed files
with
158 additions
and
3 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
82 changes: 82 additions & 0 deletions
82
...nt/src/test/java/io/quarkus/security/test/cdi/SecurityAnnotationOnObservedMethodTest.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,82 @@ | ||
package io.quarkus.security.test.cdi; | ||
|
||
import jakarta.annotation.security.PermitAll; | ||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.runtime.Startup; | ||
import io.quarkus.runtime.StartupEvent; | ||
import io.quarkus.security.Authenticated; | ||
import io.quarkus.security.PermissionsAllowed; | ||
import io.quarkus.security.test.utils.AuthData; | ||
import io.quarkus.security.test.utils.IdentityMock; | ||
import io.quarkus.security.test.utils.SecurityTestUtils; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class SecurityAnnotationOnObservedMethodTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(StartupMethodBean.class, IdentityMock.class, PermitAllEagerAppBean.class, | ||
AuthData.class, SecurityTestUtils.class, EagerAppBean.class)) | ||
.assertException(throwable -> { | ||
String errorMsg = throwable.getMessage(); | ||
Assertions.assertTrue(errorMsg.contains("StartupMethodBean#packagePrivateClassAnnotatedMethod")); | ||
Assertions.assertTrue(errorMsg.contains("StartupMethodBean#publicInit")); | ||
Assertions.assertTrue(errorMsg.contains("EagerAppBean")); | ||
Assertions.assertFalse(errorMsg.contains("packagePrivateInit")); | ||
Assertions.assertFalse(errorMsg.contains("permittedInit")); | ||
Assertions.assertFalse(errorMsg.contains("PermitAllEagerAppBean")); | ||
}); | ||
|
||
@Test | ||
public void test() { | ||
// must be here to run test | ||
Assertions.fail(); | ||
} | ||
|
||
@PermissionsAllowed("ignored") | ||
public static class StartupMethodBean { | ||
|
||
public void publicInit(@Observes StartupEvent event) { | ||
Assertions.fail("Illegal state - validation should detect secured observed method"); | ||
} | ||
|
||
void packagePrivateInit(@Observes StartupEvent event) { | ||
// invoked as not intercepted by class level annotation | ||
} | ||
|
||
@Authenticated | ||
void packagePrivateClassAnnotatedMethod(@Observes StartupEvent event) { | ||
Assertions.fail("Illegal state - validation should detect secured observed method"); | ||
} | ||
|
||
@PermitAll | ||
public void permittedInit(@Observes StartupEvent event) { | ||
// invoked as not secured | ||
} | ||
|
||
} | ||
|
||
@RolesAllowed("ignored") | ||
@Startup | ||
@ApplicationScoped | ||
public static class EagerAppBean { | ||
|
||
EagerAppBean() { | ||
Assertions.fail("Illegal state - validation should detect secured observed method"); | ||
} | ||
} | ||
|
||
@PermitAll | ||
@Startup | ||
@ApplicationScoped | ||
public static class PermitAllEagerAppBean { | ||
} | ||
} |