-
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.
Merge pull request #45848 from michalvavrik/reproducer/permission-che…
…cker-multi Quarkus REST: Run security checks that require method arguments in a non-blocking manner before secured methods are invoked
- Loading branch information
Showing
7 changed files
with
347 additions
and
129 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
123 changes: 123 additions & 0 deletions
123
...uarkus/resteasy/reactive/server/test/security/AbstractPermissionCheckerRestMultiTest.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,123 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.QueryParam; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.resteasy.reactive.RestMulti; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.security.PermissionChecker; | ||
import io.quarkus.security.PermissionsAllowed; | ||
import io.quarkus.security.test.utils.TestIdentityController; | ||
import io.quarkus.security.test.utils.TestIdentityProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
import io.smallrye.mutiny.Multi; | ||
|
||
public abstract class AbstractPermissionCheckerRestMultiTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(TestResource.class, TestIdentityController.class, | ||
TestIdentityProvider.class)); | ||
|
||
@BeforeAll | ||
public static void setupUsers() { | ||
TestIdentityController.resetRoles().add("user", "user"); | ||
} | ||
|
||
@Test | ||
public void testReturnRestMultiAsMulti() { | ||
RestAssured | ||
.given() | ||
.auth().preemptive().basic("user", "user") | ||
.queryParam("user", "Georgios") | ||
.get("/test/public-multi") | ||
.then() | ||
.statusCode(201) | ||
.header("header1", "value header 1"); | ||
RestAssured | ||
.given() | ||
.auth().preemptive().basic("user", "user") | ||
.queryParam("user", "Georgios") | ||
.get("/test/secured-multi") | ||
.then() | ||
.statusCode(201) | ||
.header("header1", "value header 1"); | ||
RestAssured | ||
.given() | ||
.auth().preemptive().basic("user", "user") | ||
.queryParam("user", "Sergey") | ||
.get("/test/secured-multi") | ||
.then() | ||
.statusCode(403) | ||
.header("header1", Matchers.nullValue()); | ||
} | ||
|
||
@Test | ||
public void testReturnRestMulti() { | ||
RestAssured | ||
.given() | ||
.auth().preemptive().basic("user", "user") | ||
.queryParam("user", "Georgios") | ||
.get("/test/secured-rest-multi") | ||
.then() | ||
.statusCode(201) | ||
.header("header1", "value header 1"); | ||
RestAssured | ||
.given() | ||
.auth().preemptive().basic("user", "user") | ||
.queryParam("user", "Sergey") | ||
.get("/test/secured-rest-multi") | ||
.then() | ||
.statusCode(403) | ||
.header("header1", Matchers.nullValue()); | ||
} | ||
|
||
@Path("/test") | ||
public static class TestResource { | ||
|
||
@GET | ||
@Path("public-multi") | ||
@Produces(MediaType.APPLICATION_OCTET_STREAM) | ||
public Multi<Byte> publicMethod(@QueryParam("user") String user) { | ||
return RestMulti.fromMultiData(Multi.createFrom().<Byte> empty()) | ||
.status(201) | ||
.header("header1", "value header 1") | ||
.build(); | ||
} | ||
|
||
@PermissionsAllowed("secured") | ||
@GET | ||
@Path("secured-multi") | ||
@Produces(MediaType.APPLICATION_OCTET_STREAM) | ||
public Multi<Byte> securedMethod(@QueryParam("user") String user) { | ||
return RestMulti.fromMultiData(Multi.createFrom().<Byte> empty()) | ||
.status(201) | ||
.header("header1", "value header 1") | ||
.build(); | ||
} | ||
|
||
@PermissionsAllowed("secured") | ||
@GET | ||
@Path("secured-rest-multi") | ||
@Produces(MediaType.APPLICATION_OCTET_STREAM) | ||
public RestMulti<Byte> securedMethodRestMulti(@QueryParam("user") String user) { | ||
return RestMulti.fromMultiData(Multi.createFrom().<Byte> empty()) | ||
.status(201) | ||
.header("header1", "value header 1") | ||
.build(); | ||
} | ||
|
||
@PermissionChecker(value = "secured") | ||
public boolean canCallSecured(String user) { | ||
return "Georgios".equals(user); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...uarkus/resteasy/reactive/server/test/security/LazyAuthPermissionCheckerRestMultiTest.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,20 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.security.test.utils.TestIdentityController; | ||
import io.quarkus.security.test.utils.TestIdentityProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class LazyAuthPermissionCheckerRestMultiTest extends AbstractPermissionCheckerRestMultiTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource(new StringAsset(""" | ||
quarkus.http.auth.proactive=false | ||
"""), "application.properties") | ||
.addClasses(TestResource.class, TestIdentityController.class, TestIdentityProvider.class)); | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...s/resteasy/reactive/server/test/security/ProactiveAuthPermissionCheckerRestMultiTest.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,16 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.security.test.utils.TestIdentityController; | ||
import io.quarkus.security.test.utils.TestIdentityProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ProactiveAuthPermissionCheckerRestMultiTest extends AbstractPermissionCheckerRestMultiTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(TestResource.class, TestIdentityController.class, | ||
TestIdentityProvider.class)); | ||
|
||
} |
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
Oops, something went wrong.