james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [04/21] james-project git commit: JAMES-2455 Avoid recursive resolution when getting group members
Date Fri, 06 Jul 2018 09:27:30 GMT
JAMES-2455 Avoid recursive resolution when getting group members

For instance if a forward destination have an other forward, the final forward was displayed,
and not the one I previously configured.

Forward destinations with other mappings might also be skept.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/cc8b7547
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/cc8b7547
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/cc8b7547

Branch: refs/heads/master
Commit: cc8b7547d609c9a605ba7495a21b93d6ae57df20
Parents: 161019d
Author: benwa <btellier@linagora.com>
Authored: Thu Jul 5 12:49:20 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Jul 5 12:55:22 2018 +0700

----------------------------------------------------------------------
 .../james/webadmin/routes/ForwardRoutes.java    |  6 +++--
 .../webadmin/routes/ForwardRoutesTest.java      | 23 +++++++++++++++++---
 2 files changed, 24 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/cc8b7547/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/ForwardRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/ForwardRoutes.java
b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/ForwardRoutes.java
index 20370d6..086d4f0 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/ForwardRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/ForwardRoutes.java
@@ -47,6 +47,7 @@ import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.lib.Mapping;
 import org.apache.james.rrt.lib.MappingSource;
 import org.apache.james.rrt.lib.Mappings;
+import org.apache.james.rrt.lib.MappingsImpl;
 import org.apache.james.user.api.UsersRepository;
 import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.util.OptionalUtils;
@@ -226,9 +227,10 @@ public class ForwardRoutes implements Routes {
         @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
             message = "Internal server error - Something went bad on the server side.")
     })
-    public ImmutableSet<ForwardDestinationResponse> listForwardDestinations(Request
request, Response response) throws RecipientRewriteTable.ErrorMappingException, RecipientRewriteTableException
{
+    public ImmutableSet<ForwardDestinationResponse> listForwardDestinations(Request
request, Response response) throws RecipientRewriteTableException {
         MailAddress baseAddress = parseMailAddress(request.params(FORWARD_BASE_ADDRESS));
-        Mappings mappings = recipientRewriteTable.getMappings(baseAddress.getLocalPart(),
baseAddress.getDomain())
+        Mappings mappings = Optional.ofNullable(recipientRewriteTable.getUserDomainMappings(MappingSource.fromMailAddress(baseAddress)))
+            .orElse(MappingsImpl.empty())
             .select(Mapping.Type.Forward);
 
         ensureNonEmptyMappings(mappings);

http://git-wip-us.apache.org/repos/asf/james-project/blob/cc8b7547/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
index 4767c55..41fdb95 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/ForwardRoutesTest.java
@@ -157,6 +157,23 @@ class ForwardRoutesTest {
         }
 
         @Test
+        void getShouldNotResolveRecurseForwards() {
+            with()
+                .put(ALICE + SEPARATOR + "targets" + SEPARATOR + BOB);
+
+            with()
+                .put(BOB + SEPARATOR + "targets" + SEPARATOR + CEDRIC);
+
+
+            when()
+                .get(ALICE)
+                .then()
+                .contentType(ContentType.JSON)
+                .statusCode(HttpStatus.OK_200)
+                .body("mailAddress", hasItems(BOB));
+        }
+
+        @Test
         void getNotRegisteredForwardShouldReturnNotFound() {
             Map<String, Object> errors = when()
                 .get("unknown@domain.travel")
@@ -683,7 +700,7 @@ class ForwardRoutesTest {
         void getShouldReturnErrorWhenRecipientRewriteTableExceptionIsThrown() throws Exception
{
             doThrow(RecipientRewriteTableException.class)
                 .when(memoryRecipientRewriteTable)
-                .getMappings(anyString(), any());
+                .getUserDomainMappings(any());
 
             when()
                 .get(ALICE)
@@ -695,7 +712,7 @@ class ForwardRoutesTest {
         void getShouldReturnErrorWhenErrorMappingExceptionIsThrown() throws Exception {
             doThrow(RecipientRewriteTable.ErrorMappingException.class)
                 .when(memoryRecipientRewriteTable)
-                .getMappings(anyString(), any());
+                .getUserDomainMappings(any());
 
             when()
                 .get(ALICE)
@@ -707,7 +724,7 @@ class ForwardRoutesTest {
         void getShouldReturnErrorWhenRuntimeExceptionIsThrown() throws Exception {
             doThrow(RuntimeException.class)
                 .when(memoryRecipientRewriteTable)
-                .getMappings(anyString(), any());
+                .getUserDomainMappings(any());
 
             when()
                 .get(ALICE)


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message