Author: norman
Date: Fri Jul 14 08:58:37 2006
New Revision: 421930
URL: http://svn.apache.org/viewvc?rev=421930&view=rev
Log:
Add junit test for JAMES-566.
Modified:
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
Modified:
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java?rev=421930&r1=421929&r2=421930&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
(original)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
Fri Jul 14 08:58:37 2006
@@ -96,6 +96,10 @@
if ("127.0.0.1".equals(host)) return getLocalhostByName();
}
+ if ("1.0.0.127.bl.spamcop.net".equals(host)) {
+ return getLocalhostByName();
+ }
+
return InetAddress.getByName(host);
// throw new UnsupportedOperationException("getByName not
implemented in mock for host: "+host);
}
@@ -1068,5 +1072,57 @@
}
-
+ // Check if auth users get not rejected cause rbl. See JAMES-566
+ public void testDNSRBLNotRejectAuthUser() throws Exception {
+ m_testConfiguration.setAuthorizedAddresses("192.168.0.1/32");
+ m_testConfiguration.setAuthorizingAnnounce();
+ m_testConfiguration.useRBL(true);
+ finishSetUp(m_testConfiguration);
+
+ m_dnsServer.setLocalhostByName(InetAddress.getByName("127.0.0.1"));
+
+ SMTPClient smtpProtocol = new SMTPClient();
+ smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+
+ smtpProtocol.sendCommand("ehlo",
InetAddress.getLocalHost().toString());
+ String[] capabilityRes = smtpProtocol.getReplyStrings();
+
+ List capabilitieslist = new ArrayList();
+ for (int i = 1; i < capabilityRes.length; i++) {
+ capabilitieslist.add(capabilityRes[i].substring(4));
+ }
+
+ assertTrue("anouncing auth required", capabilitieslist
+ .contains("AUTH LOGIN PLAIN"));
+ // is this required or just for compatibility? assertTrue("anouncing
+ // auth required", capabilitieslist.contains("AUTH=LOGIN PLAIN"));
+
+ String userName = "test_user_smtp";
+ String sender = "[EMAIL PROTECTED]";
+
+ smtpProtocol.setSender(sender);
+
+ smtpProtocol.sendCommand("AUTH PLAIN");
+
+ m_usersRepository.addUser(userName, "pwd");
+
+ smtpProtocol.sendCommand("AUTH PLAIN");
+
+ smtpProtocol.sendCommand("AUTH PLAIN");
+ smtpProtocol.sendCommand(Base64.encodeAsString("\0" + userName
+ + "\0pwd\0"));
+ assertEquals("authenticated", 235, smtpProtocol.getReplyCode());
+
+ smtpProtocol.addRecipient("[EMAIL PROTECTED]");
+ assertEquals("authenticated.. not reject", 250, smtpProtocol
+ .getReplyCode());
+
+ smtpProtocol.sendShortMessageData("Subject: test\r\n\r\nTest
body\r\n");
+
+ smtpProtocol.quit();
+
+ // mail was propagated by SMTPServer
+ assertNotNull("mail received by mail server", m_mailServer
+ .getLastMail());
+ }
}
Modified:
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java?rev=421930&r1=421929&r2=421930&view=diff
==============================================================================
---
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
(original)
+++
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
Fri Jul 14 08:58:37 2006
@@ -40,6 +40,7 @@
private boolean m_reverseEqualsHelo = false;
private boolean m_reverseEqualsEhlo = false;
private int m_maxRcpt = 0;
+ private boolean m_useRBL = false;
public SMTPTestConfiguration(int smtpListenerPort) {
@@ -120,6 +121,10 @@
public void setHeloEhloEnforcement(boolean heloEhloEnforcement) {
m_heloEhloEnforcement = heloEhloEnforcement;
}
+
+ public void useRBL(boolean useRBL) {
+ m_useRBL = useRBL;
+ }
public void init() throws ConfigurationException {
@@ -137,8 +142,18 @@
handlerConfig.addChild(Util.getValuedConfiguration("heloEhloEnforcement",
m_heloEhloEnforcement+""));
if (m_verifyIdentity)
handlerConfig.addChild(Util.getValuedConfiguration("verifyIdentity", "" +
m_verifyIdentity));
+
handlerConfig.addChild(Util.createSMTPHandlerChainConfiguration());
+ if (m_useRBL) {
+ DefaultConfiguration handlerChain = (DefaultConfiguration)
handlerConfig
+ .getChild("handlerchain");
+ DefaultConfiguration handler = new DefaultConfiguration("handler");
+ handler.setAttribute("class", DNSRBLHandler.class.getName());
+ handlerChain.addChild(handler);
+ handlerConfig.addChild(handlerChain);
+ }
+
// Add Configuration for Helo checks and Ehlo checks
Configuration[] heloConfig =
handlerConfig.getChild("handlerchain").getChildren("handler");
for (int i = 0; i < heloConfig.length; i++) {
@@ -158,6 +173,21 @@
((DefaultConfiguration)
heloConfig[i]).addChild(Util.getValuedConfiguration("checkAuthClients",m_checkAuthClients+""));
} else if ("RCPT".equals(cmd)) {
((DefaultConfiguration)
heloConfig[i]).addChild(Util.getValuedConfiguration("maxRcpt",m_maxRcpt+""));
+ }
+ } else {
+ String className = ((DefaultConfiguration) heloConfig[i])
+ .getAttribute("class", null);
+
+ if (DNSRBLHandler.class.getName().equals(className)) {
+ DefaultConfiguration d = (DefaultConfiguration)
heloConfig[i];
+
+ DefaultConfiguration blacklist = new
DefaultConfiguration(
+ "blacklist");
+ blacklist.setValue("bl.spamcop.net");
+ DefaultConfiguration rblServers = new
DefaultConfiguration(
+ "rblservers");
+ rblServers.addChild(blacklist);
+ d.addChild(rblServers);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]