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 rc...@apache.org on 2020/06/23 02:13:28 UTC

[james-project] branch master updated (64a487d -> addf601)

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

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


    from 64a487d  JAMES-1481 Fix a dead link in install page
     new de4aae8  JAMES-3262 Add tests for SolveMailboxInconsistenciesRequestToTask
     new 8e6bcc4  JAMES-3262 Fix issue when I-KNOW-WHAT-I-M-DOING header is missing
     new 91f4e1d  JAMES-3262 Enhance webadmin documentation regarding the I-KNOW-WHAT-I-M-DOING header for the fix mailboxes inconsistencies task
     new addf601  JAMES-3249: Correcting webadmin documentation

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../task/SolveMailboxInconsistenciesService.java   |  4 +-
 .../SolveMailboxInconsistenciesRequestToTask.java  |  5 +-
 ...veMailboxInconsistenciesRequestToTaskTest.java} | 75 ++++++++--------------
 src/site/markdown/server/manage-webadmin.md        | 13 ++--
 4 files changed, 38 insertions(+), 59 deletions(-)
 copy server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/{SolveMessageInconsistenciesRequestToTaskTest.java => SolveMailboxInconsistenciesRequestToTaskTest.java} (75%)


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


[james-project] 02/04: JAMES-3262 Fix issue when I-KNOW-WHAT-I-M-DOING header is missing

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8e6bcc412a74849e924e33f471f887d969d16459
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Mon Jun 22 11:13:19 2020 +0700

    JAMES-3262 Fix issue when I-KNOW-WHAT-I-M-DOING header is missing
    
    We should return 400 with a proper error message, and not 500
---
 .../webadmin/routes/SolveMailboxInconsistenciesRequestToTask.java    | 5 +++--
 .../routes/SolveMailboxInconsistenciesRequestToTaskTest.java         | 2 --
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/SolveMailboxInconsistenciesRequestToTask.java b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/SolveMailboxInconsistenciesRequestToTask.java
index 064dca5..1f4ec46 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/SolveMailboxInconsistenciesRequestToTask.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/SolveMailboxInconsistenciesRequestToTask.java
@@ -35,8 +35,9 @@ public class SolveMailboxInconsistenciesRequestToTask extends TaskFromRequestReg
     public SolveMailboxInconsistenciesRequestToTask(SolveMailboxInconsistenciesService service) {
         super(REGISTRATION_KEY,
             request -> {
-                Preconditions.checkArgument(request.headers("I-KNOW-WHAT-I-M-DOING")
-                        .equalsIgnoreCase("ALL-SERVICES-ARE-OFFLINE"),
+                String header = request.headers("I-KNOW-WHAT-I-M-DOING");
+                Preconditions.checkArgument(header != null
+                        && header.equalsIgnoreCase("ALL-SERVICES-ARE-OFFLINE"),
                     "Due to concurrency risks, a `I-KNOW-WHAT-I-M-DOING` header should be positioned to " +
                         "`ALL-SERVICES-ARE-OFFLINE` in order to prevent accidental calls. " +
                         "Check the documentation for details.");
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/SolveMailboxInconsistenciesRequestToTaskTest.java b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/SolveMailboxInconsistenciesRequestToTaskTest.java
index 6cf9cee..73921d1 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/SolveMailboxInconsistenciesRequestToTaskTest.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/SolveMailboxInconsistenciesRequestToTaskTest.java
@@ -42,7 +42,6 @@ import org.apache.james.webadmin.utils.JsonTransformer;
 import org.eclipse.jetty.http.HttpStatus;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.mockito.Mockito;
 
@@ -148,7 +147,6 @@ public class SolveMailboxInconsistenciesRequestToTaskTest {
     }
 
     @Test
-    @Disabled("JAMES-3262 : returns 500, should fix")
     void postShouldFailWhenIKnowWhatImDoingHeaderIsMissing() {
         given()
             .queryParam("action", "SolveInconsistencies")


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


[james-project] 03/04: JAMES-3262 Enhance webadmin documentation regarding the I-KNOW-WHAT-I-M-DOING header for the fix mailboxes inconsistencies task

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 91f4e1d9964a6f89d3c45aa9ff0b2c4ce9f8c196
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Mon Jun 22 11:21:04 2020 +0700

    JAMES-3262 Enhance webadmin documentation regarding the I-KNOW-WHAT-I-M-DOING header for the fix mailboxes inconsistencies task
---
 src/site/markdown/server/manage-webadmin.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index abffd56..f988530 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -419,6 +419,8 @@ Will schedule a task for fixing inconsistencies for the mailbox deduplicated obj
 
 [More details about endpoints returning a task](#Endpoints_returning_a_task).
 
+The `I-KNOW-WHAT-I-M-DOING` header is mandatory (you can read more information about it in the warning section below).
+
 The scheduled task will have the following type `solve-mailbox-inconsistencies` and the following `additionalInformation`:
 
 ```


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


[james-project] 04/04: JAMES-3249: Correcting webadmin documentation

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit addf6019083edd8e803f8103180434eafd5a26ff
Author: duc91 <du...@gmail.com>
AuthorDate: Mon Jun 22 10:59:09 2020 +0700

    JAMES-3249: Correcting webadmin documentation
---
 src/site/markdown/server/manage-webadmin.md | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index f988530..bf27154 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -271,7 +271,7 @@ Response codes:
 
  - 204: The redirection now exists
  - 400: `source.domain.tld` or `destination.domain.tld` have an invalid syntax
- - 400: source, domain and destination domain are the same
+ - 400: `source, domain` and `destination domain` are the same
  - 404: `source.domain.tld` are not part of handled domains.
 
 ### Delete an alias for a domain
@@ -3302,6 +3302,7 @@ Response codes:
 
  - 200: Success. A JSON representing this event is returned.
  - 400: Invalid group name or `insertionId`
+ - 404: No event with this `insertionId`
 
 ### Deleting an event
 
@@ -3319,7 +3320,7 @@ Response codes:
 ### Redeliver all events
 
 ```
-curl -XPOST http://ip:port/events/deadLetter
+curl -XPOST http://ip:port/events/deadLetter?action=redeliver
 ```
 
 Will create a task that will attempt to redeliver all events stored in "Event Dead Letter".
@@ -3351,7 +3352,7 @@ Response codes:
 ### Redeliver a single event
 
 ```
-curl -XPOST http://ip:port/events/deadLetter/groups/org.apache.james.mailbox.events.EventBusTestFixture$GroupA/6e0dd59d-660e-4d9b-b22f-0354479f47b4
+curl -XPOST http://ip:port/events/deadLetter/groups/org.apache.james.mailbox.events.EventBusTestFixture$GroupA/6e0dd59d-660e-4d9b-b22f-0354479f47b4?action=reDeliver
 ```
 
 Will create a task that will attempt to redeliver a single event of a particular group stored in "Event Dead Letter".
@@ -3721,7 +3722,7 @@ Response codes:
 A list of all tasks can be retrieved:
 
 ```
-curl -XGET /tasks
+curl -XGET http://ip:port/tasks
 ```
 
 Will return a list of Execution reports
@@ -3729,7 +3730,7 @@ Will return a list of Execution reports
 One can filter the above results by status. For example:
 
 ```
-curl -XGET /tasks?status=inProgress
+curl -XGET http://ip:port/tasks?status=inProgress
 ```
 
 Will return a list of Execution reports that are currently in progress.


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


[james-project] 01/04: JAMES-3262 Add tests for SolveMailboxInconsistenciesRequestToTask

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit de4aae8994d6c3d8d8723469aa4302f6129f466e
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Mon Jun 22 10:41:43 2020 +0700

    JAMES-3262 Add tests for SolveMailboxInconsistenciesRequestToTask
    
    Proves as well that if we omit the `I-KNOW-WHAT-I-M-DOING` we return 500, which is wrong (should return 400)
---
 .../task/SolveMailboxInconsistenciesService.java   |   4 +-
 ...lveMailboxInconsistenciesRequestToTaskTest.java | 208 +++++++++++++++++++++
 2 files changed, 210 insertions(+), 2 deletions(-)

diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/SolveMailboxInconsistenciesService.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/SolveMailboxInconsistenciesService.java
index a10fc6d..aa53506 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/SolveMailboxInconsistenciesService.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/SolveMailboxInconsistenciesService.java
@@ -174,7 +174,7 @@ public class SolveMailboxInconsistenciesService {
         }
     }
 
-    static class Context {
+    public static class Context {
         static class Builder {
             private Optional<Long> processedMailboxEntries;
             private Optional<Long> processedMailboxPathEntries;
@@ -366,7 +366,7 @@ public class SolveMailboxInconsistenciesService {
         this.versionManager = versionManager;
     }
 
-    Mono<Result> fixMailboxInconsistencies(Context context) {
+    public Mono<Result> fixMailboxInconsistencies(Context context) {
         assertValidVersion();
         return Flux.concat(
                 processMailboxDaoInconsistencies(context),
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/SolveMailboxInconsistenciesRequestToTaskTest.java b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/SolveMailboxInconsistenciesRequestToTaskTest.java
new file mode 100644
index 0000000..6cf9cee
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/SolveMailboxInconsistenciesRequestToTaskTest.java
@@ -0,0 +1,208 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.routes;
+
+import static io.restassured.RestAssured.given;
+import static io.restassured.RestAssured.when;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+
+import org.apache.james.json.DTOConverter;
+import org.apache.james.mailbox.cassandra.mail.task.SolveMailboxInconsistenciesService;
+import org.apache.james.mailbox.cassandra.mail.task.SolveMessageInconsistenciesTaskAdditionalInformationDTO;
+import org.apache.james.task.Hostname;
+import org.apache.james.task.MemoryTaskManager;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskManager;
+import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.WebAdminServer;
+import org.apache.james.webadmin.WebAdminUtils;
+import org.apache.james.webadmin.tasks.TaskFromRequestRegistry;
+import org.apache.james.webadmin.utils.ErrorResponder;
+import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import io.restassured.RestAssured;
+import io.restassured.filter.log.LogDetail;
+import reactor.core.publisher.Mono;
+import spark.Service;
+
+public class SolveMailboxInconsistenciesRequestToTaskTest {
+    private final class JMAPRoutes implements Routes {
+        private final SolveMailboxInconsistenciesService service;
+        private final TaskManager taskManager;
+
+        private JMAPRoutes(SolveMailboxInconsistenciesService service, TaskManager taskManager) {
+            this.service = service;
+            this.taskManager = taskManager;
+        }
+
+        @Override
+        public String getBasePath() {
+            return BASE_PATH;
+        }
+
+        @Override
+        public void define(Service service) {
+            service.post(BASE_PATH,
+                TaskFromRequestRegistry.builder()
+                    .registrations(new SolveMailboxInconsistenciesRequestToTask(this.service))
+                    .buildAsRoute(taskManager),
+                new JsonTransformer());
+        }
+    }
+
+    static final String BASE_PATH = "/mailboxes";
+
+    private WebAdminServer webAdminServer;
+    private SolveMailboxInconsistenciesService service;
+    private MemoryTaskManager taskManager;
+
+    @BeforeEach
+    void setUp() {
+        JsonTransformer jsonTransformer = new JsonTransformer();
+        taskManager = new MemoryTaskManager(new Hostname("foo"));
+
+        service = mock(SolveMailboxInconsistenciesService.class);
+        Mockito.when(service.fixMailboxInconsistencies(any())).thenReturn(Mono.just(Task.Result.COMPLETED));
+
+        webAdminServer = WebAdminUtils.createWebAdminServer(
+            new TasksRoutes(taskManager, jsonTransformer, DTOConverter.of(SolveMessageInconsistenciesTaskAdditionalInformationDTO.module())),
+            new JMAPRoutes(
+                service,
+                taskManager))
+            .start();
+
+        RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer)
+            .setBasePath(BASE_PATH)
+            .log(LogDetail.URI)
+            .build();
+    }
+
+    @AfterEach
+    void afterEach() {
+        webAdminServer.destroy();
+        taskManager.stop();
+    }
+
+    @Test
+    void actionRequestParameterShouldBeCompulsory() {
+        when()
+            .post()
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(400))
+            .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+            .body("message", is("Invalid arguments supplied in the user request"))
+            .body("details", is("'action' query parameter is compulsory. Supported values are [SolveInconsistencies]"));
+    }
+
+    @Test
+    void postShouldFailUponEmptyTask() {
+        given()
+            .queryParam("action", "")
+            .post()
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(400))
+            .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+            .body("message", is("Invalid arguments supplied in the user request"))
+            .body("details", is("'action' query parameter cannot be empty or blank. Supported values are [SolveInconsistencies]"));
+    }
+
+    @Test
+    void postShouldFailUponInvalidAction() {
+        given()
+            .queryParam("action", "invalid")
+            .post()
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(400))
+            .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+            .body("message", is("Invalid arguments supplied in the user request"))
+            .body("details", is("Invalid value supplied for query parameter 'action': invalid. Supported values are [SolveInconsistencies]"));
+    }
+
+    @Test
+    @Disabled("JAMES-3262 : returns 500, should fix")
+    void postShouldFailWhenIKnowWhatImDoingHeaderIsMissing() {
+        given()
+            .queryParam("action", "SolveInconsistencies")
+            .post()
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(400))
+            .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+            .body("message", is("Invalid arguments supplied in the user request"))
+            .body("details", is("Due to concurrency risks, a `I-KNOW-WHAT-I-M-DOING` header should be positioned to " +
+                "`ALL-SERVICES-ARE-OFFLINE` in order to prevent accidental calls. " +
+                "Check the documentation for details."));
+    }
+
+    @Test
+    void postShouldFailWhenIKnowWhatImDoingHeaderIsInvalid() {
+        given()
+            .queryParam("action", "SolveInconsistencies")
+            .header("I-KNOW-WHAT-I-M-DOING", "invalid")
+            .post()
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(400))
+            .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+            .body("message", is("Invalid arguments supplied in the user request"))
+            .body("details", is("Due to concurrency risks, a `I-KNOW-WHAT-I-M-DOING` header should be positioned to " +
+                "`ALL-SERVICES-ARE-OFFLINE` in order to prevent accidental calls. " +
+                "Check the documentation for details."));
+    }
+
+    @Test
+    void postShouldFailWhenIKnowWhatImDoingHeaderIsEmpty() {
+        given()
+            .queryParam("action", "SolveInconsistencies")
+            .header("I-KNOW-WHAT-I-M-DOING", "")
+            .post()
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(400))
+            .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+            .body("message", is("Invalid arguments supplied in the user request"))
+            .body("details", is("Due to concurrency risks, a `I-KNOW-WHAT-I-M-DOING` header should be positioned to " +
+                "`ALL-SERVICES-ARE-OFFLINE` in order to prevent accidental calls. " +
+                "Check the documentation for details."));
+    }
+
+    @Test
+    void postShouldCreateANewTask() {
+        given()
+            .queryParam("action", "SolveInconsistencies")
+            .header("I-KNOW-WHAT-I-M-DOING", "ALL-SERVICES-ARE-OFFLINE")
+            .post()
+        .then()
+            .statusCode(HttpStatus.CREATED_201)
+            .body("taskId", notNullValue());
+    }
+}


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