fix protocol exception regarding control frames and FIN=false
This commit is contained in:
parent
c24b7d83e6
commit
27b05ccd6e
|
@ -4,7 +4,6 @@ import java.nio.ByteBuffer;
|
|||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.PolicyViolationException;
|
||||
import org.eclipse.jetty.websocket.api.ProtocolException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.protocol.CloseInfo;
|
||||
|
@ -57,6 +56,11 @@ public class FrameGenerator
|
|||
|
||||
byte b;
|
||||
|
||||
if ( frame.getOpCode().isControlFrame() && !frame.isFin() )
|
||||
{
|
||||
throw new ProtocolException("Control Frames must be FIN=true");
|
||||
}
|
||||
|
||||
// Setup fin thru opcode
|
||||
b = 0x00;
|
||||
if (frame.isFin())
|
||||
|
@ -67,19 +71,19 @@ public class FrameGenerator
|
|||
{
|
||||
b |= 0x40; // 0100_0000
|
||||
// TODO: extensions can negotiate this (somehow)
|
||||
throw new PolicyViolationException("RSV1 not allowed to be set");
|
||||
throw new ProtocolException("RSV1 not allowed to be set");
|
||||
}
|
||||
if (frame.isRsv2())
|
||||
{
|
||||
b |= 0x20; // 0010_0000
|
||||
// TODO: extensions can negotiate this (somehow)
|
||||
throw new PolicyViolationException("RSV2 not allowed to be set");
|
||||
throw new ProtocolException("RSV2 not allowed to be set");
|
||||
}
|
||||
if (frame.isRsv3())
|
||||
{
|
||||
b |= 0x10;
|
||||
// TODO: extensions can negotiate this (somehow)
|
||||
throw new PolicyViolationException("RSV3 not allowed to be set");
|
||||
throw new ProtocolException("RSV3 not allowed to be set");
|
||||
}
|
||||
|
||||
byte opcode = frame.getOpCode().getCode();
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.PolicyViolationException;
|
||||
import org.eclipse.jetty.websocket.api.ProtocolException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.generator.Generator;
|
||||
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
|
||||
|
@ -24,6 +24,8 @@ public class TestABCase3
|
|||
{
|
||||
List<WebSocketFrame[]> data = new ArrayList<>();
|
||||
// @formatter:off
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.ping().fin(false).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.ping().rsv1(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
|
@ -31,11 +33,15 @@ public class TestABCase3
|
|||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.ping().rsv3(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.pong().rsv1(true).asFrame() });
|
||||
{ FrameBuilder.pong().fin(false).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.ping().rsv1(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.pong().rsv2(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.pong().rsv3(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.close().fin(false).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.close().rsv1(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
|
@ -53,8 +59,8 @@ public class TestABCase3
|
|||
this.invalidFrame = invalidFrame;
|
||||
}
|
||||
|
||||
@Test(expected = PolicyViolationException.class)
|
||||
public void testGenerateRSV1CloseFrame()
|
||||
@Test(expected = ProtocolException.class)
|
||||
public void testGenerateInvalidControlFrame()
|
||||
{
|
||||
Generator generator = new Generator(WebSocketPolicy.newServerPolicy());
|
||||
|
||||
|
|
Loading…
Reference in New Issue