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 ad...@apache.org on 2016/07/04 14:46:17 UTC
[2/5] james-project git commit: JAMES-1788 Introduce the upload
endpoint
JAMES-1788 Introduce the upload endpoint
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/bdd8415c
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/bdd8415c
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/bdd8415c
Branch: refs/heads/master
Commit: bdd8415c3f7b533bb1a3393f2fd37f71247c957a
Parents: f26d8cb
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Jun 30 17:04:57 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Jul 4 14:57:37 2016 +0200
----------------------------------------------------------------------
.../cucumber/CassandraUploadCucumberTest.java | 33 ++++++++
.../integration/cucumber/UploadStepdefs.java | 85 ++++++++++++++++++++
.../resources/cucumber/UploadEndpoint.feature | 23 ++++++
.../cucumber/MemoryUploadCucumberTest.java | 33 ++++++++
.../java/org/apache/james/jmap/JMAPServer.java | 7 +-
.../java/org/apache/james/jmap/JMAPUrls.java | 1 +
.../org/apache/james/jmap/UploadServlet.java | 34 ++++++++
7 files changed, 215 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/bdd8415c/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraUploadCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraUploadCucumberTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraUploadCucumberTest.java
new file mode 100644
index 0000000..10e5d6c
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraUploadCucumberTest.java
@@ -0,0 +1,33 @@
+/****************************************************************
+ * 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.jmap.cassandra.cucumber;
+
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features={"classpath:cucumber/UploadEndpoint.feature"},
+ glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra.cucumber"},
+ tags = {"~@Ignore"},
+ strict = true)
+public class CassandraUploadCucumberTest {
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/bdd8415c/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java
new file mode 100644
index 0000000..bb31263
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java
@@ -0,0 +1,85 @@
+/****************************************************************
+ * 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.jmap.methods.integration.cucumber;
+
+import static com.jayway.restassured.RestAssured.with;
+
+import javax.inject.Inject;
+
+import org.apache.james.jmap.api.access.AccessToken;
+
+import com.jayway.restassured.response.Response;
+import com.jayway.restassured.specification.RequestSpecification;
+
+import cucumber.api.java.en.Then;
+import cucumber.api.java.en.When;
+import cucumber.runtime.java.guice.ScenarioScoped;
+
+@ScenarioScoped
+public class UploadStepdefs {
+
+ private final UserStepdefs userStepdefs;
+ private Response response;
+
+ @Inject
+ private UploadStepdefs(UserStepdefs userStepdefs) {
+ this.userStepdefs = userStepdefs;
+ }
+
+ @When("^\"([^\"]*)\" upload a content$")
+ public void userUploadContent(String username) throws Throwable {
+ AccessToken accessToken = userStepdefs.tokenByUser.get(username);
+ RequestSpecification with = with();
+ if (accessToken != null) {
+ with.header("Authorization", accessToken.serialize());
+ }
+ response = with
+ .post("/upload");
+ }
+
+ @When("^\"([^\"]*)\" checks for the availability of the upload endpoint$")
+ public void optionUpload(String username) throws Throwable {
+ AccessToken accessToken = userStepdefs.tokenByUser.get(username);
+ RequestSpecification with = with();
+ if (accessToken != null) {
+ with.header("Authorization", accessToken.serialize());
+ }
+ response = with
+ .options("/upload");
+ }
+
+ @Then("^the user should receive an authorized response$")
+ public void httpAuthorizedStatus() throws Exception {
+ response.then()
+ .statusCode(200);
+ }
+
+ @Then("^the user should receive a created response$")
+ public void httpCreatedStatus() throws Exception {
+ response.then()
+ .statusCode(201);
+ }
+
+ @Then("^the user should receive a not authorized response$")
+ public void httpUnauthorizedStatus() throws Exception {
+ response.then()
+ .statusCode(401);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/bdd8415c/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/UploadEndpoint.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/UploadEndpoint.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/UploadEndpoint.feature
new file mode 100644
index 0000000..6564f60
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/UploadEndpoint.feature
@@ -0,0 +1,23 @@
+Feature: An upload endpoint should be available to upload contents
+ As a James user
+ I want to upload my attachments
+
+ Background:
+ Given a domain named "domain.tld"
+ And a connected user "username@domain.tld"
+
+ Scenario: An authenticated user should initiate the access to the upload endpoint
+ When "username@domain.tld" checks for the availability of the upload endpoint
+ Then the user should receive an authorized response
+
+ Scenario: An unauthenticated user should initiate the access to the download endpoint
+ When "non-authenticated@domain.tld" checks for the availability of the upload endpoint
+ Then the user should receive an authorized response
+
+ Scenario: Uploading a content without being authenticated
+ When "non-authenticated@domain.tld" upload a content
+ Then the user should receive a not authorized response
+
+ Scenario: Uploading a content being authenticated
+ When "username@domain.tld" upload a content
+ Then the user should receive a created response
http://git-wip-us.apache.org/repos/asf/james-project/blob/bdd8415c/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryUploadCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryUploadCucumberTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryUploadCucumberTest.java
new file mode 100644
index 0000000..25b123e
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryUploadCucumberTest.java
@@ -0,0 +1,33 @@
+/****************************************************************
+ * 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.jmap.memory.cucumber;
+
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features={"classpath:cucumber/UploadEndpoint.feature"},
+ glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory.cucumber"},
+ tags = {"~@Ignore"},
+ strict = true)
+public class MemoryUploadCucumberTest {
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/bdd8415c/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
index 1728d0a..7d235a4 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
@@ -39,7 +39,7 @@ public class JMAPServer implements Configurable {
@Inject
private JMAPServer(JMAPConfiguration jmapConfiguration,
- AuthenticationServlet authenticationServlet, JMAPServlet jmapServlet, DownloadServlet downloadServlet,
+ AuthenticationServlet authenticationServlet, JMAPServlet jmapServlet, DownloadServlet downloadServlet, UploadServlet uploadServlet,
AuthenticationFilter authenticationFilter, FirstUserConnectionFilter firstUserConnectionFilter) {
server = JettyHttpServer.create(
@@ -60,6 +60,11 @@ public class JMAPServer implements Configurable {
.filterAsOneLevelTemplate(JMAPUrls.DOWNLOAD)
.with(new AllowAllCrossOriginRequests(bypass(authenticationFilter).on("GET").and("OPTIONS").only()))
.only()
+ .serve(JMAPUrls.UPLOAD)
+ .with(uploadServlet)
+ .filterAsOneLevelTemplate(JMAPUrls.UPLOAD)
+ .with(new AllowAllCrossOriginRequests(bypass(authenticationFilter).on("OPTIONS").only()))
+ .only()
.build());
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/bdd8415c/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java
index 9d96ccd..563b090 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java
@@ -24,4 +24,5 @@ public interface JMAPUrls {
String JMAP = "/jmap";
String AUTHENTICATION = "/authentication";
String DOWNLOAD = "/download";
+ String UPLOAD = "/upload";
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/bdd8415c/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadServlet.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadServlet.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadServlet.java
new file mode 100644
index 0000000..c7e9ed0
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadServlet.java
@@ -0,0 +1,34 @@
+/****************************************************************
+ * 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.jmap;
+
+import static javax.servlet.http.HttpServletResponse.SC_CREATED;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class UploadServlet extends HttpServlet {
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
+ resp.setStatus(SC_CREATED);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org