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-jspf.git
commit c2aa2607eb8a1ccf8b88dc538efe65dfdbb10bc0
Author: Emerson Pinter <[email protected]>
AuthorDate: Wed Jan 22 13:13:32 2025 -0300
Add tests for cases when the dns is unreachable
When a PortUnreachableException or SocketException happens, a temperror
should be returned.
---
.../AsynchronousSPFExecutorIntegrationTest.java | 21 +++++++++++++++++++++
.../SynchronousSPFExecutorIntegrationTest.java | 22 ++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/resolver/src/test/java/org/apache/james/jspf/AsynchronousSPFExecutorIntegrationTest.java b/resolver/src/test/java/org/apache/james/jspf/AsynchronousSPFExecutorIntegrationTest.java
index 7103d27..e0f346b 100644
--- a/resolver/src/test/java/org/apache/james/jspf/AsynchronousSPFExecutorIntegrationTest.java
+++ b/resolver/src/test/java/org/apache/james/jspf/AsynchronousSPFExecutorIntegrationTest.java
@@ -21,15 +21,19 @@ package org.apache.james.jspf;
import static org.junit.Assert.assertEquals;
+import org.apache.james.jspf.executor.AsynchronousSPFExecutor;
import org.apache.james.jspf.executor.SPFResult;
+import org.apache.james.jspf.impl.DNSServiceXBillImpl;
import org.apache.james.jspf.impl.DefaultSPF;
import org.apache.james.jspf.impl.SPF;
import org.junit.BeforeClass;
import org.junit.Test;
import org.xbill.DNS.Lookup;
+import org.xbill.DNS.Resolver;
import org.xbill.DNS.SimpleResolver;
import java.net.UnknownHostException;
+import java.util.concurrent.ThreadLocalRandom;
public class AsynchronousSPFExecutorIntegrationTest {
@BeforeClass
@@ -73,4 +77,21 @@ public class AsynchronousSPFExecutorIntegrationTest {
System.out.println(result.getHeader());
assertEquals("none", result.getResult());
}
+
+ @Test
+ public void shouldReturnTempErrorOnPortUnreachable() throws UnknownHostException {
+ Resolver simpleResolver = new SimpleResolver("127.0.0.1");
+ simpleResolver.setPort(ThreadLocalRandom.current().nextInt(55000, 56000));
+
+ DNSServiceXBillImpl dns = new DNSServiceXBillImpl(simpleResolver);
+
+ SPF spf = new SPF(dns, new AsynchronousSPFExecutor(dns));
+ SPFResult result = spf.checkSPF("207.54.72.202",
+ "[email protected]",
+ "reyifglerifwukfvbdjhrkbvebvekvfulervkerkeruerbeb.de");
+ System.out.println(result.getResult());
+ System.out.println(result.getExplanation());
+ System.out.println(result.getHeader());
+ assertEquals("temperror", result.getResult());
+ }
}
diff --git a/resolver/src/test/java/org/apache/james/jspf/SynchronousSPFExecutorIntegrationTest.java b/resolver/src/test/java/org/apache/james/jspf/SynchronousSPFExecutorIntegrationTest.java
index 4bfd81e..db6ff9e 100644
--- a/resolver/src/test/java/org/apache/james/jspf/SynchronousSPFExecutorIntegrationTest.java
+++ b/resolver/src/test/java/org/apache/james/jspf/SynchronousSPFExecutorIntegrationTest.java
@@ -19,15 +19,20 @@
package org.apache.james.jspf;
+import org.apache.james.jspf.executor.AsynchronousSPFExecutor;
import org.apache.james.jspf.executor.SPFResult;
+import org.apache.james.jspf.executor.SynchronousSPFExecutor;
+import org.apache.james.jspf.impl.DNSServiceXBillImpl;
import org.apache.james.jspf.impl.DefaultSPF;
import org.apache.james.jspf.impl.SPF;
import org.junit.BeforeClass;
import org.junit.Test;
import org.xbill.DNS.Lookup;
+import org.xbill.DNS.Resolver;
import org.xbill.DNS.SimpleResolver;
import java.net.UnknownHostException;
+import java.util.concurrent.ThreadLocalRandom;
import static org.junit.Assert.assertEquals;
@@ -73,4 +78,21 @@ public class SynchronousSPFExecutorIntegrationTest {
System.out.println(result.getHeader());
assertEquals("none", result.getResult());
}
+
+ @Test
+ public void shouldReturnTempErrorOnPortUnreachable() throws UnknownHostException {
+ Resolver simpleResolver = new SimpleResolver("127.0.0.1");
+ simpleResolver.setPort(ThreadLocalRandom.current().nextInt(55000, 56000));
+
+ DNSServiceXBillImpl dns = new DNSServiceXBillImpl(simpleResolver);
+
+ SPF spf = new SPF(dns, new SynchronousSPFExecutor(dns));
+ SPFResult result = spf.checkSPF("207.54.72.202",
+ "[email protected]",
+ "reyifglerifwukfvbdjhrkbvebvekvfulervkerkeruerbeb.de");
+ System.out.println(result.getResult());
+ System.out.println(result.getExplanation());
+ System.out.println(result.getHeader());
+ assertEquals("temperror", result.getResult());
+ }
}
\ No newline at end of file
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.