Refactoring out the basic good/bad UTF tests from TestABCase6 into separate parameterized test cases
This commit is contained in:
parent
6c0bb390ae
commit
e04bb3128c
|
@ -29,6 +29,9 @@ import org.junit.runner.RunWith;
|
|||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
/**
|
||||
* Test various invalid frame situations
|
||||
*/
|
||||
@RunWith(value = Parameterized.class)
|
||||
public class TestABCase3
|
||||
{
|
||||
|
|
|
@ -4,8 +4,19 @@ import org.junit.runner.RunWith;
|
|||
import org.junit.runners.Suite;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses(
|
||||
{ TestABCase1.class, TestABCase2.class, TestABCase3.class, TestABCase4.class, TestABCase5.class, TestABCase6.class, TestABCase7_9.class })
|
||||
// @formatter:off
|
||||
@Suite.SuiteClasses( {
|
||||
TestABCase1.class,
|
||||
TestABCase2.class,
|
||||
TestABCase3.class,
|
||||
TestABCase4.class,
|
||||
TestABCase5.class,
|
||||
TestABCase6.class,
|
||||
TestABCase6_GoodUTF.class,
|
||||
TestABCase6_BadUTF.class,
|
||||
TestABCase7_9.class
|
||||
})
|
||||
// @formatter:on
|
||||
public class AllTests
|
||||
{
|
||||
/* let junit do the rest */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,157 @@
|
|||
package org.eclipse.jetty.websocket.server.ab;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.protocol.CloseInfo;
|
||||
import org.eclipse.jetty.websocket.protocol.OpCode;
|
||||
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.server.helper.Hex;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
/**
|
||||
* Tests of Known Bad UTF8 sequences that should trigger a {@link StatusCode#BAD_PAYLOAD} close and early connection termination
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestABCase6_BadUTF extends AbstractABCase
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(TestABCase6_BadUTF.class);
|
||||
|
||||
@Parameters
|
||||
public static Collection<String[]> data()
|
||||
{
|
||||
// The various Good UTF8 sequences as a String (hex form)
|
||||
List<String[]> data = new ArrayList<>();
|
||||
|
||||
// @formatter:off
|
||||
// - differently unicode fragmented
|
||||
data.add(new String[]{ "6.3.1", "CEBAE1BDB9CF83CEBCCEB5EDA080656469746564" });
|
||||
// - partial/incomplete multi-byte code points
|
||||
data.add(new String[]{ "6.6.1", "CE" });
|
||||
data.add(new String[]{ "6.6.3", "CEBAE1" });
|
||||
data.add(new String[]{ "6.6.4", "CEBAE1BD" });
|
||||
data.add(new String[]{ "6.6.6", "CEBAE1BDB9CF" });
|
||||
data.add(new String[]{ "6.6.8", "CEBAE1BDB9CF83CE" });
|
||||
data.add(new String[]{ "6.6.10", "CEBAE1BDB9CF83CEBCCE" });
|
||||
// - first possible sequence length 5/6 (invalid code points)
|
||||
data.add(new String[]{ "6.8.1", "F888808080" });
|
||||
data.add(new String[]{ "6.8.2", "FC8480808080" });
|
||||
// - last possible sequence length (invalid code points)
|
||||
data.add(new String[]{ "6.10.1", "F7BFBFBF" });
|
||||
data.add(new String[]{ "6.10.2", "FBBFBFBFBF" });
|
||||
data.add(new String[]{ "6.10.3", "FDBFBFBFBFBF" });
|
||||
// - other boundary conditions
|
||||
data.add(new String[]{ "6.11.5", "F4908080" });
|
||||
// - unexpected continuation bytes
|
||||
data.add(new String[]{ "6.12.1", "80" });
|
||||
data.add(new String[]{ "6.12.2", "BF" });
|
||||
data.add(new String[]{ "6.12.3", "80BF" });
|
||||
data.add(new String[]{ "6.12.4", "80BF80" });
|
||||
data.add(new String[]{ "6.12.5", "80BF80BF" });
|
||||
data.add(new String[]{ "6.12.6", "80BF80BF80" });
|
||||
data.add(new String[]{ "6.12.7", "80BF80BF80BF" });
|
||||
data.add(new String[]{ "6.12.8", "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9"
|
||||
+ "FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBE" });
|
||||
// - lonely start characters
|
||||
data.add(new String[]{ "6.13.1", "C020C120C220C320C420C520C620C720C820C920CA20CB20CC20CD20CE20CF2"
|
||||
+ "0D020D120D220D320D420D520D620D720D820D920DA20DB20DC20DD20DE20" });
|
||||
data.add(new String[]{ "6.13.2", "E020E120E220E320E420E520E620E720E820E920EA20EB20EC20ED20EE20" });
|
||||
data.add(new String[]{ "6.13.3", "F020F120F220F320F420F520F620" });
|
||||
data.add(new String[]{ "6.13.4", "F820F920FA20" });
|
||||
data.add(new String[]{ "6.13.5", "FC20" });
|
||||
// - sequences with last continuation byte missing
|
||||
data.add(new String[]{ "6.14.1", "C0" });
|
||||
data.add(new String[]{ "6.14.2", "E080" });
|
||||
data.add(new String[]{ "6.14.3", "F08080" });
|
||||
data.add(new String[]{ "6.14.4", "F8808080" });
|
||||
data.add(new String[]{ "6.14.5", "FC80808080" });
|
||||
data.add(new String[]{ "6.14.6", "DF" });
|
||||
data.add(new String[]{ "6.14.7", "EFBF" });
|
||||
data.add(new String[]{ "6.14.8", "F7BFBF" });
|
||||
data.add(new String[]{ "6.14.9", "FBBFBFBF" });
|
||||
data.add(new String[]{ "6.14.10", "FDBFBFBFBF" });
|
||||
// - concatenation of incomplete sequences
|
||||
data.add(new String[]{ "6.15.1", "C0E080F08080F8808080FC80808080DFEFBFF7BFBFFBBFBFBFFDBFBFBFBF" });
|
||||
// - impossible bytes
|
||||
data.add(new String[]{ "6.16.1", "FE" });
|
||||
data.add(new String[]{ "6.16.2", "FF" });
|
||||
data.add(new String[]{ "6.16.3", "FEFEFFFF" });
|
||||
// - overlong ascii characters
|
||||
data.add(new String[]{ "6.17.1", "C0AF" });
|
||||
data.add(new String[]{ "6.17.2", "E080AF" });
|
||||
data.add(new String[]{ "6.17.3", "F08080AF" });
|
||||
data.add(new String[]{ "6.17.4", "F8808080AF" });
|
||||
data.add(new String[]{ "6.17.5", "FC80808080AF" });
|
||||
// - maximum overlong sequences
|
||||
data.add(new String[]{ "6.18.1", "C1BF" });
|
||||
data.add(new String[]{ "6.18.2", "E09FBF" });
|
||||
data.add(new String[]{ "6.18.3", "F08FBFBF" });
|
||||
data.add(new String[]{ "6.18.4", "F887BFBFBF" });
|
||||
data.add(new String[]{ "6.18.5", "FC83BFBFBFBF" });
|
||||
// - overlong representation of NUL character
|
||||
data.add(new String[]{ "6.19.1", "C080" });
|
||||
data.add(new String[]{ "6.19.2", "E08080" });
|
||||
data.add(new String[]{ "6.19.3", "F0808080" });
|
||||
data.add(new String[]{ "6.19.4", "F880808080" });
|
||||
data.add(new String[]{ "6.19.5", "FC8080808080" });
|
||||
// - single UTF-16 surrogates
|
||||
data.add(new String[]{ "6.20.1", "EDA080" });
|
||||
data.add(new String[]{ "6.20.2", "EDADBF" });
|
||||
data.add(new String[]{ "6.20.3", "EDAE80" });
|
||||
data.add(new String[]{ "6.20.4", "EDAFBF" });
|
||||
data.add(new String[]{ "6.20.5", "EDB080" });
|
||||
data.add(new String[]{ "6.20.6", "EDBE80" });
|
||||
data.add(new String[]{ "6.20.7", "EDBFBF" });
|
||||
// - paired UTF-16 surrogates
|
||||
data.add(new String[]{ "6.21.1", "EDA080EDB080" });
|
||||
data.add(new String[]{ "6.21.2", "EDA080EDBFBF" });
|
||||
data.add(new String[]{ "6.21.3", "EDADBFEDB080" });
|
||||
data.add(new String[]{ "6.21.4", "EDADBFEDBFBF" });
|
||||
data.add(new String[]{ "6.21.5", "EDAE80EDB080" });
|
||||
data.add(new String[]{ "6.21.6", "EDAE80EDBFBF" });
|
||||
data.add(new String[]{ "6.21.7", "EDAFBFEDB080" });
|
||||
data.add(new String[]{ "6.21.8", "EDAFBFEDBFBF" });
|
||||
// @formatter:on
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private final byte[] invalid;
|
||||
|
||||
public TestABCase6_BadUTF(String testId, String hexMsg)
|
||||
{
|
||||
LOG.debug("Test ID: {}",testId);
|
||||
this.invalid = Hex.asByteArray(hexMsg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertBadTextPayload() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(invalid));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package org.eclipse.jetty.websocket.server.ab;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.StatusCode;
|
||||
import org.eclipse.jetty.websocket.protocol.CloseInfo;
|
||||
import org.eclipse.jetty.websocket.protocol.OpCode;
|
||||
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.server.helper.Hex;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
/**
|
||||
* Tests of Known Good UTF8 sequences.
|
||||
* <p>
|
||||
* Should be preserved / echoed back, with normal close code.
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestABCase6_GoodUTF extends AbstractABCase
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(TestABCase6_GoodUTF.class);
|
||||
|
||||
@Parameters
|
||||
public static Collection<String[]> data()
|
||||
{
|
||||
// The various Good UTF8 sequences as a String (hex form)
|
||||
List<String[]> data = new ArrayList<>();
|
||||
|
||||
// @formatter:off
|
||||
// - combination of simple 1 byte characters and unicode code points
|
||||
data.add(new String[]{ "6.2.1", "48656C6C6F2DC2B540C39FC3B6C3A4C3BCC3A0C3A12D5554462D382121" });
|
||||
// - simple valid UTF8 sequence
|
||||
data.add(new String[]{ "6.5.1", "CEBAE1BDB9CF83CEBCCEB5" });
|
||||
// - multi-byte code points
|
||||
data.add(new String[]{ "6.6.11", "CEBAE1BDB9CF83CEBCCEB5" });
|
||||
data.add(new String[]{ "6.6.2", "CEBA" });
|
||||
data.add(new String[]{ "6.6.5", "CEBAE1BDB9" });
|
||||
data.add(new String[]{ "6.6.7", "CEBAE1BDB9CF83" });
|
||||
data.add(new String[]{ "6.6.9", "CEBAE1BDB9CF83CEBC" });
|
||||
// - first possible sequence of a certain length (1 code point)
|
||||
data.add(new String[]{ "6.7.1", "00" });
|
||||
data.add(new String[]{ "6.7.2", "C280" });
|
||||
data.add(new String[]{ "6.7.3", "E0A080" });
|
||||
data.add(new String[]{ "6.7.4", "F0908080" });
|
||||
// - last possible sequence of a certain length (1 code point)
|
||||
data.add(new String[]{ "6.9.1", "7F" });
|
||||
data.add(new String[]{ "6.9.2", "DFBF" });
|
||||
data.add(new String[]{ "6.9.3", "EFBFBF" });
|
||||
data.add(new String[]{ "6.9.4", "F48FBFBF" });
|
||||
// - other boundary conditions
|
||||
data.add(new String[]{ "6.11.1", "ED9FBF" });
|
||||
data.add(new String[]{ "6.11.2", "EE8080" });
|
||||
data.add(new String[]{ "6.11.3", "EFBFBD" });
|
||||
data.add(new String[]{ "6.11.4", "F48FBFBF" });
|
||||
// - non character code points
|
||||
data.add(new String[]{ "6.22.1", "EFBFBE" });
|
||||
data.add(new String[]{ "6.22.2", "EFBFBF" });
|
||||
data.add(new String[]{ "6.22.3", "F09FBFBE" });
|
||||
data.add(new String[]{ "6.22.4", "F09FBFBF" });
|
||||
data.add(new String[]{ "6.22.5", "F0AFBFBE" });
|
||||
data.add(new String[]{ "6.22.6", "F0AFBFBF" });
|
||||
data.add(new String[]{ "6.22.7", "F0BFBFBE" });
|
||||
data.add(new String[]{ "6.22.8", "F0BFBFBF" });
|
||||
data.add(new String[]{ "6.22.9", "F18FBFBE" });
|
||||
data.add(new String[]{ "6.22.10", "F18FBFBF" });
|
||||
data.add(new String[]{ "6.22.11", "F19FBFBE" });
|
||||
data.add(new String[]{ "6.22.12", "F19FBFBF" });
|
||||
data.add(new String[]{ "6.22.13", "F1AFBFBE" });
|
||||
data.add(new String[]{ "6.22.14", "F1AFBFBF" });
|
||||
data.add(new String[]{ "6.22.15", "F1BFBFBE" });
|
||||
data.add(new String[]{ "6.22.16", "F1BFBFBF" });
|
||||
data.add(new String[]{ "6.22.17", "F28FBFBE" });
|
||||
data.add(new String[]{ "6.22.18", "F28FBFBF" });
|
||||
data.add(new String[]{ "6.22.19", "F29FBFBE" });
|
||||
data.add(new String[]{ "6.22.20", "F29FBFBF" });
|
||||
data.add(new String[]{ "6.22.21", "F2AFBFBE" });
|
||||
data.add(new String[]{ "6.22.22", "F2AFBFBF" });
|
||||
data.add(new String[]{ "6.22.23", "F2BFBFBE" });
|
||||
data.add(new String[]{ "6.22.24", "F2BFBFBF" });
|
||||
data.add(new String[]{ "6.22.25", "F38FBFBE" });
|
||||
data.add(new String[]{ "6.22.26", "F38FBFBF" });
|
||||
data.add(new String[]{ "6.22.27", "F39FBFBE" });
|
||||
data.add(new String[]{ "6.22.28", "F39FBFBF" });
|
||||
data.add(new String[]{ "6.22.29", "F3AFBFBE" });
|
||||
data.add(new String[]{ "6.22.30", "F3AFBFBF" });
|
||||
data.add(new String[]{ "6.22.31", "F3BFBFBE" });
|
||||
data.add(new String[]{ "6.22.32", "F3BFBFBF" });
|
||||
data.add(new String[]{ "6.22.33", "F48FBFBE" });
|
||||
data.add(new String[]{ "6.22.34", "F48FBFBF" });
|
||||
// - unicode replacement character
|
||||
data.add(new String[]{ "6.23.1", "EFBFBD" });
|
||||
// @formatter:on
|
||||
|
||||
return data;
|
||||
}
|
||||
private final byte[] msg;
|
||||
|
||||
public TestABCase6_GoodUTF(String testId, String hexMsg)
|
||||
{
|
||||
LOG.debug("Test ID: {}",testId);
|
||||
this.msg = Hex.asByteArray(hexMsg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertEchoTextMessage() throws Exception
|
||||
{
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new WebSocketFrame(OpCode.TEXT).setPayload(msg));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
{
|
||||
fuzzer.connect();
|
||||
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
|
||||
fuzzer.send(send);
|
||||
fuzzer.expect(expect);
|
||||
}
|
||||
finally
|
||||
{
|
||||
fuzzer.close();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue