forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
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 quarkusio#44238 from michalvavrik/feature/improve-…
…repeated-permissions-allowed-in-quaruks-rest Refactor SecurityTransformerUtils to consider repeated annotations
- Loading branch information
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
...ava/io/quarkus/resteasy/reactive/server/test/security/RepeatedPermissionsAllowedTest.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,113 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.security.PermissionsAllowed; | ||
import io.quarkus.security.StringPermission; | ||
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.vertx.core.json.JsonObject; | ||
|
||
public class RepeatedPermissionsAllowedTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(TestIdentityProvider.class, TestIdentityController.class, HelloResource.class) | ||
.addAsResource( | ||
new StringAsset( | ||
"quarkus.log.category.\"io.quarkus.vertx.http.runtime.QuarkusErrorHandler\".level=OFF" | ||
+ System.lineSeparator()), | ||
"application.properties")); | ||
|
||
@BeforeAll | ||
public static void setupUsers() { | ||
TestIdentityController.resetRoles() | ||
.add("user", "user", new StringPermission("read")) | ||
.add("admin", "admin", new StringPermission("read"), new StringPermission("write")); | ||
} | ||
|
||
@Test | ||
public void testRepeatedPermissionsAllowedOnClass() { | ||
// anonymous user | ||
RestAssured.given() | ||
.body("{%$$#!#@") // assures checks are eager | ||
.post("/hello") | ||
.then() | ||
.statusCode(401); | ||
// authenticated user, insufficient rights | ||
RestAssured.given() | ||
.auth().preemptive().basic("user", "user") | ||
.body("{%$$#!#@") // assures checks are eager | ||
.post("/hello") | ||
.then() | ||
.statusCode(403); | ||
// authorized user, invalid payload | ||
RestAssured.given() | ||
.auth().preemptive().basic("admin", "admin") | ||
.body("{%$$#!#@") // assures checks are eager | ||
.post("/hello") | ||
.then() | ||
.statusCode(500); | ||
} | ||
|
||
@Test | ||
public void testRepeatedPermissionsAllowedOnInterface() { | ||
// anonymous user | ||
RestAssured.given() | ||
.body("{%$$#!#@") // assures checks are eager | ||
.post("/hello-interface") | ||
.then() | ||
.statusCode(401); | ||
// authenticated user, insufficient rights | ||
RestAssured.given() | ||
.auth().preemptive().basic("user", "user") | ||
.body("{%$$#!#@") // assures checks are eager | ||
.post("/hello-interface") | ||
.then() | ||
.statusCode(403); | ||
// authorized user, invalid payload | ||
RestAssured.given() | ||
.auth().preemptive().basic("admin", "admin") | ||
.body("{%$$#!#@") // assures checks are eager | ||
.post("/hello-interface") | ||
.then() | ||
.statusCode(500); | ||
} | ||
|
||
@Path("/hello") | ||
public static class HelloResource { | ||
|
||
@PermissionsAllowed(value = "write") | ||
@PermissionsAllowed(value = "read") | ||
@POST | ||
public String sayHello(JsonObject entity) { | ||
return "ignored"; | ||
} | ||
} | ||
|
||
@Path("/hello-interface") | ||
public interface HelloInterface { | ||
|
||
@PermissionsAllowed(value = "write") | ||
@PermissionsAllowed(value = "read") | ||
@POST | ||
String sayHello(JsonObject entity); | ||
} | ||
|
||
public static class HelloInterfaceImpl implements HelloInterface { | ||
|
||
@Override | ||
public String sayHello(JsonObject entity) { | ||
return "ignored"; | ||
} | ||
} | ||
} |
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