Author: norman
Date: Wed Jan 18 15:27:59 2012
New Revision: 1232928

URL: http://svn.apache.org/viewvc?rev=1232928&view=rev
Log:
Add test for announce of starttls

Added:
    
james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractStartTlsSMTPServerTest.java
   (with props)
    
james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
   (with props)

Added: 
james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractStartTlsSMTPServerTest.java
URL: 
http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractStartTlsSMTPServerTest.java?rev=1232928&view=auto
==============================================================================
--- 
james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractStartTlsSMTPServerTest.java
 (added)
+++ 
james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractStartTlsSMTPServerTest.java
 Wed Jan 18 15:27:59 2012
@@ -0,0 +1,101 @@
+/****************************************************************
+ * 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.protocols.smtp;
+
+import static org.junit.Assert.assertTrue;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Locale;
+
+import org.apache.commons.net.smtp.SMTPReply;
+import org.apache.commons.net.smtp.SMTPSClient;
+import org.apache.james.protocols.api.Encryption;
+import org.apache.james.protocols.api.Protocol;
+import org.apache.james.protocols.api.ProtocolServer;
+import org.apache.james.protocols.api.handler.ProtocolHandler;
+import org.apache.james.protocols.api.handler.WiringException;
+import org.apache.james.protocols.api.utils.BogusSslContextFactory;
+import org.apache.james.protocols.api.utils.BogusTrustManagerFactory;
+import org.apache.james.protocols.api.utils.MockLogger;
+import org.apache.james.protocols.api.utils.TestUtils;
+import org.junit.Test;
+
+public abstract class AbstractStartTlsSMTPServerTest {
+    
+    protected SMTPSClient createClient() {
+        SMTPSClient client = new SMTPSClient(false, 
BogusSslContextFactory.getClientContext());
+        client.setTrustManager(BogusTrustManagerFactory.getTrustManagers()[0]);
+        return client;
+    }
+
+    protected abstract ProtocolServer createServer(Protocol protocol, 
InetSocketAddress address, Encryption enc);
+
+    
+    protected Protocol createProtocol(ProtocolHandler... handlers) throws 
WiringException {
+        SMTPProtocolHandlerChain chain = new SMTPProtocolHandlerChain();
+        chain.addAll(0, Arrays.asList(handlers));
+        chain.wireExtensibleHandlers();
+        return new SMTPProtocol(chain, new SMTPConfigurationImpl(), new 
MockLogger());
+    }
+
+
+    @Test
+    public void testStartTLSAnnounced() throws Exception {
+        InetSocketAddress address = new InetSocketAddress("127.0.0.1", 
TestUtils.getFreePort());
+        
+        
+        ProtocolServer server = null;
+        try {
+            server = createServer(createProtocol(new ProtocolHandler[0]), 
address, Encryption.createStartTls(BogusSslContextFactory.getServerContext())); 
 
+            server.bind();
+            
+            SMTPSClient client = createClient();
+            client.connect(address.getAddress().getHostAddress(), 
address.getPort());
+            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            
+            client.sendCommand("EHLO localhost");
+            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            
+            boolean startTLSAnnounced = false;
+            for (String reply: client.getReplyStrings()) {
+                if (reply.toUpperCase(Locale.UK).endsWith("STARTTLS")) {
+                    startTLSAnnounced = true;
+                    break;
+                }
+            }
+            assertTrue(startTLSAnnounced);
+            
+           // assertTrue(client.execTLS());
+            
+            client.quit();
+            assertTrue("Reply="+ client.getReplyString(), 
SMTPReply.isPositiveCompletion(client.getReplyCode()));
+            client.disconnect();
+
+
+        } finally {
+            if (server != null) {
+                server.unbind();
+            }
+        }
+        
+    }
+    
+    
+}

Propchange: 
james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractStartTlsSMTPServerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
URL: 
http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java?rev=1232928&view=auto
==============================================================================
--- 
james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
 (added)
+++ 
james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
 Wed Jan 18 15:27:59 2012
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.protocols.smtp.netty;
+
+import java.net.InetSocketAddress;
+
+import org.apache.james.protocols.api.Encryption;
+import org.apache.james.protocols.api.Protocol;
+import org.apache.james.protocols.api.ProtocolServer;
+import org.apache.james.protocols.netty.NettyServer;
+import org.apache.james.protocols.smtp.AbstractStartTlsSMTPServerTest;
+
+public class NettyStartTlsSMTPServerTest extends 
AbstractStartTlsSMTPServerTest{
+
+    @Override
+    protected ProtocolServer createServer(Protocol protocol, InetSocketAddress 
address, Encryption enc) {
+        NettyServer server = new NettyServer(protocol, enc);
+        server.setListenAddresses(address);
+        
+        return server;
+    }
+
+}

Propchange: 
james/protocols/trunk/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



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

Reply via email to