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 2015/06/26 18:20:22 UTC

svn commit: r1687798 - in /james/mpt/trunk/impl/imap-mailbox: core/src/main/java/org/apache/james/mpt/imapmailbox/ core/src/main/java/org/apache/james/mpt/imapmailbox/suite/ core/src/main/resources/org/apache/james/imap/scripts/ cyrus/src/test/java/org...

Author: btellier
Date: Fri Jun 26 16:20:22 2015
New Revision: 1687798

URL: http://svn.apache.org/r1687798
Log:
MPT-14 Adding tests for ACL commands

Added:
    james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/GrantRightsOnHost.java
    james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/ACLCommands.java
    james/mpt/trunk/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ACLCommandsOnOtherUser.test
    james/mpt/trunk/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ACLCommandsOnOwner.test
    james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/GrantRightsOnCyrusHost.java
Modified:
    james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTest.java
    james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTestModule.java
    james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java

Added: james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/GrantRightsOnHost.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/GrantRightsOnHost.java?rev=1687798&view=auto
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/GrantRightsOnHost.java (added)
+++ james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/GrantRightsOnHost.java Fri Jun 26 16:20:22 2015
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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.mpt.imapmailbox;
+
+import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxPath;
+
+public interface GrantRightsOnHost {
+
+    void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.MailboxACLRights rights) throws Exception;
+
+}

Added: james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/ACLCommands.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/ACLCommands.java?rev=1687798&view=auto
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/ACLCommands.java (added)
+++ james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/ACLCommands.java Fri Jun 26 16:20:22 2015
@@ -0,0 +1,86 @@
+/****************************************************************
+ * 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.mpt.imapmailbox.suite;
+
+import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.SimpleMailboxACL;
+import org.apache.james.mpt.api.HostSystem;
+import org.apache.james.mpt.imapmailbox.GrantRightsOnHost;
+import org.apache.james.mpt.imapmailbox.suite.base.BaseImapProtocol;
+import org.junit.Test;
+
+import javax.inject.Inject;
+import java.util.Locale;
+
+public class ACLCommands extends BaseImapProtocol {
+    public static final String OTHER_USER_NAME = "Boby";
+    public static final String OTHER_USER_PASSWORD = "password";
+    public static final MailboxPath OTHER_USER_MAILBOX = new MailboxPath("#private", OTHER_USER_NAME, "") ;
+    private MailboxACL.MailboxACLRights readWriteSeenRight;
+
+    @Inject
+    private static HostSystem system;
+    @Inject
+    private GrantRightsOnHost grantRightsOnHost;
+
+    public ACLCommands() throws Exception {
+        super(system);
+        readWriteSeenRight = new SimpleMailboxACL.Rfc4314Rights("rsw");
+    }
+
+    @Test
+    public void testACLCommandsOwnerUS() throws Exception {
+        scriptTest("ACLCommandsOnOwner", Locale.US);
+    }
+
+    @Test
+    public void testACLCommandsOtherUserUS() throws Exception {
+        system.addUser(OTHER_USER_NAME, OTHER_USER_PASSWORD);
+        grantRightsOnHost.grantRights(OTHER_USER_MAILBOX, USER, readWriteSeenRight);
+        scriptTest("ACLCommandsOnOtherUser", Locale.US);
+    }
+
+    @Test
+    public void testACLCommandsOwnerKorea() throws Exception {
+        scriptTest("ACLCommandsOnOwner", Locale.KOREA);
+    }
+
+    @Test
+    public void testACLCommandsOtherUserKorea() throws Exception {
+        system.addUser(OTHER_USER_NAME, OTHER_USER_PASSWORD);
+        grantRightsOnHost.grantRights(OTHER_USER_MAILBOX, USER, readWriteSeenRight);
+        scriptTest("ACLCommandsOnOtherUser", Locale.KOREA);
+    }
+
+
+    @Test
+    public void testACLCommandsOwnerItaly() throws Exception {
+        scriptTest("ACLCommandsOnOwner", Locale.ITALY);
+    }
+
+    @Test
+    public void testACLCommandsOtherUserItaly() throws Exception {
+        system.addUser(OTHER_USER_NAME, OTHER_USER_PASSWORD);
+        grantRightsOnHost.grantRights(OTHER_USER_MAILBOX, USER, readWriteSeenRight);
+        scriptTest("ACLCommandsOnOtherUser", Locale.ITALY);
+    }
+
+}

Added: james/mpt/trunk/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ACLCommandsOnOtherUser.test
URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ACLCommandsOnOtherUser.test?rev=1687798&view=auto
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ACLCommandsOnOtherUser.test (added)
+++ james/mpt/trunk/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ACLCommandsOnOtherUser.test Fri Jun 26 16:20:22 2015
@@ -0,0 +1,27 @@
+################################################################
+# 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.                                           #
+################################################################
+
+C: a000 LOGIN imapuser password
+S: \* OK IMAP4rev1 Server ready
+S: a000 OK .*
+
+C: a001 MYRIGHTS user.Boby
+S: \* MYRIGHTS user.Boby rsw
+S: a001 OK Completed
+

Added: james/mpt/trunk/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ACLCommandsOnOwner.test
URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ACLCommandsOnOwner.test?rev=1687798&view=auto
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ACLCommandsOnOwner.test (added)
+++ james/mpt/trunk/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ACLCommandsOnOwner.test Fri Jun 26 16:20:22 2015
@@ -0,0 +1,77 @@
+################################################################
+# 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.                                           #
+################################################################
+
+C: a000 LOGIN imapuser password
+S: \* OK IMAP4rev1 Server ready
+S: a000 OK .*
+
+C: a001 GETACL INBOX
+S: \* ACL INBOX imapuser lrswipkxtecda
+S: a001 OK Completed
+
+C: a002 SETACL INBOX Boby +rsw
+S: a002 OK Completed
+
+C: a003 GETACL INBOX
+S: \* ACL INBOX imapuser lrswipkxtecda boby rsw
+S: a003 OK Completed
+
+C: a004 SETACL INBOX Boby +wa
+S: a004 OK Completed
+
+C: a005 GETACL INBOX
+S: \* ACL INBOX imapuser lrswipkxtecda boby rswa
+S: a005 OK Completed
+
+C: a006 SETACL INBOX Boby -rat
+S: a006 OK Completed
+
+C: a007 GETACL INBOX
+S: \* ACL INBOX imapuser lrswipkxtecda boby sw
+S: a007 OK Completed
+
+C: a008 DELETEACL INBOX Boby
+S: a008 OK Completed
+
+C: a009 GETACL INBOX
+S: \* ACL INBOX imapuser lrswipkxtecda
+S: a009 OK Completed
+
+C: a010 GETACL INBOX
+S: \* ACL INBOX imapuser lrswipkxtecda
+S: a010 OK Completed
+
+C: a011 LISTRIGHTS INBOX imapuser
+S: \* LISTRIGHTS INBOX imapuser lkxca r s w i p t e d 0 1 2 3 4 5 6 7 8 9
+S: a011 OK Completed
+
+C: a012 LISTRIGHTS INBOX Boby
+S: \* LISTRIGHTS INBOX Boby p l r s w i k x t e c d a 0 1 2 3 4 5 6 7 8 9
+S: a012 OK Completed
+
+C: a013 SETACL INBOX Boby +rsw
+S: a013 OK Completed
+
+C: a014 LISTRIGHTS INBOX Boby
+S: \* LISTRIGHTS INBOX Boby p l r s w i k x t e c d a 0 1 2 3 4 5 6 7 8 9
+S: a014 OK Completed
+
+C: a015 MYRIGHTS INBOX
+S: \* MYRIGHTS INBOX lrswipkxtecda
+S: a015 OK Completed
\ No newline at end of file

Modified: james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTest.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTest.java?rev=1687798&r1=1687797&r2=1687798&view=diff
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTest.java (original)
+++ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTest.java Fri Jun 26 16:20:22 2015
@@ -19,15 +19,15 @@
 
 package org.apache.james.mpt.imapmailbox.cyrus;
 
+import org.apache.james.mpt.imapmailbox.suite.ACLCommands;
 import org.apache.onami.test.OnamiSuite;
 import org.apache.onami.test.annotation.GuiceModules;
-import org.junit.Ignore;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite.SuiteClasses;
 
-@Ignore("JWC-156 create mailbox in Cyrus")
 @RunWith(OnamiSuite.class)
-@SuiteClasses({ 
+@SuiteClasses({
+    ACLCommands.class
 //    AuthenticatedState.class,
 //    ConcurrentSessions.class,
 //    Events.class,

Modified: james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTestModule.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTestModule.java?rev=1687798&r1=1687797&r2=1687798&view=diff
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTestModule.java (original)
+++ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTestModule.java Fri Jun 26 16:20:22 2015
@@ -4,12 +4,14 @@ import org.apache.james.mpt.api.HostSyst
 import org.apache.james.mpt.api.ImapHostSystem;
 import org.apache.james.mpt.api.UserAdder;
 import org.apache.james.mpt.host.ExternalHostSystem;
+import org.apache.james.mpt.imapmailbox.GrantRightsOnHost;
 import org.apache.james.mpt.imapmailbox.cyrus.host.CyrusHostSystem;
 import org.apache.james.mpt.imapmailbox.cyrus.host.CyrusUserAdder;
 import org.apache.james.mpt.imapmailbox.cyrus.host.Docker;
 
 import com.google.inject.AbstractModule;
 import com.spotify.docker.client.messages.ContainerCreation;
+import org.apache.james.mpt.imapmailbox.cyrus.host.GrantRightsOnCyrusHost;
 
 public class CyrusMailboxTestModule extends AbstractModule {
 
@@ -21,5 +23,6 @@ public class CyrusMailboxTestModule exte
         bind(HostSystem.class).to(CyrusHostSystem.class);
         bind(ExternalHostSystem.class).to(CyrusHostSystem.class);
         bind(UserAdder.class).to(CyrusUserAdder.class);
+        bind(GrantRightsOnHost.class).to(GrantRightsOnCyrusHost.class);
     }
 }

Modified: james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java?rev=1687798&r1=1687797&r2=1687798&view=diff
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java (original)
+++ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java Fri Jun 26 16:20:22 2015
@@ -20,6 +20,8 @@ package org.apache.james.mpt.imapmailbox
 
 import java.net.InetSocketAddress;
 
+import com.google.common.base.Joiner;
+import com.google.common.base.Strings;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mpt.api.Session;
@@ -90,14 +92,33 @@ public class CyrusHostSystem extends Ext
     
     @Override
     public void createMailbox(MailboxPath mailboxPath) {
-        ProtocolSession protocolSession = new ProtocolSession();
-        protocolSession.SL(".*", CREATE_MAILBOX_LOCATION);
-        protocolSession.CL(". LOGIN cyrus cyrus");
-        protocolSession.SL("\\. OK .*", CREATE_MAILBOX_LOCATION);
-        protocolSession.CL(String.format("A1 CREATE user.%s.%s", mailboxPath.getUser(), mailboxPath.getName()));
+        ProtocolSession protocolSession = logAndGetAdminProtocolSession(new ProtocolSession());
+        protocolSession.CL(String.format("A1 CREATE %s", createMailboxStringFromMailboxPath(mailboxPath)));
         protocolSession.SL("A1 OK .*", CREATE_MAILBOX_LOCATION);
+        executeProtocolSession(logoutAndGetProtocolSession(protocolSession));
+    }
+
+    public ProtocolSession logoutAndGetProtocolSession(ProtocolSession protocolSession) {
         protocolSession.CL("A2 LOGOUT");
         protocolSession.SL("\\* BYE .*", CREATE_MAILBOX_LOCATION);
+        return protocolSession;
+    }
+
+    public ProtocolSession logAndGetAdminProtocolSession(ProtocolSession protocolSession) {
+        protocolSession.SL(".*", CREATE_MAILBOX_LOCATION);
+        protocolSession.CL(". LOGIN cyrus cyrus");
+        protocolSession.SL("\\. OK .*", CREATE_MAILBOX_LOCATION);
+        return protocolSession;
+    }
+
+    public String createMailboxStringFromMailboxPath(MailboxPath mailboxPath) {
+        return Joiner.on('.').skipNulls()
+            .join("user",
+                mailboxPath.getUser(),
+                Strings.emptyToNull(mailboxPath.getName()));
+    }
+
+    public void executeProtocolSession(ProtocolSession protocolSession) {
         try {
             Session session = newSession(null);
             try {

Added: james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/GrantRightsOnCyrusHost.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/GrantRightsOnCyrusHost.java?rev=1687798&view=auto
==============================================================================
--- james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/GrantRightsOnCyrusHost.java (added)
+++ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/GrantRightsOnCyrusHost.java Fri Jun 26 16:20:22 2015
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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.mpt.imapmailbox.cyrus.host;
+
+import com.google.inject.Inject;
+import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mpt.imapmailbox.GrantRightsOnHost;
+import org.apache.james.mpt.protocol.ProtocolSession;
+
+public class GrantRightsOnCyrusHost implements GrantRightsOnHost {
+    private static final String GRANT_RIGHTS_LOCATION = "ACLCommands.grantRights";
+
+    private CyrusHostSystem system;
+
+    @Inject
+    private GrantRightsOnCyrusHost(CyrusHostSystem system) {
+        this.system = system;
+    }
+
+    public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.MailboxACLRights rights) throws Exception {
+        ProtocolSession protocolSession = system.logAndGetAdminProtocolSession(new ProtocolSession());
+        protocolSession.CL(String.format("A1 SETACL %s %s %s",
+            system.createMailboxStringFromMailboxPath(mailboxPath),
+            userName,
+            rights.serialize()));
+        protocolSession.SL("A1 OK .*", GRANT_RIGHTS_LOCATION);
+        system.executeProtocolSession(system.logoutAndGetProtocolSession(protocolSession));
+    }
+}



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