[java-opensaml] branch main updated: Extend unit test and stage a test for later.
Scott Cantor
cantor.2 at osu.edu
Tue Oct 20 13:05:07 UTC 2020
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=618226bb6eb59ad26b5264addcf93c00081c7c36
The following commit(s) were added to refs/heads/main by this push:
new 618226bb6 Extend unit test and stage a test for later.
618226bb6 is described below
commit 618226bb6eb59ad26b5264addcf93c00081c7c36
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Oct 20 09:05:04 2020 -0400
Extend unit test and stage a test for later.
---
opensaml-profile-api/pom.xml | 5 +++
.../profile/logic/IPRangePredicateTest.java | 40 ++++++++++++++++++----
.../src/test/resources/iprange.xml | 6 +---
3 files changed, 40 insertions(+), 11 deletions(-)
diff --git a/opensaml-profile-api/pom.xml b/opensaml-profile-api/pom.xml
index 03f6e4c58..596862ab9 100644
--- a/opensaml-profile-api/pom.xml
+++ b/opensaml-profile-api/pom.xml
@@ -65,6 +65,11 @@
<artifactId>spring-context</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>${spring.groupId}</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>net.shibboleth.ext</groupId>
<artifactId>spring-extensions</artifactId>
diff --git a/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java b/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java
index 68f286415..df0da9cbb 100644
--- a/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java
+++ b/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java
@@ -24,24 +24,52 @@ import net.shibboleth.ext.spring.util.ApplicationContextBuilder;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.io.ClassPathResource;
+import org.springframework.mock.web.MockHttpServletRequest;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
- *
+ * Unit test of {@link IPRangePredicate}.
*/
public class IPRangePredicateTest {
@Test public void testRanges() {
- final GenericApplicationContext ctx = new ApplicationContextBuilder()
+ final GenericApplicationContext ctx = new ApplicationContextBuilder()
.setName("IpRange")
.setServiceConfiguration(new ClassPathResource("iprange.xml"))
.setBeanPostProcessor(new IdentifiableBeanPostProcessor())
.build();
- final Map<String, IPRangePredicate> bar = ctx.getBeansOfType(IPRangePredicate.class);
-
- Assert.assertEquals(bar.size(), 2);
+ final Map<String,IPRangePredicate> map = ctx.getBeansOfType(IPRangePredicate.class);
+ Assert.assertEquals(map.size(), 2);
+
+ final MockHttpServletRequest request = new MockHttpServletRequest();
+
+ IPRangePredicate condition = map.get("three");
+ condition.setHttpServletRequest(request);
+
+ request.setRemoteAddr("192.168.1.128");
+ Assert.assertTrue(condition.test(null));
+
+ request.setRemoteAddr("192.168.3.128");
+ Assert.assertFalse(condition.test(null));
+
+ request.setRemoteAddr("::1");
+ Assert.assertFalse(condition.test(null));
+
+ condition = map.get("four");
+ condition.setHttpServletRequest(request);
+
+ request.setRemoteAddr("2620:df:8000:ff14:0:0:0:2");
+ Assert.assertTrue(condition.test(null));
+
+ request.setRemoteAddr("2620:df:8000:ff14:0:0:0:3");
+ Assert.assertFalse(condition.test(null));
+
+ // TODO reverse once we handle brackets.
+ request.setRemoteAddr("[2620:df:8000:ff14:0:0:0:2]");
+ Assert.assertFalse(condition.test(null));
}
-}
+
+}
\ No newline at end of file
diff --git a/opensaml-profile-api/src/test/resources/iprange.xml b/opensaml-profile-api/src/test/resources/iprange.xml
index 45ab4f21e..cc1bd74a6 100644
--- a/opensaml-profile-api/src/test/resources/iprange.xml
+++ b/opensaml-profile-api/src/test/resources/iprange.xml
@@ -16,14 +16,10 @@
</property>
</bean>
- <!-- Multiple address ranges with a list bean
- This fails because Spring cannot cast an ArrayList<String> to an Iterable<IPRAnge> (its too late for the converter to fire)
- -->
<bean id="four" class="org.opensaml.profile.logic.IPRangePredicate">
<property name="ranges">
<list>
- <value>192.168.1.0/24</value>
- <value>192.168.2.0/28</value>
+ <value>2620:df:8000:ff14:0:0:0:2/128</value>
</list>
</property>
</bean>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list