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/02/13 02:29:32 UTC
[james-project] 21/21: JAMES-3039: Provision a LinShare technical
user within James
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 11765992e2240d801e781665c2a37e03d16e1221
Author: duc91 <du...@gmail.com>
AuthorDate: Tue Feb 4 11:02:57 2020 +0700
JAMES-3039: Provision a LinShare technical user within James
---
.../apache/james/linshare/LinshareExtension.java | 36 +++++++++-
.../org/apache/james/linshare/LinshareFixture.java | 7 ++
.../org/apache/james/linshare/LinshareTest.java | 19 ++++++
.../client/TechnicalAccountCreationRequest.java | 76 ++++++++++++++++++++++
.../TechnicalAccountGrantPermissionsRequest.java | 66 +++++++++++++++++++
.../linshare/client/TechnicalAccountResponse.java | 66 +++++++++++++++++++
6 files changed, 269 insertions(+), 1 deletion(-)
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareExtension.java b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareExtension.java
index 488083b..103ef3d 100644
--- a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareExtension.java
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareExtension.java
@@ -18,17 +18,23 @@
****************************************************************/
package org.apache.james.linshare;
+import static org.apache.james.linshare.LinshareFixture.ADMIN_ACCOUNT;
import static org.apache.james.linshare.LinshareFixture.USER_1;
import static org.apache.james.linshare.LinshareFixture.USER_CREDENTIAL_MAP;
import static org.apache.james.linshare.client.LinshareAPI.Headers.ACCEPT_APPLICATION_JSON;
+import static org.apache.james.linshare.client.LinshareAPI.Headers.CONTENT_TYPE_APPLICATION_JSON;
import java.util.List;
import java.util.Optional;
import org.apache.james.linshare.client.Document;
import org.apache.james.linshare.client.LinshareAPI;
+import org.apache.james.linshare.client.TechnicalAccountCreationRequest;
+import org.apache.james.linshare.client.TechnicalAccountGrantPermissionsRequest;
+import org.apache.james.linshare.client.TechnicalAccountResponse;
import org.apache.james.linshare.client.User;
import org.apache.james.utils.FakeSmtp;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
@@ -45,7 +51,7 @@ import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import feign.slf4j.Slf4jLogger;
-public class LinshareExtension implements BeforeEachCallback {
+public class LinshareExtension implements BeforeEachCallback, BeforeAllCallback {
private interface LinshareAPIForTesting {
@@ -74,9 +80,21 @@ public class LinshareExtension implements BeforeEachCallback {
@Headers(ACCEPT_APPLICATION_JSON)
List<User> allUsers();
+ @RequestLine("GET /linshare/webservice/rest/admin/technical_accounts")
+ @Headers(ACCEPT_APPLICATION_JSON)
+ List<TechnicalAccountResponse> allTechnicalAccounts();
+
@RequestLine("GET /linshare/webservice/rest/user/v2/received_shares/{documentId}/download")
@Headers({ CONTENT_TYPE_APPLICATION_OCTET_STREAM, CONTENT_DISPOSITION_ATTACHMENT })
byte[] downloadShare(@Param("documentId") String documentId, @Param("filename") String filename);
+
+ @RequestLine("POST /linshare/webservice/rest/admin/technical_accounts")
+ @Headers({ ACCEPT_APPLICATION_JSON, CONTENT_TYPE_APPLICATION_JSON })
+ TechnicalAccountResponse createTechnicalAccount(TechnicalAccountCreationRequest accountCreationRequest);
+
+ @RequestLine("PUT /linshare/webservice/rest/admin/technical_accounts")
+ @Headers({ ACCEPT_APPLICATION_JSON, CONTENT_TYPE_APPLICATION_JSON })
+ TechnicalAccountResponse grantTechnicalAccountPermissions(TechnicalAccountGrantPermissionsRequest accountGrantPermissionsRequest);
}
private final Linshare linshare = LinshareSingleton.singleton;
@@ -109,6 +127,22 @@ public class LinshareExtension implements BeforeEachCallback {
.downloadShare(document.asString(), filename);
}
+ @Override
+ public void beforeAll(ExtensionContext extensionContext){
+ createTechnicalAccount(TechnicalAccountCreationRequest.defaultAccount());
+ }
+
+ private void createTechnicalAccount(TechnicalAccountCreationRequest technicalAccountDTO) {
+ TechnicalAccountResponse technicalAccountResponse = LinshareAPIForTesting.from(ADMIN_ACCOUNT, linshare).createTechnicalAccount(technicalAccountDTO);
+
+ TechnicalAccountGrantPermissionsRequest technicalAccountGrantPermissionsRequest = new TechnicalAccountGrantPermissionsRequest(technicalAccountResponse);
+ LinshareAPIForTesting.from(ADMIN_ACCOUNT, linshare).grantTechnicalAccountPermissions(technicalAccountGrantPermissionsRequest);
+ }
+
+ public List<TechnicalAccountResponse> getAllTechnicalAccounts(LinshareFixture.Credential credential) {
+ return LinshareAPIForTesting.from(credential, linshare).allTechnicalAccounts();
+ }
+
private void deleteAllUsersDocuments() {
LinshareAPIForTesting.from(USER_1, linshare)
.allUsers()
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareFixture.java b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareFixture.java
index a47e409..1ee6217 100644
--- a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareFixture.java
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareFixture.java
@@ -84,4 +84,11 @@ public interface LinshareFixture {
"\"combinator\": \"and\"," +
"\"criteria\": []" +
"}";
+
+ Credential TECHNICAL_ACCOUNT = new Credential("Technical@linshare.org", "Technical");
+ Credential ADMIN_ACCOUNT = new Credential("root@localhost.localdomain", "adminlinshare");
+
+ boolean ACCOUNT_ENABLED = true;
+
+ List<String> TECHNICAL_PERMISSIONS = ImmutableList.of("DOCUMENT_ENTRIES_CREATE");
}
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareTest.java b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareTest.java
index 855f5ed..27d55e4 100644
--- a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareTest.java
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareTest.java
@@ -21,10 +21,17 @@ package org.apache.james.linshare;
import static io.restassured.RestAssured.given;
import static io.restassured.config.EncoderConfig.encoderConfig;
import static io.restassured.config.RestAssuredConfig.newConfig;
+import static org.apache.james.linshare.LinshareFixture.ACCOUNT_ENABLED;
+import static org.apache.james.linshare.LinshareFixture.TECHNICAL_ACCOUNT;
+import static org.apache.james.linshare.LinshareFixture.TECHNICAL_PERMISSIONS;
+import static org.assertj.core.api.Assertions.assertThat;
import java.nio.charset.StandardCharsets;
+import java.util.List;
import org.apache.http.HttpStatus;
+import org.apache.james.linshare.client.TechnicalAccountResponse;
+import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -34,6 +41,7 @@ import io.restassured.builder.RequestSpecBuilder;
import io.restassured.http.ContentType;
class LinshareTest {
+
@RegisterExtension
static LinshareExtension linshareExtension = new LinshareExtension();
@@ -58,4 +66,15 @@ class LinshareTest {
.then()
.statusCode(HttpStatus.SC_OK);
}
+
+ @Test
+ void linshareShouldHaveATechnicalAccountConfigured() {
+ List<TechnicalAccountResponse> technicalAccounts = linshareExtension.getAllTechnicalAccounts(LinshareFixture.ADMIN_ACCOUNT);
+
+ assertThat(technicalAccounts).anySatisfy(account -> SoftAssertions.assertSoftly(softly -> {
+ softly.assertThat(account.getName()).isEqualTo(TECHNICAL_ACCOUNT.getUsername());
+ softly.assertThat(account.getPermissions()).containsOnlyElementsOf(TECHNICAL_PERMISSIONS);
+ softly.assertThat(account.isEnabled()).isEqualTo(ACCOUNT_ENABLED);
+ }));
+ }
}
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/client/TechnicalAccountCreationRequest.java b/third-party/linshare/src/test/java/org/apache/james/linshare/client/TechnicalAccountCreationRequest.java
new file mode 100644
index 0000000..ad52803
--- /dev/null
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/client/TechnicalAccountCreationRequest.java
@@ -0,0 +1,76 @@
+/****************************************************************
+ * 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.linshare.client;
+
+import static org.apache.james.linshare.LinshareFixture.ACCOUNT_ENABLED;
+import static org.apache.james.linshare.LinshareFixture.TECHNICAL_ACCOUNT;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class TechnicalAccountCreationRequest {
+
+ private final String name;
+ private final String mail;
+ private final boolean enable;
+ private final String password;
+ private final String role;
+
+ public static TechnicalAccountCreationRequest defaultAccount() {
+ return new TechnicalAccountCreationRequest(TECHNICAL_ACCOUNT.getUsername(),
+ "Technical@linshare.org",
+ ACCOUNT_ENABLED,
+ TECHNICAL_ACCOUNT.getPassword(),
+ "DELEGATION");
+ }
+
+ public TechnicalAccountCreationRequest(String name,
+ String mail,
+ boolean enable,
+ String password,
+ String role) {
+ this.name = name;
+ this.mail = mail;
+ this.enable = enable;
+ this.password = password;
+ this.role = role;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getMail() {
+ return mail;
+ }
+
+ @JsonProperty("enable")
+ public boolean isEnabled() {
+ return enable;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getRole() {
+ return role;
+ }
+
+}
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/client/TechnicalAccountGrantPermissionsRequest.java b/third-party/linshare/src/test/java/org/apache/james/linshare/client/TechnicalAccountGrantPermissionsRequest.java
new file mode 100644
index 0000000..9fff36c
--- /dev/null
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/client/TechnicalAccountGrantPermissionsRequest.java
@@ -0,0 +1,66 @@
+/****************************************************************
+ * 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.linshare.client;
+
+import static org.apache.james.linshare.LinshareFixture.ACCOUNT_ENABLED;
+import static org.apache.james.linshare.LinshareFixture.TECHNICAL_PERMISSIONS;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.collect.ImmutableList;
+
+public class TechnicalAccountGrantPermissionsRequest {
+
+ private final String uuid;
+ private final String mail;
+ private final String name;
+ private final List<String> permissions;
+ private final boolean enable;
+
+ public TechnicalAccountGrantPermissionsRequest(TechnicalAccountResponse technicalAccountResponse) {
+ this.uuid = technicalAccountResponse.getUuid();
+ this.mail = technicalAccountResponse.getMail();
+ this.name = technicalAccountResponse.getName();
+ this.enable = ACCOUNT_ENABLED;
+ this.permissions = ImmutableList.copyOf(TECHNICAL_PERMISSIONS);
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public String getMail() {
+ return mail;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<String> getPermissions() {
+ return permissions;
+ }
+
+ @JsonProperty("enable")
+ public boolean isEnabled() {
+ return enable;
+ }
+}
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/client/TechnicalAccountResponse.java b/third-party/linshare/src/test/java/org/apache/james/linshare/client/TechnicalAccountResponse.java
new file mode 100644
index 0000000..c30477e
--- /dev/null
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/client/TechnicalAccountResponse.java
@@ -0,0 +1,66 @@
+/****************************************************************
+ * 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.linshare.client;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.collect.ImmutableList;
+
+public class TechnicalAccountResponse {
+
+ private final String uuid;
+ private final boolean enabled;
+ private final String name;
+ private final String mail;
+ private final List<String> permissions;
+
+ public TechnicalAccountResponse(@JsonProperty("uuid") String uuid,
+ @JsonProperty("enable") boolean enabled,
+ @JsonProperty("name") String name,
+ @JsonProperty("mail") String mail,
+ @JsonProperty("permissions") List<String> permissions) {
+ this.uuid = uuid;
+ this.enabled = enabled;
+ this.mail = mail;
+ this.name = name;
+ this.permissions = ImmutableList.copyOf(permissions);
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<String> getPermissions() {
+ return permissions;
+ }
+
+ public String getMail() {
+ return mail;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org