This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-jspf.git


The following commit(s) were added to refs/heads/master by this push:
     new 57968f0  Fix SPFSession inAddress
57968f0 is described below

commit 57968f0929f299d66ab91ba802acf9fafa3b96a7
Author: Emerson Pinter <e...@pinter.dev>
AuthorDate: Wed Jan 22 16:25:46 2025 -0300

    Fix SPFSession inAddress
    
    The inAddress field should not end up with a "in-addr" when the
    exception was handled in the constructor in the event of an invalid address 
is
    passed to IPAddr check. This commit sets the default value to "invalid"
    and adds some ip tests for SPFSession.
---
 .../org/apache/james/jspf/core/SPFSession.java     |  2 +-
 .../org/apache/james/jspf/core/SPFSessionTest.java | 46 +++++++++++++++++-----
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/resolver/src/main/java/org/apache/james/jspf/core/SPFSession.java 
b/resolver/src/main/java/org/apache/james/jspf/core/SPFSession.java
index a6672e8..7c9cf2b 100644
--- a/resolver/src/main/java/org/apache/james/jspf/core/SPFSession.java
+++ b/resolver/src/main/java/org/apache/james/jspf/core/SPFSession.java
@@ -46,7 +46,7 @@ public class SPFSession implements MacroData {
 
     private String currentDomain = ""; // (d)<current-domain>
 
-    private String inAddress = "in-addr"; // (v)
+    private String inAddress = "invalid"; // (v)
 
     private String clientDomain = null; // (p)
 
diff --git 
a/resolver/src/test/java/org/apache/james/jspf/core/SPFSessionTest.java 
b/resolver/src/test/java/org/apache/james/jspf/core/SPFSessionTest.java
index cec1afe..d4a697b 100644
--- a/resolver/src/test/java/org/apache/james/jspf/core/SPFSessionTest.java
+++ b/resolver/src/test/java/org/apache/james/jspf/core/SPFSessionTest.java
@@ -19,19 +19,47 @@
 
 package org.apache.james.jspf.core;
 
-import org.apache.james.jspf.core.exceptions.NoneException;
-import org.apache.james.jspf.core.exceptions.PermErrorException;
+import org.junit.Test;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
 
-public class SPFSessionTest extends TestCase {
-
-    /*
-     * Test method for 
'org.apache.james.jspf.core.SPF1Data.getMacroIpAddress()'
-     */
-    public void testGetMacroIpAddress() throws PermErrorException, 
NoneException {
+public class SPFSessionTest {
+    @Test
+    public void testGetMacroIpAddress() {
         SPFSession d = new 
SPFSession("mailf...@fromdomain.com","helodomain.com","2001:DB8::CB01");
         
assertEquals("2.0.0.1.0.D.B.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.C.B.0.1",d.getMacroIpAddress());
     }
 
+    @Test
+    public void shouldReturnInvalidIP6() {
+        String addr = "2001:db8::644:f:f:f:x";
+        SPFSession spfSession = new SPFSession("", "", addr);
+        assertEquals("invalid", spfSession.getInAddress());
+    }
+
+    @Test
+    public void shouldReturnInvalidIP4() {
+        String addr = "192.168.0.256";
+        SPFSession spfSession = new SPFSession("", "", addr);
+        assertEquals("invalid", spfSession.getInAddress());
+    }
+
+    @Test
+    public void shouldReturnValidIP6() {
+        String addr = "2001:db8::644:f:f:f:1";
+        SPFSession spfSession = new SPFSession("", "", addr);
+        assertEquals("ip6", spfSession.getInAddress());
+    }
+
+    @Test
+    public void shouldReturnIPv4Mapped() {
+        SPFSession spfSession = new SPFSession("", "", "::ffff:192.168.1.1");
+        assertEquals("ip6", spfSession.getInAddress());
+    }
+
+    @Test
+    public void shouldReturnIPv4() {
+        SPFSession spfSession = new SPFSession("", "", "192.168.1.1");
+        assertEquals("in-addr", spfSession.getInAddress());
+    }
 }


---------------------------------------------------------------------
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