<artifactId>snakeyaml</artifactId>
<version>1.11</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ <type>jar</type>
+ </dependency>
</dependencies>
<build>
--- /dev/null
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package net.rizon.acid.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/**
+ *
+ * @author Orillion {@literal <orillion@rizon.net>}
+ */
+@RunWith(Parameterized.class)
+public class CloakGeneratorHostTest
+{
+ private static final String KEY_ONE = "kaflklLKJASLDFJALDFJAL91283013Ljldj23490jf290342ujdlow9234j1oid9023";
+ private static final String KEY_TWO = "IQUWE90834kljrn234jh782y3njf89y34h2jihnlkjnf2o3liwur4g2o3lLKJSDFL";
+ private static final String KEY_THREE = "9827342JLjsdr892u34kj2nlkjn234ukdmwlerj190234j1omkoe;23jLfjlskfj";
+ private static final String NETWORK = "Rizon-";
+
+ private static final String KEYS[] =
+ {
+ KEY_ONE, KEY_TWO, KEY_THREE
+ };
+
+ private final String host;
+ private final String expected;
+
+ private CloakGenerator cloakGenerator;
+
+ public CloakGeneratorHostTest(String host, String expected)
+ {
+ this.host = host;
+ this.expected = expected;
+ }
+
+ @Before
+ public void setUp()
+ {
+ this.cloakGenerator = new CloakGenerator(KEYS, NETWORK);
+ }
+
+ @After
+ public void tearDown()
+ {
+ this.cloakGenerator = null;
+ }
+
+ @Parameterized.Parameters
+ public static Collection ips6()
+ {
+ return Arrays.asList(new Object[][]
+ {
+ {
+ "ip31-20-10.12-1.0-2.sovereign.orillion.net", NETWORK + "298B6C75.sovereign.orillion.net"
+ },
+ {
+ "ip31-12-1.a12.0-2.sovereign.orillion.net", NETWORK + "CB8A6AD6.a12.0-2.sovereign.orillion.net"
+ },
+ {
+ "zaq77189a11.zaq.ne.jp", NETWORK + "5FEDBA88.zaq.ne.jp"
+ }
+ });
+ }
+
+ @Test
+ public void testHostCloak()
+ {
+ String result = this.cloakGenerator.cloak(this.host);
+ Assert.assertEquals(this.expected, result);
+ }
+}
--- /dev/null
+package net.rizon.acid.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/**
+ *
+ * @author Orillion {@literal <orillion@rizon.net>}
+ */
+@RunWith(Parameterized.class)
+public class CloakGeneratorIPv4Test
+{
+ private static final String KEY_ONE = "kaflklLKJASLDFJALDFJAL91283013Ljldj23490jf290342ujdlow9234j1oid9023";
+ private static final String KEY_TWO = "IQUWE90834kljrn234jh782y3njf89y34h2jihnlkjnf2o3liwur4g2o3lLKJSDFL";
+ private static final String KEY_THREE = "9827342JLjsdr892u34kj2nlkjn234ukdmwlerj190234j1omkoe;23jLfjlskfj";
+ private static final String NETWORK = "Rizon-";
+
+ private static final String KEYS[] =
+ {
+ KEY_ONE, KEY_TWO, KEY_THREE
+ };
+
+ private final String ipv6;
+ private final String expected;
+
+ private CloakGenerator cloakGenerator;
+
+ public CloakGeneratorIPv4Test(String ipv6, String expected)
+ {
+ this.ipv6 = ipv6;
+ this.expected = expected;
+ }
+
+ @Before
+ public void setUp()
+ {
+ this.cloakGenerator = new CloakGenerator(KEYS, NETWORK);
+ }
+
+ @After
+ public void tearDown()
+ {
+ this.cloakGenerator = null;
+ }
+
+ @Parameterized.Parameters
+ public static Collection ips6()
+ {
+ return Arrays.asList(new Object[][]
+ {
+ {
+ "112.186.100.39", "8218542D.87FC15FF.35D004AC.IP"
+ },
+ {
+ "41.102.164.2", "F51EFEE.2A9FE7F3.3D74DEC4.IP"
+ }
+ });
+ }
+
+ @Test
+ public void testIPv4Cloak()
+ {
+ String result = this.cloakGenerator.cloak(this.ipv6);
+ Assert.assertEquals(this.expected, result);
+ }
+}
--- /dev/null
+package net.rizon.acid.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/**
+ * Tests the cloak generator functionality for IPv6 addresses.
+ * <p>
+ * @author Orillion {@literal <orillion@rizon.net>}
+ */
+@RunWith(Parameterized.class)
+public class CloakGeneratorIPv6Test
+{
+ private static final String KEY_ONE = "kaflklLKJASLDFJALDFJAL91283013Ljldj23490jf290342ujdlow9234j1oid9023";
+ private static final String KEY_TWO = "IQUWE90834kljrn234jh782y3njf89y34h2jihnlkjnf2o3liwur4g2o3lLKJSDFL";
+ private static final String KEY_THREE = "9827342JLjsdr892u34kj2nlkjn234ukdmwlerj190234j1omkoe;23jLfjlskfj";
+ private static final String NETWORK = "Rizon-";
+
+ private static final String KEYS[] =
+ {
+ KEY_ONE, KEY_TWO, KEY_THREE
+ };
+
+ private final String ipv6;
+ private final String expected;
+
+ private CloakGenerator cloakGenerator;
+
+ /**
+ * Constructor, used to run the parameterized tests.
+ * <p>
+ * @param ipv6 ipv6 address to test.
+ * @param expected expected cloaked ipv6 address.
+ */
+ public CloakGeneratorIPv6Test(String ipv6, String expected)
+ {
+ this.ipv6 = ipv6;
+ this.expected = expected;
+ }
+
+ /**
+ * Constructs a new {@link CloakGenerator} for each test.
+ */
+ @Before
+ public void setUp()
+ {
+ this.cloakGenerator = new CloakGenerator(KEYS, NETWORK);
+ }
+
+ /**
+ * Clears the {@link CloakGenerator} after each test.
+ */
+ @After
+ public void tearDown()
+ {
+ this.cloakGenerator = null;
+ }
+
+ /**
+ * List of ipv6 addresses to test. Contains input and expected results.
+ * <p>
+ * @return A collection of inputs and their expected result.
+ */
+ @Parameterized.Parameters
+ public static Collection ips6()
+ {
+ return Arrays.asList(new Object[][]
+ {
+ {
+ "dead:beef:b00b::2", "EE00F4FD:3DF800EC:F7D016F5:IP"
+ },
+ {
+ "dead:beef:b00b:0:30c4:3d53:12dd:2fcb", "8EC92880:29837DE1:F7D016F5:IP"
+ }
+ });
+ }
+
+ /**
+ * Test function, reused for each parameter.
+ */
+ @Test
+ public void testIPv6Cloak()
+ {
+ String result = this.cloakGenerator.cloak(this.ipv6);
+ Assert.assertEquals(this.expected, result);
+ }
+}
--- /dev/null
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package net.rizon.acid.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ * @author Orillion {@literal <orillion@rizon.net>}
+ */
+public class CloakGeneratorTest
+{
+ private static final String KEY_ONE = "kaflklLKJASLDFJALDFJAL91283013Ljldj23490jf290342ujdlow9234j1oid9023";
+ private static final String KEY_TWO = "IQUWE90834kljrn234jh782y3njf89y34h2jihnlkjnf2o3liwur4g2o3lLKJSDFL";
+ private static final String KEY_THREE = "9827342JLjsdr892u34kj2nlkjn234ukdmwlerj190234j1omkoe;23jLfjlskfj";
+ private static final String NETWORK = "Rizon-";
+
+ private static final String KEYS[] =
+ {
+ KEY_ONE, KEY_TWO, KEY_THREE
+ };
+
+ private CloakGenerator cloakGenerator;
+
+ public CloakGeneratorTest()
+ {
+ }
+
+ @Before
+ public void setUp()
+ {
+ cloakGenerator = new CloakGenerator(KEYS, NETWORK);
+ }
+
+ @After
+ public void tearDown()
+ {
+ cloakGenerator = null;
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testConstructorEmptyKeys()
+ {
+ String keys[] = new String[0];
+ cloakGenerator = new CloakGenerator(keys, NETWORK);
+ }
+
+ @Test
+ public void testConstructorEmptyNetwork()
+ {
+ cloakGenerator = new CloakGenerator(KEYS, "");
+ }
+
+ /**
+ * Test of validateCloakKey method, of class CloakGenerator.
+ */
+ @Test
+ public void testValidateCloakKeyNoUpper()
+ {
+ String key = "a1";
+ boolean expResult = false;
+ boolean result = CloakGenerator.validateCloakKey(key);
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testValidateCloakKeyNoLower()
+ {
+ String key = "A1";
+ boolean expResult = false;
+ boolean result = CloakGenerator.validateCloakKey(key);
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testValidateCloakKeyNoDigit()
+ {
+ String key = "aA";
+ boolean expResult = false;
+ boolean result = CloakGenerator.validateCloakKey(key);
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testValidateCloakKey()
+ {
+ String key = "aA1";
+ boolean expResult = true;
+ boolean result = CloakGenerator.validateCloakKey(key);
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testValidateCloakKeyExtra()
+ {
+ String key = "aA1;";
+ boolean expResult = true;
+ boolean result = CloakGenerator.validateCloakKey(key);
+ assertEquals(expResult, result);
+ }
+}