-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Per-entity CRUD filters for update/delete operations #502
.. create/update/delete authorizers
- Loading branch information
Showing
11 changed files
with
423 additions
and
19 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
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
107 changes: 107 additions & 0 deletions
107
agrest-cayenne/src/test/java/io/agrest/cayenne/PUT_CreateAuthorizerIT.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,107 @@ | ||
package io.agrest.cayenne; | ||
|
||
import io.agrest.Ag; | ||
import io.agrest.EntityUpdate; | ||
import io.agrest.SimpleResponse; | ||
import io.agrest.cayenne.cayenne.main.E2; | ||
import io.agrest.cayenne.cayenne.main.E3; | ||
import io.agrest.cayenne.cayenne.main.E4; | ||
import io.agrest.cayenne.unit.AgCayenneTester; | ||
import io.agrest.cayenne.unit.DbTest; | ||
import io.agrest.meta.AgEntity; | ||
import io.bootique.junit5.BQTestTool; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.core.Configuration; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.UriInfo; | ||
import java.util.List; | ||
|
||
public class PUT_CreateAuthorizerIT extends DbTest { | ||
|
||
@BQTestTool | ||
static final AgCayenneTester tester = tester(Resource.class) | ||
.entities(E2.class, E3.class, E4.class) | ||
.agCustomizer(ab -> ab | ||
.entityOverlay(AgEntity.overlay(E2.class).createAuthorizer(u -> !"blocked".equals(u.getValues().get("name")))) | ||
).build(); | ||
|
||
@Test | ||
public void testInStack_Allowed() { | ||
|
||
tester.target("/e2_stack_authorizer") | ||
.put("[{\"name\":\"Bb\"},{\"name\":\"Aa\"}]") | ||
.wasCreated(); | ||
|
||
tester.e2().matcher().assertMatches(2); | ||
tester.e2().matcher().eq("name", "Aa").assertOneMatch(); | ||
tester.e2().matcher().eq("name", "Bb").assertOneMatch(); | ||
} | ||
|
||
@Test | ||
public void testInStack_Blocked() { | ||
|
||
tester.target("/e2_stack_authorizer") | ||
.put("[{\"name\":\"Bb\"},{\"name\":\"blocked\"}]") | ||
.wasForbidden(); | ||
|
||
tester.e2().matcher().assertNoMatches(); | ||
} | ||
|
||
@Test | ||
public void testInRequestAndStack_Allowed() { | ||
|
||
tester.target("/e2_request_and_stack_authorizer/not_this") | ||
.put("[{\"name\":\"Bb\"},{\"name\":\"Aa\"}]") | ||
.wasCreated(); | ||
|
||
tester.e2().matcher().assertMatches(2); | ||
tester.e2().matcher().eq("name", "Aa").assertOneMatch(); | ||
tester.e2().matcher().eq("name", "Bb").assertOneMatch(); | ||
} | ||
|
||
@Test | ||
public void testInRequestAndStack_Blocked() { | ||
|
||
tester.target("/e2_request_and_stack_authorizer/not_this") | ||
.put("[{\"name\":\"Bb\"},{\"name\":\"blocked\"}]") | ||
.wasForbidden(); | ||
|
||
tester.e2().matcher().assertNoMatches(); | ||
|
||
tester.target("/e2_request_and_stack_authorizer/not_this") | ||
.put("[{\"name\":\"not_this\"},{\"name\":\"Aa\"}]") | ||
.wasForbidden(); | ||
|
||
tester.e2().matcher().assertNoMatches(); | ||
} | ||
|
||
@Path("") | ||
public static class Resource { | ||
|
||
@Context | ||
private Configuration config; | ||
|
||
@PUT | ||
@Path("e2_stack_authorizer") | ||
public SimpleResponse putE2StackFilter(@Context UriInfo uriInfo, List<EntityUpdate<E2>> updates) { | ||
return Ag.service(config).createOrUpdate(E2.class).uri(uriInfo).sync(updates); | ||
} | ||
|
||
@PUT | ||
@Path("e2_request_and_stack_authorizer/{name}") | ||
public SimpleResponse putE2RequestAndStackFilter( | ||
@Context UriInfo uriInfo, | ||
@PathParam("name") String name, | ||
List<EntityUpdate<E2>> updates) { | ||
|
||
return Ag.service(config).createOrUpdate(E2.class) | ||
.uri(uriInfo) | ||
.createAuthorizer(E2.class, u -> !name.equals(u.getValues().get("name"))) | ||
.sync(updates); | ||
} | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
agrest-cayenne/src/test/java/io/agrest/cayenne/PUT_DeleteAuthorizerIT.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,119 @@ | ||
package io.agrest.cayenne; | ||
|
||
import io.agrest.Ag; | ||
import io.agrest.EntityUpdate; | ||
import io.agrest.SimpleResponse; | ||
import io.agrest.cayenne.cayenne.main.E2; | ||
import io.agrest.cayenne.cayenne.main.E3; | ||
import io.agrest.cayenne.cayenne.main.E4; | ||
import io.agrest.cayenne.unit.AgCayenneTester; | ||
import io.agrest.cayenne.unit.DbTest; | ||
import io.agrest.meta.AgEntity; | ||
import io.bootique.junit5.BQTestTool; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.core.Configuration; | ||
import javax.ws.rs.core.Context; | ||
import java.util.List; | ||
|
||
public class PUT_DeleteAuthorizerIT extends DbTest { | ||
|
||
@BQTestTool | ||
static final AgCayenneTester tester = tester(Resource.class) | ||
.entities(E2.class, E3.class, E4.class) | ||
.agCustomizer(ab -> ab | ||
.entityOverlay(AgEntity.overlay(E2.class).deleteAuthorizer(o -> !"dont_delete".equals(o.getName()))) | ||
).build(); | ||
|
||
@Test | ||
public void testInStack_Allowed() { | ||
|
||
tester.e2().insertColumns("id_", "name") | ||
.values(1, "a") | ||
.values(2, "b") | ||
.exec(); | ||
|
||
tester.target("/e2_stack_authorizer") | ||
.put("[{\"id\":2,\"name\":\"Bb\"}]") | ||
.wasOk(); | ||
|
||
tester.e2().matcher().assertMatches(1); | ||
tester.e2().matcher().eq("name", "Bb").assertOneMatch(); | ||
} | ||
|
||
@Test | ||
public void testInStack_Blocked() { | ||
tester.e2().insertColumns("id_", "name") | ||
.values(1, "dont_delete") | ||
.values(2, "b") | ||
.exec(); | ||
|
||
tester.target("/e2_stack_authorizer") | ||
.put("[{\"id\":2,\"name\":\"Bb\"}]") | ||
.wasForbidden(); | ||
|
||
tester.e2().matcher().assertMatches(2); | ||
tester.e2().matcher().eq("name", "dont_delete").assertOneMatch(); | ||
tester.e2().matcher().eq("name", "b").assertOneMatch(); | ||
} | ||
|
||
@Test | ||
public void testInRequestAndStack_Allowed() { | ||
|
||
tester.e2().insertColumns("id_", "name") | ||
.values(1, "a") | ||
.values(2, "b") | ||
.exec(); | ||
|
||
tester.target("/e2_request_and_stack_authorizer/not_this") | ||
.put("[{\"id\":2,\"name\":\"Bb\"}]") | ||
.wasOk(); | ||
|
||
tester.e2().matcher().assertMatches(1); | ||
tester.e2().matcher().eq("name", "Bb").assertOneMatch(); | ||
} | ||
|
||
@Test | ||
public void testInRequestAndStack_Blocked() { | ||
tester.e2().insertColumns("id_", "name") | ||
.values(1, "dont_delete_this_either") | ||
.values(2, "b") | ||
.exec(); | ||
|
||
tester.target("/e2_request_and_stack_authorizer/dont_delete_this_either") | ||
.put("[{\"id\":2,\"name\":\"Bb\"}]") | ||
.wasForbidden(); | ||
|
||
tester.e2().matcher().assertMatches(2); | ||
tester.e2().matcher().eq("name", "dont_delete_this_either").assertOneMatch(); | ||
tester.e2().matcher().eq("name", "b").assertOneMatch(); | ||
} | ||
|
||
@Path("") | ||
public static class Resource { | ||
|
||
@Context | ||
private Configuration config; | ||
|
||
@PUT | ||
@Path("e2_stack_authorizer") | ||
public SimpleResponse putE2StackFilter(List<EntityUpdate<E2>> updates) { | ||
return Ag.service(config).idempotentFullSync(E2.class).sync(updates); | ||
} | ||
|
||
@PUT | ||
@Path("e2_request_and_stack_authorizer/{name}") | ||
public SimpleResponse putE2RequestAndStackFilter( | ||
@PathParam("name") String name, | ||
List<EntityUpdate<E2>> updates) { | ||
|
||
return Ag.service(config) | ||
.idempotentFullSync(E2.class) | ||
.deleteAuthorizer(E2.class, o -> !name.equals(o.getName())) | ||
.sync(updates); | ||
} | ||
} | ||
} |
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.