use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.
the class SlowClientTest method testClientSlowToSend.
@Test
@Slow
public void testClientSlowToSend() throws Exception {
JettyTrackingSocket tsocket = new JettyTrackingSocket();
client.getPolicy().setIdleTimeout(60000);
URI wsUri = server.getWsUri();
Future<Session> future = client.connect(tsocket, wsUri);
IBlockheadServerConnection sconnection = server.accept();
sconnection.setSoTimeout(60000);
sconnection.upgrade();
// Confirm connected
future.get(30, TimeUnit.SECONDS);
tsocket.waitForConnected(30, TimeUnit.SECONDS);
int messageCount = 10;
// Setup server read thread
ServerReadThread reader = new ServerReadThread(sconnection, messageCount);
reader.start();
// Have client write slowly.
ClientWriteThread writer = new ClientWriteThread(tsocket.getSession());
writer.setMessageCount(messageCount);
writer.setMessage("Hello");
writer.setSlowness(10);
writer.start();
writer.join();
reader.waitForExpectedMessageCount(1, TimeUnit.MINUTES);
// Verify receive
Assert.assertThat("Frame Receive Count", reader.getFrameCount(), is(messageCount));
// Close
tsocket.getSession().close(StatusCode.NORMAL, "Done");
Assert.assertTrue("Client Socket Closed", tsocket.closeLatch.await(3, TimeUnit.MINUTES));
tsocket.assertCloseCode(StatusCode.NORMAL);
// stop reading
reader.cancel();
}
use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.
the class TestABCase6 method testCase6_4_3.
/**
* invalid text message, 1 frame/fragment (slowly, and split within code points)
* @throws Exception on test failure
*/
@Test
@Slow
public void testCase6_4_3() throws Exception {
// Disable Long Stacks from Parser (we know this test will throw an exception)
try (StacklessLogging scope = new StacklessLogging(Parser.class)) {
ByteBuffer payload = ByteBuffer.allocate(64);
BufferUtil.clearToFill(payload);
// good
payload.put(TypeUtil.fromHexString("cebae1bdb9cf83cebcceb5"));
// INVALID
payload.put(TypeUtil.fromHexString("f4908080"));
// good
payload.put(TypeUtil.fromHexString("656469746564"));
BufferUtil.flipToFlush(payload, 0);
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(payload));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
ByteBuffer net = fuzzer.asNetworkBuffer(send);
int[] splits = { 17, 21, net.limit() };
// Header + good UTF
ByteBuffer part1 = net.slice();
part1.limit(splits[0]);
// invalid UTF
ByteBuffer part2 = net.slice();
part2.position(splits[0]);
part2.limit(splits[1]);
// good UTF
ByteBuffer part3 = net.slice();
part3.position(splits[1]);
part3.limit(splits[2]);
// the header + good utf
fuzzer.send(part1);
TimeUnit.MILLISECONDS.sleep(500);
// the bad UTF
fuzzer.send(part2);
TimeUnit.MILLISECONDS.sleep(500);
// the rest (shouldn't work)
fuzzer.send(part3);
fuzzer.expect(expect);
}
}
}
use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.
the class TestABCase6 method testCase6_4_2.
/**
* invalid text message, 3 fragments.
* <p>
* fragment #1 is valid and ends in the middle of an incomplete code point.
* <p>
* fragment #2 finishes the UTF8 code point but it is invalid
* <p>
* fragment #3 contains the remainder of the message.
* @throws Exception on test failure
*/
@Test
@Slow
public void testCase6_4_2() throws Exception {
// split code point
byte[] part1 = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F4");
// continue code point & invalid
byte[] part2 = Hex.asByteArray("90");
// continue code point & finish
byte[] part3 = Hex.asByteArray("8080656469746564");
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false));
TimeUnit.SECONDS.sleep(1);
fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false));
TimeUnit.SECONDS.sleep(1);
fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true));
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.
the class TestABCase6 method testCase6_4_4.
/**
* invalid text message, 1 frame/fragment (slowly, and split within code points)
* @throws Exception on test failure
*/
@Test
@Slow
public void testCase6_4_4() throws Exception {
byte[] invalid = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F49080808080656469746564");
List<WebSocketFrame> send = new ArrayList<>();
send.add(new TextFrame().setPayload(ByteBuffer.wrap(invalid)));
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this);
StacklessLogging scope = new StacklessLogging(Parser.class)) {
fuzzer.connect();
ByteBuffer net = fuzzer.asNetworkBuffer(send);
fuzzer.send(net, 6);
fuzzer.send(net, 11);
TimeUnit.SECONDS.sleep(1);
fuzzer.send(net, 1);
TimeUnit.SECONDS.sleep(1);
// the rest
fuzzer.send(net, 100);
fuzzer.expect(expect);
}
}
use of org.eclipse.jetty.toolchain.test.annotation.Slow in project jetty.project by eclipse.
the class TestABCase6 method testCase6_4_1.
/**
* invalid text message, 3 fragments.
* <p>
* fragment #1 and fragment #3 are both valid in themselves.
* <p>
* fragment #2 contains the invalid utf8 code point.
* @throws Exception on test failure
*/
@Test
@Slow
public void testCase6_4_1() throws Exception {
byte[] part1 = StringUtil.getUtf8Bytes("κόσμε");
// invalid
byte[] part2 = Hex.asByteArray("F4908080");
byte[] part3 = StringUtil.getUtf8Bytes("edited");
List<WebSocketFrame> expect = new ArrayList<>();
expect.add(new CloseInfo(StatusCode.BAD_PAYLOAD).asFrame());
try (Fuzzer fuzzer = new Fuzzer(this)) {
fuzzer.connect();
fuzzer.setSendMode(Fuzzer.SendMode.BULK);
fuzzer.send(new TextFrame().setPayload(ByteBuffer.wrap(part1)).setFin(false));
TimeUnit.SECONDS.sleep(1);
fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part2)).setFin(false));
TimeUnit.SECONDS.sleep(1);
fuzzer.send(new ContinuationFrame().setPayload(ByteBuffer.wrap(part3)).setFin(true));
fuzzer.expect(expect);
}
}
Aggregations