396428 - Test for WebSocket masking on client fragments per RFC 6455 Sec 5.1
This commit is contained in:
parent
25b0bd73a6
commit
b2951bdf5d
|
@ -131,6 +131,7 @@ public class IncomingFramesCapture implements IncomingFrames
|
|||
public void incomingFrame(Frame frame)
|
||||
{
|
||||
WebSocketFrame copy = new WebSocketFrame(frame);
|
||||
Assert.assertThat("frame.masking must be set",frame.isMasked(),is(true));
|
||||
frames.add(copy);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.jetty.util.log.Log;
|
|||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.MessageTooLargeException;
|
||||
import org.eclipse.jetty.websocket.api.ProtocolException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.api.extensions.Extension;
|
||||
|
@ -179,6 +180,17 @@ public class Parser
|
|||
{
|
||||
LOG.debug("{} Notify {}",policy.getBehavior(),incomingFramesHandler);
|
||||
}
|
||||
|
||||
if (policy.getBehavior() == WebSocketBehavior.SERVER)
|
||||
{
|
||||
// Parsing on server?
|
||||
// Then you MUST make sure all incoming frames are masked!
|
||||
if (f.isMasked() == false)
|
||||
{
|
||||
throw new ProtocolException("Client frames MUST be masked (RFC-6455)");
|
||||
}
|
||||
}
|
||||
|
||||
if (incomingFramesHandler == null)
|
||||
{
|
||||
return;
|
||||
|
|
|
@ -35,7 +35,7 @@ public class GeneratorParserRoundtripTest
|
|||
@Test
|
||||
public void testParserAndGenerator() throws Exception
|
||||
{
|
||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
|
||||
ByteBufferPool bufferPool = new MappedByteBufferPool();
|
||||
Generator gen = new Generator(policy,bufferPool);
|
||||
Parser parser = new Parser(policy,bufferPool);
|
||||
|
@ -71,7 +71,7 @@ public class GeneratorParserRoundtripTest
|
|||
@Test
|
||||
public void testParserAndGeneratorMasked() throws Exception
|
||||
{
|
||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
|
||||
ByteBufferPool bufferPool = new MappedByteBufferPool();
|
||||
Generator gen = new Generator(policy,bufferPool);
|
||||
Parser parser = new Parser(policy,bufferPool);
|
||||
|
|
|
@ -39,7 +39,7 @@ public class PingPayloadParserTest
|
|||
{ (byte)0x89, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f });
|
||||
BufferUtil.flipToFlush(buf,0);
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
Parser parser = new UnitParser(policy);
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
|
|
|
@ -37,7 +37,7 @@ public class RFC6455ExamplesParserTest
|
|||
@Test
|
||||
public void testFragmentedUnmaskedTextMessage()
|
||||
{
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
Parser parser = new UnitParser(policy);
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
|
@ -135,7 +135,7 @@ public class RFC6455ExamplesParserTest
|
|||
}
|
||||
buf.flip();
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
Parser parser = new UnitParser(policy);
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
|
@ -174,7 +174,7 @@ public class RFC6455ExamplesParserTest
|
|||
}
|
||||
buf.flip();
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
Parser parser = new UnitParser(policy);
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
|
@ -205,7 +205,7 @@ public class RFC6455ExamplesParserTest
|
|||
{ (byte)0x89, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f });
|
||||
buf.flip();
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
Parser parser = new UnitParser(policy);
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
|
@ -228,7 +228,7 @@ public class RFC6455ExamplesParserTest
|
|||
{ (byte)0x81, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f });
|
||||
buf.flip();
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
Parser parser = new UnitParser(policy);
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.junit.Test;
|
|||
*/
|
||||
public class TestABCase1_1
|
||||
{
|
||||
private WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
private WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
|
||||
|
||||
@Test
|
||||
public void testGenerate125ByteTextCase1_1_2()
|
||||
|
@ -450,7 +450,7 @@ public class TestABCase1_1
|
|||
}
|
||||
|
||||
expected.flip();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
policy.setMaxMessageSize(length);
|
||||
Parser parser = new UnitParser(policy);
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
|
@ -487,7 +487,7 @@ public class TestABCase1_1
|
|||
|
||||
expected.flip();
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
policy.setMaxMessageSize(length);
|
||||
Parser parser = new UnitParser(policy);
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
|
|
|
@ -42,7 +42,7 @@ import org.junit.Test;
|
|||
*/
|
||||
public class TestABCase1_2
|
||||
{
|
||||
private WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
private WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
|
||||
|
||||
@Test
|
||||
public void testGenerate125ByteBinaryCase1_2_2()
|
||||
|
@ -465,7 +465,7 @@ public class TestABCase1_2
|
|||
}
|
||||
|
||||
expected.flip();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
policy.setMaxMessageSize(length);
|
||||
Parser parser = new UnitParser(policy);
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
|
@ -502,7 +502,7 @@ public class TestABCase1_2
|
|||
|
||||
expected.flip();
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
policy.setMaxMessageSize(length);
|
||||
Parser parser = new UnitParser(policy);
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.junit.Test;
|
|||
|
||||
public class TestABCase2
|
||||
{
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
|
||||
@Test
|
||||
public void testGenerate125OctetPingCase2_4()
|
||||
|
|
|
@ -46,7 +46,7 @@ public class TestABCase4
|
|||
LogShush.enableStacks(Parser.class);
|
||||
}
|
||||
|
||||
private WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
private WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
|
||||
@Test
|
||||
public void testParserControlOpCode11Case4_2_1()
|
||||
|
|
|
@ -43,7 +43,7 @@ import org.junit.Test;
|
|||
|
||||
public class TestABCase7_3
|
||||
{
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
|
||||
|
||||
@Test
|
||||
public void testCase7_3_1GenerateEmptyClose()
|
||||
|
|
|
@ -53,7 +53,7 @@ public class FragmentExtensionTest
|
|||
|
||||
FragmentExtension ext = new FragmentExtension();
|
||||
ext.setBufferPool(new MappedByteBufferPool());
|
||||
ext.setPolicy(WebSocketPolicy.newServerPolicy());
|
||||
ext.setPolicy(WebSocketPolicy.newClientPolicy());
|
||||
ExtensionConfig config = ExtensionConfig.parse("fragment;maxLength=4");
|
||||
ext.setConfig(config);
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public class FrameCompressionExtensionTest
|
|||
{
|
||||
private void assertIncoming(byte[] raw, String... expectedTextDatas)
|
||||
{
|
||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
|
||||
|
||||
FrameCompressionExtension ext = new FrameCompressionExtension();
|
||||
ext.setBufferPool(new MappedByteBufferPool());
|
||||
|
@ -92,7 +92,7 @@ public class FrameCompressionExtensionTest
|
|||
|
||||
private void assertOutgoing(String text, String expectedHex) throws IOException
|
||||
{
|
||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
|
||||
|
||||
FrameCompressionExtension ext = new FrameCompressionExtension();
|
||||
ext.setBufferPool(new MappedByteBufferPool());
|
||||
|
@ -211,7 +211,7 @@ public class FrameCompressionExtensionTest
|
|||
@Test
|
||||
public void testGeneratedTwoFrames() throws IOException
|
||||
{
|
||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
|
||||
|
||||
FrameCompressionExtension ext = new FrameCompressionExtension();
|
||||
ext.setBufferPool(new MappedByteBufferPool());
|
||||
|
|
|
@ -56,7 +56,7 @@ public class MuxParserRFCTest
|
|||
private LinkedList<WebSocketFrame> asFrames(byte[] buf)
|
||||
{
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
WebSocketPolicy policy = WebSocketPolicy.newClientPolicy();
|
||||
Parser parser = new UnitParser(policy);
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
List<? extends AbstractExtension> muxList = Collections.singletonList(new DummyMuxExtension());
|
||||
|
|
Loading…
Reference in New Issue