You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by sc...@apache.org on 2018/11/21 22:48:01 UTC
svn commit: r1847144 -
/tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java
Author: schultz
Date: Wed Nov 21 22:48:01 2018
New Revision: 1847144
URL: http://svn.apache.org/viewvc?rev=1847144&view=rev
Log:
Add unit tests to ensure ciphertext uniqueness and test multiple message delivery.
Modified:
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java
Modified: tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java?rev=1847144&r1=1847143&r2=1847144&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java (original)
+++ tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java Wed Nov 21 22:48:01 2018
@@ -36,6 +36,8 @@ import org.apache.catalina.tribes.group.
import org.apache.catalina.tribes.group.InterceptorPayload;
import org.apache.catalina.tribes.io.ChannelData;
import org.apache.catalina.tribes.io.XByteBuffer;
+import org.hamcrest.core.IsEqual;
+import org.hamcrest.core.IsNot;
/**
* Tests the EncryptInterceptor.
@@ -78,6 +80,34 @@ public class TestEncryptInterceptor {
}
@Test
+ public void testMultipleMessages() throws Exception {
+ src.start(Channel.SND_TX_SEQ);
+ dest.start(Channel.SND_TX_SEQ);
+
+ String testInput = "The quick brown fox jumps over the lazy dog.";
+
+ Assert.assertEquals("Basic roundtrip failed",
+ testInput,
+ roundTrip(testInput, src, dest));
+
+ Assert.assertEquals("Second roundtrip failed",
+ testInput,
+ roundTrip(testInput, src, dest));
+
+ Assert.assertEquals("Third roundtrip failed",
+ testInput,
+ roundTrip(testInput, src, dest));
+
+ Assert.assertEquals("Fourth roundtrip failed",
+ testInput,
+ roundTrip(testInput, src, dest));
+
+ Assert.assertEquals("Fifth roundtrip failed",
+ testInput,
+ roundTrip(testInput, src, dest));
+ }
+
+ @Test
public void testTinyPayload() throws Exception {
src.start(Channel.SND_TX_SEQ);
dest.start(Channel.SND_TX_SEQ);
@@ -271,6 +301,28 @@ public class TestEncryptInterceptor {
}
@Test
+ public void testMessageUniqueness() throws Exception {
+ src.start(Channel.SND_TX_SEQ);
+ src.setNext(new ValueCaptureInterceptor());
+
+ String testInput = "The quick brown fox jumps over the lazy dog.";
+
+ ChannelData msg = new ChannelData(false);
+ msg.setMessage(new XByteBuffer(testInput.getBytes("UTF-8"), false));
+ src.sendMessage(null, msg, null);
+
+ byte[] cipherText1 = ((ValueCaptureInterceptor)src.getNext()).getValue();
+
+ msg.setMessage(new XByteBuffer(testInput.getBytes("UTF-8"), false));
+ src.sendMessage(null, msg, null);
+
+ byte[] cipherText2 = ((ValueCaptureInterceptor)src.getNext()).getValue();
+
+ Assert.assertThat("Two identical cleartexts encrypt to the same ciphertext",
+ cipherText1, IsNot.not(IsEqual.equalTo(cipherText2)));
+ }
+
+ @Test
public void testPickup() throws Exception {
File file = new File("message.bin");
if(!file.exists()) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org