Removing test for inputClosed on BlockheadClient to fix test failure.
This commit is contained in:
parent
60598c5c73
commit
c8c15a4063
|
@ -564,7 +564,7 @@ public class WebSocketFrame implements Frame
|
|||
{
|
||||
if (buf.remaining() > WebSocketFrame.MAX_CONTROL_PAYLOAD)
|
||||
{
|
||||
throw new ProtocolException("Control Payloads can not exceed 125 bytes in length.");
|
||||
throw new ProtocolException("Control Payloads can not exceed 125 bytes in length. (was " + buf.remaining() + " bytes)");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,13 @@ import org.junit.Assert;
|
|||
*/
|
||||
public class Fuzzer
|
||||
{
|
||||
public static enum CloseState
|
||||
{
|
||||
OPEN,
|
||||
REMOTE_INITIATED,
|
||||
LOCAL_INITIATED
|
||||
}
|
||||
|
||||
public static enum SendMode
|
||||
{
|
||||
BULK,
|
||||
|
@ -56,13 +63,6 @@ public class Fuzzer
|
|||
SLOW
|
||||
}
|
||||
|
||||
public static enum CloseState
|
||||
{
|
||||
OPEN,
|
||||
REMOTE_INITIATED,
|
||||
LOCAL_INITIATED
|
||||
}
|
||||
|
||||
private static final int KBYTE = 1024;
|
||||
private static final int MBYTE = KBYTE * KBYTE;
|
||||
|
||||
|
@ -126,6 +126,7 @@ public class Fuzzer
|
|||
if (!client.isConnected())
|
||||
{
|
||||
client.connect();
|
||||
client.addHeader("X-TestCase: " + testname + "\r\n");
|
||||
client.sendStandardRequest();
|
||||
client.expectUpgradeResponse();
|
||||
}
|
||||
|
@ -189,17 +190,17 @@ public class Fuzzer
|
|||
// we expect that the close handshake to have occurred and the server should have closed the connection
|
||||
try
|
||||
{
|
||||
int val = client.read();
|
||||
|
||||
int val = client.read();
|
||||
|
||||
Assert.fail("Server has not closed socket");
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
IOState ios = client.getIOState();
|
||||
|
||||
|
||||
if (wasClean)
|
||||
{
|
||||
Assert.assertTrue(ios.wasRemoteCloseInitiated());
|
||||
|
@ -209,7 +210,25 @@ public class Fuzzer
|
|||
{
|
||||
Assert.assertTrue(ios.wasRemoteCloseInitiated());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public CloseState getCloseState()
|
||||
{
|
||||
IOState ios = client.getIOState();
|
||||
|
||||
if (ios.wasLocalCloseInitiated())
|
||||
{
|
||||
return CloseState.LOCAL_INITIATED;
|
||||
}
|
||||
else if (ios.wasRemoteCloseInitiated())
|
||||
{
|
||||
return CloseState.REMOTE_INITIATED;
|
||||
}
|
||||
else
|
||||
{
|
||||
return CloseState.OPEN;
|
||||
}
|
||||
}
|
||||
|
||||
public SendMode getSendMode()
|
||||
|
@ -358,22 +377,4 @@ public class Fuzzer
|
|||
{
|
||||
this.slowSendSegmentSize = segmentSize;
|
||||
}
|
||||
|
||||
public CloseState getCloseState()
|
||||
{
|
||||
IOState ios = client.getIOState();
|
||||
|
||||
if ( ios.wasLocalCloseInitiated() )
|
||||
{
|
||||
return CloseState.LOCAL_INITIATED;
|
||||
}
|
||||
else if ( ios.wasRemoteCloseInitiated() )
|
||||
{
|
||||
return CloseState.REMOTE_INITIATED;
|
||||
}
|
||||
else
|
||||
{
|
||||
return CloseState.OPEN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -233,12 +233,12 @@ public class TestABCase2 extends AbstractABCase
|
|||
public void testCase2_5() throws Exception
|
||||
{
|
||||
byte payload[] = new byte[126]; // intentionally too big
|
||||
Arrays.fill(payload,(byte)0xFE);
|
||||
Arrays.fill(payload,(byte)'5');
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
// trick websocket frame into making extra large payload for ping
|
||||
send.add(WebSocketFrame.binary(payload).setOpCode(OpCode.PING));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
send.add(new CloseInfo(StatusCode.NORMAL,"Test 2.5").asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(new CloseInfo(StatusCode.PROTOCOL).asFrame());
|
||||
|
@ -263,16 +263,17 @@ public class TestABCase2 extends AbstractABCase
|
|||
@Test
|
||||
public void testCase2_6() throws Exception
|
||||
{
|
||||
System.err.println("==================================================================================================");
|
||||
byte payload[] = new byte[125];
|
||||
Arrays.fill(payload,(byte)0xFE);
|
||||
Arrays.fill(payload,(byte)'6');
|
||||
|
||||
List<WebSocketFrame> send = new ArrayList<>();
|
||||
send.add(WebSocketFrame.ping().setPayload(payload));
|
||||
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
send.add(new CloseInfo(StatusCode.NORMAL,"Test 2.6").asFrame());
|
||||
|
||||
List<WebSocketFrame> expect = new ArrayList<>();
|
||||
expect.add(WebSocketFrame.pong().setPayload(payload));
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL).asFrame());
|
||||
expect.add(new CloseInfo(StatusCode.NORMAL,"Test 2.6").asFrame());
|
||||
|
||||
Fuzzer fuzzer = new Fuzzer(this);
|
||||
try
|
||||
|
|
|
@ -107,6 +107,7 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
|
|||
private int version = 13; // default to RFC-6455
|
||||
private String protocols;
|
||||
private List<String> extensions = new ArrayList<>();
|
||||
private List<String> headers = new ArrayList<>();
|
||||
private byte[] clientmask = new byte[]
|
||||
{ (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF };
|
||||
private int timeout = 1000;
|
||||
|
@ -116,7 +117,7 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
|
|||
private ExtensionStack extensionStack;
|
||||
private IOState ioState;
|
||||
private CountDownLatch disconnectedLatch = new CountDownLatch(1);
|
||||
|
||||
|
||||
public BlockheadClient(URI destWebsocketURI) throws URISyntaxException
|
||||
{
|
||||
this(WebSocketPolicy.newClientPolicy(),destWebsocketURI);
|
||||
|
@ -149,6 +150,11 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
|
|||
this.extensions.add(xtension);
|
||||
}
|
||||
|
||||
public void addHeader(String header)
|
||||
{
|
||||
this.headers.add(header);
|
||||
}
|
||||
|
||||
public boolean awaitDisconnect(long timeout, TimeUnit unit) throws InterruptedException
|
||||
{
|
||||
return disconnectedLatch.await(timeout,unit);
|
||||
|
@ -173,7 +179,7 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
|
|||
public void close(int statusCode, String message)
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
CloseInfo close = new CloseInfo(statusCode,message);
|
||||
|
||||
if (ioState.onCloseHandshake(false,close))
|
||||
|
@ -440,11 +446,6 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
|
|||
{
|
||||
throw new EOFException("Hit EOF");
|
||||
}
|
||||
if (ioState.isInputClosed())
|
||||
{
|
||||
LOG.debug("Input is closed");
|
||||
return 0;
|
||||
}
|
||||
int len = 0;
|
||||
int b;
|
||||
while ((in.available() > 0) && (buf.remaining() > 0))
|
||||
|
@ -552,6 +553,10 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames
|
|||
req.append("\r\n");
|
||||
req.append("Upgrade: websocket\r\n");
|
||||
req.append("Connection: Upgrade\r\n");
|
||||
for (String header : headers)
|
||||
{
|
||||
req.append(header);
|
||||
}
|
||||
req.append("Sec-WebSocket-Key: ").append(REQUEST_HASH_KEY).append("\r\n");
|
||||
req.append("Sec-WebSocket-Origin: ").append(destWebsocketURI.toASCIIString()).append("\r\n");
|
||||
if (StringUtil.isNotBlank(protocols))
|
||||
|
|
Loading…
Reference in New Issue