mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
Fix dspace-api module per new code style
This commit is contained in:
@@ -6,26 +6,25 @@
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.dspace.authenticate;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Mark Wood
|
||||
* @author Ben Bosman
|
||||
* @author Roeland Dillen
|
||||
*/
|
||||
public class IPMatcherTest
|
||||
{
|
||||
public class IPMatcherTest {
|
||||
private static final String IP6_FULL_ADDRESS1 = "2001:18e8:3:171:218:8bff:fe2a:56a4";
|
||||
private static final String IP6_FULL_ADDRESS2 = "2001:18e8:3:171:218:8bff:fe2a:56a3";
|
||||
private static final String IP6_MASKED_ADDRESS = "2001:18e8:3::/48";
|
||||
@@ -37,13 +36,12 @@ public class IPMatcherTest
|
||||
|
||||
/**
|
||||
* This also tests instantiation of correct masked and unmasked IPv6 addresses.
|
||||
* @throws IPMatcherException
|
||||
* if there is an error parsing the specification (i.e. it is
|
||||
* somehow malformed)
|
||||
*
|
||||
* @throws IPMatcherException if there is an error parsing the specification (i.e. it is
|
||||
* somehow malformed)
|
||||
*/
|
||||
@BeforeClass
|
||||
static public void setUp() throws IPMatcherException
|
||||
{
|
||||
static public void setUp() throws IPMatcherException {
|
||||
ip6FullMatcher = new IPMatcher(IP6_FULL_ADDRESS1);
|
||||
ip6MaskedMatcher = new IPMatcher(IP6_MASKED_ADDRESS);
|
||||
}
|
||||
@@ -51,40 +49,36 @@ public class IPMatcherTest
|
||||
/**
|
||||
* Test method for {@link org.dspace.authenticate.IPMatcher#IPMatcher(java.lang.String)}.
|
||||
*/
|
||||
@Test(expected=IPMatcherException.class)
|
||||
@Test(expected = IPMatcherException.class)
|
||||
public void testIPMatcherIp6Incomplete()
|
||||
throws IPMatcherException
|
||||
{
|
||||
throws IPMatcherException {
|
||||
new IPMatcher("1234:5"); // Incomplete IPv6 address
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.dspace.authenticate.IPMatcher#IPMatcher(java.lang.String)}.
|
||||
*/
|
||||
@Test(expected=IPMatcherException.class)
|
||||
@Test(expected = IPMatcherException.class)
|
||||
public void testIPMatcherIp6MaskOutOfRange()
|
||||
throws IPMatcherException
|
||||
{
|
||||
throws IPMatcherException {
|
||||
new IPMatcher("123::456/999"); // Mask bits out of range
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.dspace.authenticate.IPMatcher#IPMatcher(java.lang.String)}.
|
||||
*/
|
||||
@Test(expected=IPMatcherException.class)
|
||||
@Test(expected = IPMatcherException.class)
|
||||
public void testIPMatcherIp6MaskNotNumeric()
|
||||
throws IPMatcherException
|
||||
{
|
||||
throws IPMatcherException {
|
||||
new IPMatcher("123::456/abc"); // Mask is not a number
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.dspace.authenticate.IPMatcher#IPMatcher(java.lang.String)}.
|
||||
*/
|
||||
@Test(expected=IPMatcherException.class)
|
||||
@Test(expected = IPMatcherException.class)
|
||||
public void testIPMatcherIp6TooManySlashes()
|
||||
throws IPMatcherException
|
||||
{
|
||||
throws IPMatcherException {
|
||||
new IPMatcher("123::456/12/12"); // Too many slashes
|
||||
}
|
||||
|
||||
@@ -94,10 +88,9 @@ public class IPMatcherTest
|
||||
*/
|
||||
@Test
|
||||
public void testIp6FullMatch()
|
||||
throws IPMatcherException
|
||||
{
|
||||
throws IPMatcherException {
|
||||
assertTrue("IPv6 full match fails", ip6FullMatcher
|
||||
.match(IP6_FULL_ADDRESS1));
|
||||
.match(IP6_FULL_ADDRESS1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,10 +99,9 @@ public class IPMatcherTest
|
||||
*/
|
||||
@Test
|
||||
public void testIp6MisMatch()
|
||||
throws IPMatcherException
|
||||
{
|
||||
throws IPMatcherException {
|
||||
assertFalse("IPv6 full nonmatch succeeds", ip6FullMatcher
|
||||
.match(IP6_FULL_ADDRESS2));
|
||||
.match(IP6_FULL_ADDRESS2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,15 +110,13 @@ public class IPMatcherTest
|
||||
*/
|
||||
@Test
|
||||
public void testIp6MaskedMatch()
|
||||
throws IPMatcherException
|
||||
{
|
||||
throws IPMatcherException {
|
||||
assertTrue("IPv6 masked match fails", ip6MaskedMatcher
|
||||
.match(IP6_FULL_ADDRESS2));
|
||||
.match(IP6_FULL_ADDRESS2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIPv4MatchingSuccess() throws Exception
|
||||
{
|
||||
public void testIPv4MatchingSuccess() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("1.1.1.1");
|
||||
|
||||
assertTrue(ipMatcher.match("1.1.1.1"));
|
||||
@@ -136,74 +126,64 @@ public class IPMatcherTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIPv4MatchingFailure() throws Exception
|
||||
{
|
||||
public void testIPv4MatchingFailure() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("1.1.1.1");
|
||||
|
||||
assertFalse(ipMatcher.match("1.1.1.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIPv6MatchingSuccess() throws Exception
|
||||
{
|
||||
public void testIPv6MatchingSuccess() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("::2");
|
||||
|
||||
assertTrue(ipMatcher.match("0:0:0:0:0:0:0:2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortFormIPv6MatchingSuccess() throws Exception
|
||||
{
|
||||
public void testShortFormIPv6MatchingSuccess() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("::2");
|
||||
|
||||
assertTrue(ipMatcher.match("::2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIPv6MatchingFailure() throws Exception
|
||||
{
|
||||
public void testIPv6MatchingFailure() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("::2");
|
||||
|
||||
assertFalse(ipMatcher.match("0:0:0:0:0:0:0:1"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testAsteriskMatchingSuccess() throws Exception
|
||||
{
|
||||
public void testAsteriskMatchingSuccess() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("172.16");
|
||||
|
||||
assertTrue(ipMatcher.match("172.16.1.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsteriskMatchingFailure() throws Exception
|
||||
{
|
||||
public void testAsteriskMatchingFailure() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("172.16");
|
||||
|
||||
assertFalse(ipMatcher.match("172.15.255.255"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIPv4CIDRMatchingSuccess() throws Exception
|
||||
{
|
||||
public void testIPv4CIDRMatchingSuccess() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("192.1.2.3/8");
|
||||
|
||||
assertTrue(ipMatcher.match("192.1.1.1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIPv4CIDRMatchingFailure() throws Exception
|
||||
{
|
||||
public void testIPv4CIDRMatchingFailure() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("192.1.2.3/8");
|
||||
|
||||
assertTrue(ipMatcher.match("192.2.0.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2IPv4CIDRMatchingSuccess() throws Exception
|
||||
{
|
||||
public void test2IPv4CIDRMatchingSuccess() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("192.86.100.72/29");
|
||||
|
||||
assertTrue(ipMatcher.match("192.86.100.75"));
|
||||
@@ -222,8 +202,7 @@ public class IPMatcherTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3IPv4CIDRMatchingSuccess() throws Exception
|
||||
{
|
||||
public void test3IPv4CIDRMatchingSuccess() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("192.86.100.72/255.255.255.248");
|
||||
|
||||
assertTrue(ipMatcher.match("192.86.100.75"));
|
||||
@@ -242,81 +221,76 @@ public class IPMatcherTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIPv6CIDRMatchingSuccess() throws Exception
|
||||
{
|
||||
public void testIPv6CIDRMatchingSuccess() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("0:0:0:1::/64");
|
||||
|
||||
assertTrue(ipMatcher.match("0:0:0:1:ffff:ffff:ffff:ffff"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIPv6CIDRMatchingFailure() throws Exception
|
||||
{
|
||||
public void testIPv6CIDRMatchingFailure() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("0:0:0:1::/64");
|
||||
|
||||
assertFalse(ipMatcher.match("0:0:0:2::"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testIPv4IPv6Matching() throws Exception
|
||||
{
|
||||
public void testIPv4IPv6Matching() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("0.0.0.1");
|
||||
|
||||
assertTrue(ipMatcher.match("::1"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testSubnetZeroIPv6CIDRMatching() throws Exception
|
||||
{
|
||||
public void testSubnetZeroIPv6CIDRMatching() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("::1/0");
|
||||
|
||||
assertTrue(ipMatcher.match("::2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllOnesSubnetIPv4CIDRMatchingSuccess() throws Exception
|
||||
{
|
||||
public void testAllOnesSubnetIPv4CIDRMatchingSuccess() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("192.1.2.3/32");
|
||||
|
||||
assertTrue(ipMatcher.match("192.1.2.3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllOnesSubnetIPv4CIDRMatchingFailure() throws Exception
|
||||
{
|
||||
public void testAllOnesSubnetIPv4CIDRMatchingFailure() throws Exception {
|
||||
final IPMatcher ipMatcher = new IPMatcher("192.1.2.3/32");
|
||||
|
||||
assertFalse(ipMatcher.match("192.1.2.2"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ArrayList<String> getAllIp4Except(ArrayList<String> exceptions) {
|
||||
int d1 = 0, d2 = 0, d3 = 0, d4 = 0;
|
||||
ArrayList<String> ips = new ArrayList<String>();
|
||||
for (d1 = 0; d1 <= 255; d1+=increment)
|
||||
for (d2 = 0; d2 <= 255; d2+=increment)
|
||||
for (d3 = 0; d3 <= 255; d3+=increment)
|
||||
for (d4 = 0; d4 <= 255; d4+=increment) {
|
||||
String IP = d1+"."+d2+"."+d3+"."+d4;
|
||||
for (d1 = 0; d1 <= 255; d1 += increment) {
|
||||
for (d2 = 0; d2 <= 255; d2 += increment) {
|
||||
for (d3 = 0; d3 <= 255; d3 += increment) {
|
||||
for (d4 = 0; d4 <= 255; d4 += increment) {
|
||||
String IP = d1 + "." + d2 + "." + d3 + "." + d4;
|
||||
if (exceptions == null || !exceptions.contains(IP)) {
|
||||
ips.add(IP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ips;
|
||||
}
|
||||
|
||||
private void verifyAllIp4Except(ArrayList<String> exceptions, boolean asserted, IPMatcher ipMatcher) throws IPMatcherException {
|
||||
private void verifyAllIp4Except(ArrayList<String> exceptions, boolean asserted, IPMatcher ipMatcher)
|
||||
throws IPMatcherException {
|
||||
int d1 = 0, d2 = 0, d3 = 0, d4 = 0;
|
||||
for (d1 = 0; d1 <= 255; d1+=increment)
|
||||
for (d2 = 0; d2 <= 255; d2+=increment)
|
||||
for (d3 = 0; d3 <= 255; d3+=increment)
|
||||
for (d4 = 0; d4 <= 255; d4+=increment) {
|
||||
String IP = d1+"."+d2+"."+d3+"."+d4;
|
||||
for (d1 = 0; d1 <= 255; d1 += increment) {
|
||||
for (d2 = 0; d2 <= 255; d2 += increment) {
|
||||
for (d3 = 0; d3 <= 255; d3 += increment) {
|
||||
for (d4 = 0; d4 <= 255; d4 += increment) {
|
||||
String IP = d1 + "." + d2 + "." + d3 + "." + d4;
|
||||
if (exceptions != null && exceptions.contains(IP)) {
|
||||
if (asserted) {
|
||||
assertFalse(ipMatcher.match(IP));
|
||||
@@ -332,15 +306,14 @@ public class IPMatcherTest
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@AfterClass
|
||||
static public void cleanup()
|
||||
{
|
||||
static public void cleanup() {
|
||||
ip6FullMatcher = null;
|
||||
ip6MaskedMatcher = null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user