james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [01/21] james-project git commit: JAMES-2455 GET forwards destination should not be impacted by other mappings
Date Fri, 06 Jul 2018 09:27:27 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 9d023beae -> a35e7157f


JAMES-2455 GET forwards destination should not be impacted by other mappings


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

Branch: refs/heads/master
Commit: deea61d79134b504e7e9fa1550b46a356bed09f4
Parents: 9d023be
Author: benwa <btellier@linagora.com>
Authored: Thu Jul 5 10:03:27 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Jul 5 12:14:31 2018 +0700

----------------------------------------------------------------------
 .../james/webadmin/routes/ForwardRoutes.java    |  6 +--
 .../webadmin/routes/ForwardRoutesTest.java      | 41 ++++++++++++++++++++
 2 files changed, 44 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/deea61d7/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 8ea0ec0..20370d6 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
@@ -228,12 +228,12 @@ public class ForwardRoutes implements Routes {
     })
     public ImmutableSet<ForwardDestinationResponse> listForwardDestinations(Request
request, Response response) throws RecipientRewriteTable.ErrorMappingException, RecipientRewriteTableException
{
         MailAddress baseAddress = parseMailAddress(request.params(FORWARD_BASE_ADDRESS));
-        Mappings mappings = recipientRewriteTable.getMappings(baseAddress.getLocalPart(),
baseAddress.getDomain());
+        Mappings mappings = recipientRewriteTable.getMappings(baseAddress.getLocalPart(),
baseAddress.getDomain())
+            .select(Mapping.Type.Forward);
 
         ensureNonEmptyMappings(mappings);
 
-        return mappings.select(Mapping.Type.Forward)
-                .asStream()
+        return mappings.asStream()
                 .map(mapping -> mapping.asMailAddress()
                         .orElseThrow(() -> new IllegalStateException(String.format("Can
not compute address for mapping %s", mapping.asString()))))
                 .map(MailAddress::asString)

http://git-wip-us.apache.org/repos/asf/james-project/blob/deea61d7/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 89d9ded..4767c55 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
@@ -44,6 +44,7 @@ import org.apache.james.domainlist.memory.MemoryDomainList;
 import org.apache.james.metrics.logger.DefaultMetricFactory;
 import org.apache.james.rrt.api.RecipientRewriteTable;
 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.memory.MemoryRecipientRewriteTable;
 import org.apache.james.user.api.UsersRepository;
@@ -174,6 +175,46 @@ class ForwardRoutesTest {
         }
 
         @Test
+        void getForwardShouldReturnNotFoundWhenNonForwardMappings() {
+            memoryRecipientRewriteTable.addMapping(
+                MappingSource.fromDomain(DOMAIN),
+                Mapping.domain(Domain.of("target.tld")));
+
+            Map<String, Object> errors = when()
+                .get(ALICE)
+            .then()
+                .statusCode(HttpStatus.NOT_FOUND_404)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", HttpStatus.NOT_FOUND_404)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "The forward does not exist");
+        }
+
+        @Test
+        void getForwardShouldReturnNotFoundWhenNoForwardMappings() {
+            Map<String, Object> errors = when()
+                .get(ALICE)
+            .then()
+                .statusCode(HttpStatus.NOT_FOUND_404)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", HttpStatus.NOT_FOUND_404)
+                .containsEntry("type", "InvalidArgument")
+                .containsEntry("message", "The forward does not exist");
+        }
+
+        @Test
         void putUserInForwardShouldReturnNoContent() {
             when()
                 .put(ALICE + SEPARATOR + "targets" + SEPARATOR + BOB)


---------------------------------------------------------------------
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