Re-enable tests on mappingservice.implementation
[lispflowmapping.git] / mappingservice / implementation / src / test / java / org / opendaylight / lispflowmapping / implementation / authentication / LispAuthenticationTest.java
index d4e7a2107fbed2ac3444b626dfb9cc421ee32871..f61cd668efb3f20522cfa3cbbe35421febdbac07 100644 (file)
@@ -19,13 +19,20 @@ import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
 import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer;
 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkeyBuilder;
 
 public class LispAuthenticationTest extends BaseTestCase {
+    private static final String PASSWORD = "password";
+    private static final String WRONG_PASSWORD = "wrongPassword";
+
+    private static final Eid EID = LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32");
 
     @Test
     public void validate_WrongAuthentication() throws Exception {
@@ -40,13 +47,13 @@ public class LispAuthenticationTest extends BaseTestCase {
         // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
         // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
         //
-        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
-                + "00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 " //
-                + "b0 21 27 a8 21 41 04 f3 46 5a 5a 5b 5c 5d 00 00 " //
-                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
+                + "00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 "
+                + "b0 21 27 a8 21 41 04 f3 46 5a 5a 5b 5c 5d 00 00 "
+                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 "
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
-        assertFalse(LispAuthenticationUtil.validate(mapRegister, "password"));
+        assertFalse(validate(mapRegister, EID, 1, PASSWORD));
     }
 
     @Test
@@ -62,13 +69,13 @@ public class LispAuthenticationTest extends BaseTestCase {
         // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
         // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
         //
-        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
-                + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
-                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
+                + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 "
+                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 "
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
-        assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
-        assertFalse(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
+        assertTrue(validate(mapRegister, EID, 1, PASSWORD));
+        assertFalse(validate(mapRegister, EID, 1, WRONG_PASSWORD));
     }
 
     @Test
@@ -88,13 +95,16 @@ public class LispAuthenticationTest extends BaseTestCase {
         MapRegister mapRegister = MapRegisterSerializer
                 .getInstance()
                 .deserialize(
-                        hexToByteBuffer("38 00 01 01 FF BB " //
-                                + "00 00 00 00 00 00 00 02 00 20 70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d 68 a5 bf 32 11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 00 00 " //
-                                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                                + "ff 00 00 05 00 01 c0 a8 88 0a"));
-
-        assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
-        assertFalse(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
+                        hexToByteBuffer("38 00 01 01 FF BB "
+                                + "00 00 00 00 00 00 00 02 00 20 "
+                                + "70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d "
+                                + "68 a5 bf 32 11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 "
+                                + "00 00 "
+                                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 "
+                                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
+
+        assertTrue(validate(mapRegister, EID, 2, PASSWORD));
+        assertFalse(validate(mapRegister, EID, 2, WRONG_PASSWORD));
     }
 
     @Test
@@ -109,14 +119,14 @@ public class LispAuthenticationTest extends BaseTestCase {
         // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
         // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
         //
-        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
-                + "00 00 00 00 00 00 00 00 00 00 " //
-                + "00 00 " //
-                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
-
-        assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
-        assertTrue(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
+        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
+                + "00 00 00 00 00 00 00 00 00 00 "
+                + "00 00 "
+                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 "
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
+
+        assertTrue(validate(mapRegister, EID, 0, PASSWORD));
+        assertTrue(validate(mapRegister, EID, 0, WRONG_PASSWORD));
     }
 
     // @Test
@@ -172,7 +182,13 @@ public class LispAuthenticationTest extends BaseTestCase {
         etlrBuilder.setRecordTtl(55);
         mapNotifyBuilder.getMappingRecordItem().add(
                 new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
-        ArrayAssert.assertEquals(new byte[0], LispAuthenticationUtil.createAuthenticationData(mapNotifyBuilder.build(), "password"));
+        ArrayAssert.assertEquals(new byte[0], LispAuthenticationUtil.createAuthenticationData(mapNotifyBuilder.build(),
+                "password"));
+
+    }
 
+    private static boolean validate(MapRegister mapRegister, Eid eid, int keyId, String password) {
+        MappingAuthkey key = new MappingAuthkeyBuilder().setKeyType(keyId).setKeyString(password).build();
+        return LispAuthenticationUtil.validate(mapRegister, eid, key);
     }
 }