Fixing old testcase as fallout from API updates

This commit is contained in:
Joakim Erdfelt 2012-06-26 16:36:38 -07:00
parent 334b7787cc
commit e32249c24f
1 changed files with 258 additions and 473 deletions

View File

@ -178,7 +178,7 @@ public class WebSocketMessageRFC6455Test
}
private static final int WSVERSION = org.eclipse.jetty.websocket.api.WebSocket.VERSION;
private static final int WSVERSION = 13; // RFC-6455 version
private static Server __server;
private static SelectChannelConnector __connector;
private static TestWebSocket __serverWebSocket;
@ -217,7 +217,6 @@ public class WebSocketMessageRFC6455Test
__server.start();
}
@AfterClass
public static void stopServer() throws Exception
{
@ -225,8 +224,7 @@ public class WebSocketMessageRFC6455Test
__server.join();
}
private void lookFor(String string,InputStream in)
throws IOException
private void lookFor(String string, InputStream in) throws IOException
{
String orig = string;
Utf8StringBuilder scanned = new Utf8StringBuilder();
@ -255,8 +253,7 @@ public class WebSocketMessageRFC6455Test
}
}
private void skipTo(String string,InputStream in)
throws IOException
private void skipTo(String string, InputStream in) throws IOException
{
int state = 0;
@ -288,16 +285,9 @@ public class WebSocketMessageRFC6455Test
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: aggregate\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: aggregate\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
socket.setSoTimeout(1000);
@ -342,7 +332,6 @@ public class WebSocketMessageRFC6455Test
lookFor("01234567890123456789",input);
}
@Test
public void testBlockedConsumer() throws Exception
{
@ -364,16 +353,9 @@ public class WebSocketMessageRFC6455Test
final int count = 100000;
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: latch\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: latch\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
// Make sure the read times out if there are problems with the implementation
@ -456,16 +438,9 @@ public class WebSocketMessageRFC6455Test
final int count = 100000;
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: latch\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: latch\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
// Make sure the read times out if there are problems with the implementation
@ -511,7 +486,6 @@ public class WebSocketMessageRFC6455Test
}
}.start();
// Send enough messages to fill receive buffer
long max = 0;
long start = System.currentTimeMillis();
@ -558,56 +532,23 @@ public class WebSocketMessageRFC6455Test
{ 4000, 2, 4000 },
{ 4000, 2 + 4, 4000 },
{ 9000, 2 + 23, 1002 },
{9000,2+23,1002}
};
{ 9000, 2 + 23, 1002 } };
String[] mesg =
{
"",
"",
"",
"mesg",
"",
"mesg",
"",
"mesg",
"",
"mesg",
"",
"mesg"
};
{ "", "", "", "mesg", "", "mesg", "", "mesg", "", "mesg", "", "mesg" };
String[] resp =
{
"",
"",
"",
"mesg",
"Invalid close code 1005",
"Invalid close code 1005",
"Invalid close code 1006",
"Invalid close code 1006",
"",
"mesg",
"Invalid close code 9000",
"Invalid close code 9000"
};
{ "", "", "", "mesg", "Invalid close code 1005", "Invalid close code 1005", "Invalid close code 1006", "Invalid close code 1006", "", "mesg",
"Invalid close code 9000", "Invalid close code 9000" };
for (int t = 0; t < tests.length; t++)
{
String tst = "" + t;
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: chat\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: chat\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
socket.setSoTimeout(100000);
@ -663,7 +604,6 @@ public class WebSocketMessageRFC6455Test
assertEquals(tst,tests[t][2],-1);
}
len = input.read(buf);
assertEquals(tst,-1,len);
}
@ -685,40 +625,19 @@ public class WebSocketMessageRFC6455Test
{ 1006, 0, -1 },
{ 1006, 0, -1 },
{ 9000, 2, 9000 },
{9000,2+4,9000}
};
{ 9000, 2 + 4, 9000 } };
String[] mesg =
{
null,
"Not Sent",
null,
"mesg",
null,
"mesg",
null,
"mesg",
null,
"mesg",
null,
"mesg"
};
{ null, "Not Sent", null, "mesg", null, "mesg", null, "mesg", null, "mesg", null, "mesg" };
for (int t = 0; t < tests.length; t++)
{
String tst = "" + t;
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: chat\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: chat\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
socket.setSoTimeout(100000);
@ -781,18 +700,10 @@ public class WebSocketMessageRFC6455Test
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: echo\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"Sec-WebSocket-Extensions: x-deflate-frame;minLength=64\r\n"+
"Sec-WebSocket-Extensions: fragment;minFragments=2\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: echo\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "Sec-WebSocket-Extensions: x-deflate-frame;minLength=64\r\n"
+ "Sec-WebSocket-Extensions: fragment;minFragments=2\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
// Make sure the read times out if there are problems with the implementation
@ -811,7 +722,6 @@ public class WebSocketMessageRFC6455Test
assertTrue(__serverWebSocket.awaitConnected(1000));
assertNotNull(__serverWebSocket.connection);
// Server sends a big message
String text = "0123456789ABCDEF ";
text = text + text + text + text;
@ -856,7 +766,6 @@ public class WebSocketMessageRFC6455Test
assertEquals(544,inflater.inflate(result));
assertEquals(TypeUtil.toHexString(data,0,544),TypeUtil.toHexString(result));
assertEquals((byte)0xC0,(byte)input.read());
assertEquals(0x21 + 3,input.read());
assertEquals(0x7e,input.read());
@ -871,7 +780,6 @@ public class WebSocketMessageRFC6455Test
assertEquals(545,inflater.inflate(result));
assertEquals(TypeUtil.toHexString(data,544,545),TypeUtil.toHexString(result));
}
@Test
@ -879,17 +787,10 @@ public class WebSocketMessageRFC6455Test
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"Sec-WebSocket-Extensions: fragment;maxLength=4;minFragments=7\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: onConnect\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "Sec-WebSocket-Extensions: fragment;maxLength=4;minFragments=7\r\n" + "\r\n")
.getBytes("ISO-8859-1"));
output.flush();
// Make sure the read times out if there are problems with the implementation
@ -939,18 +840,10 @@ public class WebSocketMessageRFC6455Test
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"Sec-WebSocket-Extensions: identity;param=0\r\n"+
"Sec-WebSocket-Extensions: identity;param=1, identity ; param = '2' ; other = ' some = value ' \r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: onConnect\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "Sec-WebSocket-Extensions: identity;param=0\r\n"
+ "Sec-WebSocket-Extensions: identity;param=1, identity ; param = '2' ; other = ' some = value ' \r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
// Make sure the read times out if there are problems with the implementation
@ -976,22 +869,14 @@ public class WebSocketMessageRFC6455Test
lookFor("sent on connect",input);
}
@Test
public void testIdle() throws Exception
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: onConnect\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
// Make sure the read times out if there are problems with the implementation
@ -1026,7 +911,6 @@ public class WebSocketMessageRFC6455Test
output.write(0xff);
output.flush();
assertTrue(__serverWebSocket.awaitDisconnected(5000));
try
{
@ -1044,16 +928,9 @@ public class WebSocketMessageRFC6455Test
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: other\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: other\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
socket.setSoTimeout(100000);
@ -1094,7 +971,6 @@ public class WebSocketMessageRFC6455Test
}
output.flush();
assertEquals(0x80 | OpCode.CLOSE.getCode(),input.read());
assertEquals(19,input.read());
int code = ((0xff & input.read()) * 0x100) + (0xff & input.read());
@ -1107,16 +983,9 @@ public class WebSocketMessageRFC6455Test
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: other\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: other\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
socket.setSoTimeout(100000);
@ -1152,23 +1021,14 @@ public class WebSocketMessageRFC6455Test
lookFor("Message size > 15",input);
}
@Test
public void testMaxTextSize() throws Exception
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: other\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: other\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
socket.setSoTimeout(1000);
@ -1216,23 +1076,14 @@ public class WebSocketMessageRFC6455Test
lookFor("Text message size > 15 chars",input);
}
@Test
public void testMaxTextSize2() throws Exception
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: other\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: other\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
socket.setSoTimeout(100000);
@ -1261,8 +1112,6 @@ public class WebSocketMessageRFC6455Test
}
output.flush();
assertEquals(0x80 | OpCode.CLOSE.getCode(),input.read());
assertEquals(30,input.read());
int code = ((0xff & input.read()) * 0x100) + (0xff & input.read());
@ -1270,22 +1119,14 @@ public class WebSocketMessageRFC6455Test
lookFor("Text message size > 15 chars",input);
}
@Test
public void testMaxTextSizeFalseFrag() throws Exception
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: other\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: other\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
socket.setSoTimeout(1000);
@ -1317,7 +1158,6 @@ public class WebSocketMessageRFC6455Test
}
output.flush();
assertEquals(0x80 | OpCode.CLOSE.getCode(),input.read());
assertEquals(33,input.read());
int code = ((0xff & input.read()) * 0x100) + (0xff & input.read());
@ -1330,16 +1170,9 @@ public class WebSocketMessageRFC6455Test
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: chat\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: chat\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
socket.setSoTimeout(100000);
@ -1377,16 +1210,9 @@ public class WebSocketMessageRFC6455Test
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: echo\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: echo\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
output.write(0x84);
output.write(0x8f);
@ -1418,24 +1244,15 @@ public class WebSocketMessageRFC6455Test
lookFor("this is an echo",input);
}
@Test
public void testServerPingPong() throws Exception
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
// Make sure the read times out if there are problems with the implementation
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: echo\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: echo\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
output.write(0x89);
output.write(0x80);
@ -1465,16 +1282,9 @@ public class WebSocketMessageRFC6455Test
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: chat, superchat\r\n"+
"Sec-WebSocket-Version: "+org.eclipse.jetty.websocket.api.WebSocket.VERSION+"\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n"
+ "Sec-WebSocket-Protocol: chat, superchat\r\n" + "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
// Make sure the read times out if there are problems with the implementation
@ -1510,22 +1320,14 @@ public class WebSocketMessageRFC6455Test
lookFor(data.substring(0x1ff6),input);
}
@Test
public void testServerSendOnConnect() throws Exception
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: onConnect\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
// Make sure the read times out if there are problems with the implementation
@ -1551,16 +1353,9 @@ public class WebSocketMessageRFC6455Test
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: onConnect\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
// Make sure the read times out if there are problems with the implementation
@ -1573,7 +1368,6 @@ public class WebSocketMessageRFC6455Test
lookFor("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",input);
skipTo("\r\n\r\n",input);
assertTrue(__serverWebSocket.awaitConnected(1000));
assertNotNull(__serverWebSocket.connection);
@ -1595,22 +1389,14 @@ public class WebSocketMessageRFC6455Test
}
}
@Test
public void testTCPHalfClose() throws Exception
{
Socket socket = new Socket("localhost",__connector.getLocalPort());
OutputStream output = socket.getOutputStream();
output.write(
("GET /chat HTTP/1.1\r\n"+
"Host: server.example.com\r\n"+
"Upgrade: websocket\r\n"+
"Connection: Upgrade\r\n"+
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n"+
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: onConnect\r\n" +
"Sec-WebSocket-Version: " + WSVERSION + "\r\n" +
"\r\n").getBytes("ISO-8859-1"));
output.write(("GET /chat HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Origin: http://example.com\r\n" + "Sec-WebSocket-Protocol: onConnect\r\n"
+ "Sec-WebSocket-Version: " + WSVERSION + "\r\n" + "\r\n").getBytes("ISO-8859-1"));
output.flush();
// Make sure the read times out if there are problems with the implementation
@ -1623,7 +1409,6 @@ public class WebSocketMessageRFC6455Test
lookFor("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",input);
skipTo("\r\n\r\n",input);
assertTrue(__serverWebSocket.awaitConnected(1000));
assertNotNull(__serverWebSocket.connection);