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/05/20 09:39:58 UTC

[james-project] 01/09: JAMES-2709 Rely on linagora/linshare-init for LinShare LDAP init

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 4f8dc2284b385a6f3938f41642afa4eaa277918e
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu May 16 10:18:04 2019 +0700

    JAMES-2709 Rely on linagora/linshare-init for LinShare LDAP init
---
 .../james/linshare/LDAPConfigurationPerformer.java | 122 ---------------------
 .../java/org/apache/james/linshare/Linshare.java   |  27 ++++-
 2 files changed, 25 insertions(+), 124 deletions(-)

diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/LDAPConfigurationPerformer.java b/third-party/linshare/src/test/java/org/apache/james/linshare/LDAPConfigurationPerformer.java
deleted file mode 100644
index d74d445..0000000
--- a/third-party/linshare/src/test/java/org/apache/james/linshare/LDAPConfigurationPerformer.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/****************************************************************
- * 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;
-
-import static io.restassured.RestAssured.given;
-import static io.restassured.config.EncoderConfig.encoderConfig;
-import static io.restassured.config.RestAssuredConfig.newConfig;
-
-import java.nio.charset.StandardCharsets;
-
-import io.restassured.authentication.BasicAuthScheme;
-import io.restassured.builder.RequestSpecBuilder;
-import io.restassured.http.ContentType;
-import io.restassured.specification.RequestSpecification;
-
-class LDAPConfigurationPerformer {
-    static void configureLdap(Linshare linshare) {
-        BasicAuthScheme basicAuthScheme = new BasicAuthScheme();
-        basicAuthScheme.setUserName("root@localhost.localdomain");
-        basicAuthScheme.setPassword("adminlinshare");
-
-        RequestSpecification specification = new RequestSpecBuilder()
-            .setContentType(ContentType.JSON)
-            .setAccept(ContentType.JSON)
-            .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
-            .setBaseUri("http://" + linshare.getIp())
-            .setPort(linshare.getPort())
-            .setAuth(basicAuthScheme)
-            .build();
-
-        String ldapId = given(specification)
-            .body("{" +
-                "  \"label\":\"ldap-local\"," +
-                "  \"providerUrl\":\"ldap://ldap:389\"," +
-                "  \"securityPrincipal\":\"cn=linshare,dc=linshare,dc=org\"," +
-                "  \"securityCredentials\":\"linshare\"" +
-                "}")
-            .post("/linshare/webservice/rest/admin/ldap_connections")
-            .jsonPath()
-            .getString("uuid");
-
-        given(specification)
-            .body("{" +
-                "  \"uuid\":\"868400c0-c12e-456a-8c3c-19e985290586\"," +
-                "  \"label\":\"openldap-local\"," +
-                "  \"description\":\"This is pattern the default pattern for the OpenLdap structure.\"," +
-                "  \"authCommand\":\"ldap.search(domain, \\\"(&(objectClass=inetOrgPerson)(mail=*)(givenName=*)(sn=*)(|(mail=\\\"+login+\\\")(uid=\\\"+login+\\\")))\\\");\"," +
-                "  \"searchUserCommand\":\"ldap.search(domain, \\\"(&(objectClass=inetOrgPerson)(mail=\\\"+mail+\\\")(givenName=\\\"+first_name+\\\")(sn=\\\"+last_name+\\\"))\\\");\"," +
-                "  \"userMail\":\"mail\"," +
-                "  \"userFirstName\":\"givenName\"," +
-                "  \"userLastName\":\"sn\"," +
-                "  \"ldapUid\":\"uid\"," +
-                "  \"autoCompleteCommandOnAllAttributes\":\"ldap.search(domain, \\\"(&(objectClass=inetOrgPerson)(mail=*)(givenName=*)(sn=*)(|(mail=\\\" + pattern + \\\")(sn=\\\" + pattern + \\\")(givenName=\\\" + pattern + \\\")))\\\");\"," +
-                "  \"autoCompleteCommandOnFirstAndLastName\":\"ldap.search(domain, \\\"(&(objectClass=inetOrgPerson)(mail=*)(givenName=*)(sn=*)(|(&(sn=\\\" + first_name + \\\")(givenName=\\\" + last_name + \\\"))(&(sn=\\\" + last_name + \\\")(givenName=\\\" + first_name + \\\"))))\\\");\"," +
-                "  \"searchPageSize\":100," +
-                "  \"searchSizeLimit\":100," +
-                "  \"completionPageSize\":10," +
-                "  \"completionSizeLimit\":10" +
-                "}")
-            .post("/linshare/webservice/rest/admin/domain_patterns");
-
-        String ldapPatternId = given(specification)
-            .get("/linshare/webservice/rest/admin/domain_patterns")
-            .getBody()
-            .jsonPath()
-            .getString("[0].uuid");
-
-        String mimePolicyId = given(specification)
-            .get("/linshare/webservice/rest/admin/mime_policies?domainId=LinShareRootDomain&onlyCurrentDomain=false")
-            .jsonPath()
-            .getString("[0].uuid");
-
-        String welcomeMessageId = given(specification)
-            .get("/linshare/webservice/rest/admin/welcome_messages?domainId=LinShareRootDomain&parent=true")
-            .jsonPath()
-            .getString("[0].uuid");
-
-        String mailConfigId = given(specification)
-            .get("/linshare/webservice/rest/admin/mail_configs?domainId=LinShareRootDomain&onlyCurrentDomain=false")
-            .jsonPath()
-            .getString("[0].uuid");
-
-        given(specification)
-            .body("{" +
-                "  \"parent\":\"LinShareRootDomain\"," +
-                "  \"type\":\"TOPDOMAIN\"," +
-                "  \"providers\":[" +
-                "    {" +
-                "      \"ldapConnectionUuid\":\"" + ldapId + "\"," +
-                "      \"userLdapPatternUuid\":\"" + ldapPatternId + "\"," +
-                "      \"baseDn\":\"ou=People,dc=linshare,dc=org\"" +
-                "     }]," +
-                "  \"externalMailLocale\":\"ENGLISH\"," +
-                "  \"language\":\"ENGLISH\"," +
-                "  \"mailConfigUuid\":\"" + mailConfigId + "\"," +
-                "  \"currentWelcomeMessage\":{\"uuid\":\"" + welcomeMessageId + "\"}," +
-                "  \"mimePolicyUuid\":\"" + mimePolicyId + "\"," +
-                "  \"userRole\":\"SIMPLE\"," +
-                "  \"policy\":{\"identifier\":\"DefaultDomainPolicy\"}," +
-                "  \"label\":\"linshare.org\"," +
-                "  \"description\":\"linshare.org domain\"" +
-                "}")
-            .post("/linshare/webservice/rest/admin/domains");
-    }
-}
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java b/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java
index 9986bd7..6f33518 100644
--- a/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/Linshare.java
@@ -37,6 +37,7 @@ import io.restassured.specification.RequestSpecification;
 
 public class Linshare {
     private static final String WAIT_FOR_BACKEND_INIT_LOG = ".*Server startup.*";
+    private static final String WAIT_FOR_LDAP_INIT_LOG = ".*The following user provider for domain '.*' was successfully created.*";
     private static final int LINSHARE_BACKEND_PORT = 8080;
 
     private final GenericContainer<?> linshareBackend;
@@ -44,6 +45,7 @@ public class Linshare {
     private final GenericContainer<?> linshareSmtp;
     private final GenericContainer<?> linshareLdap;
     private final GenericContainer<?> linshareMongodb;
+    private final GenericContainer<?> linshareDBInit;
 
     private Network network;
 
@@ -55,6 +57,7 @@ public class Linshare {
         linshareLdap = createDockerLdap();
         linshareSmtp = createDockerSmtp();
         linshareBackend = createDockerBackend();
+        linshareDBInit = createLinshareBackendInit();
     }
 
     public void start() {
@@ -63,11 +66,11 @@ public class Linshare {
         linshareLdap.start();
         linshareSmtp.start();
         linshareBackend.start();
-
-        LDAPConfigurationPerformer.configureLdap(this);
+        linshareDBInit.start();
     }
 
     public void stop() {
+        linshareDBInit.stop();
         linshareDatabase.stop();
         linshareMongodb.stop();
         linshareLdap.stop();
@@ -139,6 +142,26 @@ public class Linshare {
             .withNetwork(network);
     }
 
+    private GenericContainer createLinshareBackendInit() {
+        return new GenericContainer<>("linagora/linshare-init:2.2")
+            .withNetworkAliases("init")
+            .withEnv("LS_HOST", "backend")
+            .withEnv("LS_PORT", "8080")
+            .withEnv("LS_LDAP_NAME", "ldap-local")
+            .withEnv("LS_LDAP_URL", "ldap://ldap:389")
+            .withEnv("LS_LDAP_BASE_DN", "ou=People,dc=linshare,dc=org")
+            .withEnv("LS_LDAP_DN", "cn=linshare,dc=linshare,dc=org")
+            .withEnv("LS_LDAP_PW", "linshare")
+            .withEnv("LS_DOMAIN_PATTERN_NAME", "openldap-local")
+            .withEnv("LS_DOMAIN_PATTERN_MODEL", "868400c0-c12e-456a-8c3c-19e985290586")
+            .withEnv("NO_REPLY_ADDRESS", "linshare-noreply@linshare.org")
+            .withEnv("DEBUG", "1")
+            .withEnv("FORCE_INIT", "1")
+            .waitingFor(Wait.forLogMessage(WAIT_FOR_LDAP_INIT_LOG, 1)
+                .withStartupTimeout(Duration.ofMinutes(10)))
+            .withNetwork(network);
+    }
+
     public RequestSpecification fakeSmtpRequestSpecification() {
         return new RequestSpecBuilder()
             .setContentType(ContentType.JSON)


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