From 5003049edb722ad7c415981fa2c85c17ba876264 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Mon, 13 Aug 2018 11:56:17 +0200 Subject: Check length of classify session's match vector (HC2VPP-373) Change-Id: I45028349f81a756d03d46e02af40041a7cae1fec Signed-off-by: Marek Gradzki --- .../write/ClassifySessionWriterTest.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'vpp-classifier/impl/src/test') diff --git a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java index ccb02708e..68d20a728 100644 --- a/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java +++ b/vpp-classifier/impl/src/test/java/io/fd/hc2vpp/vpp/classifier/write/ClassifySessionWriterTest.java @@ -99,6 +99,8 @@ public class ClassifySessionWriterTest extends WriterCustomizerTest { when(classfierContext.getTableIndex(TABLE_NAME, mappingContext)).thenReturn(TABLE_INDEX); final ClassifyTable table = mock(ClassifyTable.class); + when(table.getMask()).thenReturn(new HexString("00:00:00:00:00:00:ff:FF:ff:ff:ff:FF:00:00:00:00")); + when(table.getSkipNVectors()).thenReturn(0L); when(table.getClassifierNode()).thenReturn(new VppNodeName("ip4-classifier")); when(writeContext.readAfter(ArgumentMatchers.any())).thenReturn(Optional.of(table)); when(writeContext.readBefore(ArgumentMatchers.any())).thenReturn(Optional.of(table)); @@ -190,4 +192,32 @@ public class ClassifySessionWriterTest extends WriterCustomizerTest { final InstanceIdentifier id = getClassifySessionId(TABLE_NAME, match); customizer.writeCurrentAttributes(id, classifySession, writeContext); } + + @Test(expected = IllegalArgumentException.class) + public void testCreateInvalidMatchLength() throws WriteFailedException { + final ClassifyTable table = mock(ClassifyTable.class); + when(table.getMask()).thenReturn(new HexString("00:00:00:00:00:00:ff:FF:ff:ff:ff:FF:00:00:00:00")); + when(table.getSkipNVectors()).thenReturn(1L); + when(writeContext.readAfter(ArgumentMatchers.any())).thenReturn(Optional.of(table)); + + final String match = "00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00"; + final ClassifySession classifySession = generateClassifySession(SESSION_INDEX, match); + final InstanceIdentifier id = getClassifySessionId(TABLE_NAME, match); + customizer.writeCurrentAttributes(id, classifySession, writeContext); + } + + @Test + public void testCreateSkipOneVector() throws WriteFailedException { + final ClassifyTable table = mock(ClassifyTable.class); + when(table.getMask()).thenReturn(new HexString("00:00:00:00:00:00:ff:FF:ff:ff:ff:FF:00:00:00:00")); + when(table.getSkipNVectors()).thenReturn(1L); + when(writeContext.readAfter(ArgumentMatchers.any())).thenReturn(Optional.of(table)); + whenClassifyAddDelSessionThenSuccess(); + + final String match = + "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01:02:03:04:05:06:00:00:00:00"; + final ClassifySession classifySession = generateClassifySession(SESSION_INDEX, match); + final InstanceIdentifier id = getClassifySessionId(TABLE_NAME, match); + customizer.writeCurrentAttributes(id, classifySession, writeContext); + } } \ No newline at end of file -- cgit 1.2.3-korg