Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2012-07-31 18:24:33 -0400
committerJoakim Erdfelt2012-07-31 18:24:33 -0400
commitab89924261bb2465a370929cb34917cef302b668 (patch)
treed48c34ee7daa1fcf3b65f010e8d97833ee44c7a0 /jetty-websocket
parenta97fe106f9b11d6d3f3791ad10b36101736c0c17 (diff)
downloadorg.eclipse.jetty.project-ab89924261bb2465a370929cb34917cef302b668.tar.gz
org.eclipse.jetty.project-ab89924261bb2465a370929cb34917cef302b668.tar.xz
org.eclipse.jetty.project-ab89924261bb2465a370929cb34917cef302b668.zip
Fleshing out more AB case 4 tests
Diffstat (limited to 'jetty-websocket')
-rw-r--r--jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/Fuzzer.java1
-rw-r--r--jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase4.java121
2 files changed, 96 insertions, 26 deletions
diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/Fuzzer.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/Fuzzer.java
index 89183d1230..46ccb7e8d7 100644
--- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/Fuzzer.java
+++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/Fuzzer.java
@@ -162,6 +162,7 @@ public class Fuzzer
{
for (WebSocketFrame f : send)
{
+ f.setMask(MASK); // make sure we have mask set
// Using lax generator, generate and send
client.writeRaw(generator.generate(f));
client.flush();
diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase4.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase4.java
index 0e0682a52e..5c4e6c23f7 100644
--- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase4.java
+++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase4.java
@@ -1,10 +1,8 @@
package org.eclipse.jetty.websocket.server.ab;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.protocol.CloseInfo;
@@ -19,17 +17,9 @@ public class TestABCase4 extends AbstractABCase
@Test
public void testCase4_1_1() throws Exception
{
- ByteBuffer buf = ByteBuffer.allocate(32);
- BufferUtil.clearToFill(buf);
+ List<WebSocketFrame> send = new ArrayList<>();
+ send.add(new WebSocketFrame((byte)3)); // intentionally bad
- // Construct bad frame by hand
- byte opcode = 3;
- buf.put((byte)(0x00 | FIN | opcode)); // bad
- putPayloadLength(buf,0);
- putMask(buf);
- BufferUtil.flipToFlush(buf,0);
-
- // Expectations
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
@@ -38,7 +28,7 @@ public class TestABCase4 extends AbstractABCase
{
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
- fuzzer.send(buf);
+ fuzzer.send(send);
fuzzer.expect(expect);
}
finally
@@ -54,19 +44,98 @@ public class TestABCase4 extends AbstractABCase
public void testCase4_1_2() throws Exception
{
byte payload[] = StringUtil.getUtf8Bytes("reserved payload");
- ByteBuffer buf = ByteBuffer.allocate(32);
- BufferUtil.clearToFill(buf);
-
- // Construct bad frame by hand
- byte opcode = 4;
- buf.put((byte)(0x00 | FIN | opcode)); // bad
- putPayloadLength(buf,payload.length);
- putMask(buf);
- buf.put(masked(payload));
- BufferUtil.flipToFlush(buf,0);
-
- // Expectations
+
+ List<WebSocketFrame> send = new ArrayList<>();
+ send.add(new WebSocketFrame((byte)4).setPayload(payload)); // intentionally bad
+
+ List<WebSocketFrame> expect = new ArrayList<>();
+ expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
+
+ Fuzzer fuzzer = new Fuzzer(this);
+ try
+ {
+ fuzzer.connect();
+ fuzzer.setSendMode(Fuzzer.SendMode.BULK);
+ fuzzer.send(send);
+ fuzzer.expect(expect);
+ }
+ finally
+ {
+ fuzzer.close();
+ }
+ }
+
+ /**
+ * Send small text, then frame with opcode 5 (reserved), then ping
+ */
+ @Test
+ public void testCase4_1_3() throws Exception
+ {
+ List<WebSocketFrame> send = new ArrayList<>();
+ send.add(WebSocketFrame.text("hello"));
+ send.add(new WebSocketFrame((byte)5)); // intentionally bad
+ send.add(WebSocketFrame.ping());
+
+ List<WebSocketFrame> expect = new ArrayList<>();
+ expect.add(WebSocketFrame.text("hello")); // echo
+ expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
+
+ Fuzzer fuzzer = new Fuzzer(this);
+ try
+ {
+ fuzzer.connect();
+ fuzzer.setSendMode(Fuzzer.SendMode.BULK);
+ fuzzer.send(send);
+ fuzzer.expect(expect);
+ }
+ finally
+ {
+ fuzzer.close();
+ }
+ }
+
+ /**
+ * Send small text, then frame with opcode 6 (reserved) w/payload, then ping
+ */
+ @Test
+ public void testCase4_1_4() throws Exception
+ {
+ List<WebSocketFrame> send = new ArrayList<>();
+ send.add(WebSocketFrame.text("hello"));
+ send.add(new WebSocketFrame((byte)6).setPayload("bad")); // intentionally bad
+ send.add(WebSocketFrame.ping());
+
+ List<WebSocketFrame> expect = new ArrayList<>();
+ expect.add(WebSocketFrame.text("hello")); // echo
+ expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
+
+ Fuzzer fuzzer = new Fuzzer(this);
+ try
+ {
+ fuzzer.connect();
+ fuzzer.setSendMode(Fuzzer.SendMode.BULK);
+ fuzzer.send(send);
+ fuzzer.expect(expect);
+ }
+ finally
+ {
+ fuzzer.close();
+ }
+ }
+
+ /**
+ * Send small text, then frame with opcode 7 (reserved) w/payload, then ping
+ */
+ @Test
+ public void testCase4_1_5() throws Exception
+ {
+ List<WebSocketFrame> send = new ArrayList<>();
+ send.add(WebSocketFrame.text("hello"));
+ send.add(new WebSocketFrame((byte)7).setPayload("bad")); // intentionally bad
+ send.add(WebSocketFrame.ping());
+
List<WebSocketFrame> expect = new ArrayList<>();
+ expect.add(WebSocketFrame.text("hello")); // echo
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
Fuzzer fuzzer = new Fuzzer(this);
@@ -74,7 +143,7 @@ public class TestABCase4 extends AbstractABCase
{
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
- fuzzer.send(buf);
+ fuzzer.send(send);
fuzzer.expect(expect);
}
finally

Back to the top