You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/11/04 11:24:03 UTC

[james-project] 27/30: JAMES-2958 Add route tests to check that the domain name can not be longer than 255 characters

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit fbfdf0846c61341fd5d670dc5f4f3ac6f9c6444e
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Nov 1 15:29:26 2019 +0700

    JAMES-2958 Add route tests to check that the domain name can not be longer than 255 characters
---
 .../webadmin/routes/DomainMappingsRoutesTest.java  | 53 ++++++++++++++++++++++
 .../james/webadmin/routes/DomainsRoutesTest.java   |  8 ++++
 2 files changed, 61 insertions(+)

diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainMappingsRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainMappingsRoutesTest.java
index 376a1b1..d8b1b6e 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainMappingsRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainMappingsRoutesTest.java
@@ -38,6 +38,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.function.Function;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.james.core.Domain;
 import org.apache.james.domainlist.api.DomainList;
 import org.apache.james.rrt.api.RecipientRewriteTableException;
@@ -125,6 +126,26 @@ class DomainMappingsRoutesTest {
         }
 
         @Test
+        void addDomainMappingsShouldReturnOkWhenWithA255LongDomainSource() {
+            given()
+                .body("to.com")
+            .when()
+                .put(StringUtils.repeat('a', 255))
+            .then()
+                .statusCode(HttpStatus.NO_CONTENT_204);
+        }
+
+        @Test
+        void addDomainMappingsShouldReturnOkWhenWithA255LongDomainDestination() {
+            given()
+                .body(StringUtils.repeat('a', 255))
+            .when()
+                .put("from.com")
+            .then()
+                .statusCode(HttpStatus.NO_CONTENT_204);
+        }
+
+        @Test
         void getDomainMappingsShouldReturnAllDomainMappings() throws RecipientRewriteTableException {
             String alias1 = "to_1.com";
             String alias2 = "to_2.com";
@@ -402,6 +423,38 @@ class DomainMappingsRoutesTest {
                 .hasEntrySatisfying("message", o -> assertThat((String) o).matches("^The domain .* is invalid\\.$"));
         }
 
+        @Test
+        void addDomainMappingShouldReturnBadRequestWhenDomainSourceTooLong() {
+            String longDomainName = StringUtils.repeat('a', 256);
+
+            given()
+                .body("destination.tld")
+            .when()
+                .put(longDomainName)
+            .then()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .body("statusCode", is(400))
+                .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+                .body("message", is("The domain " + longDomainName + " is invalid."))
+                .body("details", is("Domain name length should not exceed 255 characters"));
+        }
+
+        @Test
+        void addDomainMappingShouldReturnBadRequestWhenDomainDestinationTooLong() {
+            String longDomainName = StringUtils.repeat('a', 256);
+
+            given()
+                .body(longDomainName)
+            .when()
+                .put("source.tld")
+            .then()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .body("statusCode", is(400))
+                .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+                .body("message", is("The domain " + longDomainName + " is invalid."))
+                .body("details", is("Domain name length should not exceed 255 characters"));
+        }
+
         private void assertBadRequest(String toDomain, Function<RequestSpecification, Response> requestingFunction) {
             Map<String, Object> errors = requestingFunction.apply(given().body(toDomain).when())
                 .then()
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
index cfd298e..185cabb 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainsRoutesTest.java
@@ -162,6 +162,14 @@ class DomainsRoutesTest {
         }
 
         @Test
+        void putShouldReturnOkWhenWithA255LongDomainName() {
+            when()
+                .put(StringUtils.repeat('a', 255))
+            .then()
+                .statusCode(HttpStatus.NO_CONTENT_204);
+        }
+
+        @Test
         void putShouldReturnBadRequestWhenDomainNameIsTooLong() {
             String longDomainName = StringUtils.repeat('a', 256);
 


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