-
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.
Loading status checks…
Validate Startup observers are not secured with RBAC annotations
- 3.17.6
- 3.17.5
- 3.17.4
- 3.17.3
- 3.17.2
- 3.17.1
- 3.17.0
- 3.17.0.CR1
- 3.16.4
- 3.16.3
- 3.16.2
- 3.16.1
- 3.16.0
- 3.16.0.CR1
- 3.15.3
- 3.15.2
- 3.15.1
- 3.15.0
- 3.15.0.CR1
- 3.14.4
- 3.14.3
- 3.14.2
- 3.14.1
- 3.14.0
- 3.14.0.CR1
- 3.13.3
- 3.13.2
- 3.13.1
- 3.13.0
- 3.13.0.CR1
- 3.12.3
- 3.12.2
- 3.12.1
- 3.12.0
- 3.12.0.CR1
- 3.11.3
- 3.11.2
- 3.11.1
- 3.11.0
- 3.11.0.CR1
- 3.10.2
- 3.10.1
- 3.10.0
- 3.10.0.CR1
- 3.9.5
- 3.9.4
- 3.9.3
- 3.9.2
- 3.9.1
- 3.9.0
- 3.9.0.CR2
- 3.9.0.CR1
- 3.8.6
- 3.8.5
- 3.8.4
- 3.8.3
- 3.8.2
- 3.8.1
- 3.8.0
- 3.8.0.CR1
- 3.7.4
- 3.7.3
- 3.7.2
- 3.7.1
- 3.7.0
- 3.7.0.CR1
- 3.6.9
- 3.6.8
- 3.6.7
- 3.6.6
- 3.6.5
- 3.6.4
- 3.6.3
- 3.6.2
- 3.6.1
- 3.6.0
- 3.6.0.CR1
1 parent
d110270
commit e9f6d6d
Showing
3 changed files
with
139 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
78 changes: 78 additions & 0 deletions
78
...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,78 @@ | ||
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.assertFalse(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 { | ||
} | ||
|
||
@PermitAll | ||
@Startup | ||
@ApplicationScoped | ||
public static class PermitAllEagerAppBean { | ||
} | ||
} |