From 43d048f691bbbb617c670cd243576981ca81fd24 Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Wed, 27 Jun 2012 10:14:51 -0500 Subject: [PATCH] control frames can not set rsv bits + tests --- .../jetty/websocket/frames/ControlFrame.java | 27 +++++++ .../eclipse/jetty/websocket/ab/ABCase3.java | 81 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/ABCase3.java diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java index caac309374b..e3c03ccf5b6 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/frames/ControlFrame.java @@ -25,6 +25,33 @@ public abstract class ControlFrame extends BaseFrame return false; // no control frames can be continuation } + @Override + public void setRsv1(boolean rsv1) + { + if (rsv1) + { + throw new IllegalArgumentException("Cannot set RSV1 to true on a " + getOpCode().name()); + } + } + + @Override + public void setRsv2(boolean rsv2) + { + if (rsv2) + { + throw new IllegalArgumentException("Cannot set RSV2 to true on a " + getOpCode().name()); + } + } + + @Override + public void setRsv3(boolean rsv3) + { + if (rsv3) + { + throw new IllegalArgumentException("Cannot set RSV3 to true on a " + getOpCode().name()); + } + } + @Override public void setPayload(ByteBuffer payload) { diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/ABCase3.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/ABCase3.java new file mode 100644 index 00000000000..5ecd7f8c9d5 --- /dev/null +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/ABCase3.java @@ -0,0 +1,81 @@ +package org.eclipse.jetty.websocket.ab; + +import org.eclipse.jetty.websocket.frames.CloseFrame; +import org.eclipse.jetty.websocket.frames.PingFrame; +import org.eclipse.jetty.websocket.frames.PongFrame; +import org.junit.Test; + +public class ABCase3 +{ + @Test( expected=IllegalArgumentException.class ) + public void testGenerateRSV1PingFrame() + { + PingFrame pingFrame = new PingFrame(); + + pingFrame.setRsv1(true); + } + + @Test( expected=IllegalArgumentException.class ) + public void testGenerateRSV2PingFrame() + { + PingFrame pingFrame = new PingFrame(); + + pingFrame.setRsv2(true); + } + + @Test( expected=IllegalArgumentException.class ) + public void testGenerateRSV3PingFrame() + { + PingFrame pingFrame = new PingFrame(); + + pingFrame.setRsv3(true); + } + + @Test( expected=IllegalArgumentException.class ) + public void testGenerateRSV1PongFrame() + { + PongFrame pongFrame = new PongFrame(); + + pongFrame.setRsv1(true); + } + + @Test( expected=IllegalArgumentException.class ) + public void testGenerateRSV2PongFrame() + { + PongFrame pongFrame = new PongFrame(); + + pongFrame.setRsv2(true); + } + + @Test( expected=IllegalArgumentException.class ) + public void testGenerateRSV3PongFrame() + { + PongFrame pongFrame = new PongFrame(); + + pongFrame.setRsv3(true); + } + + @Test( expected=IllegalArgumentException.class ) + public void testGenerateRSV1CloseFrame() + { + CloseFrame closeFrame = new CloseFrame(); + + closeFrame.setRsv1(true); + } + + @Test( expected=IllegalArgumentException.class ) + public void testGenerateRSV2CloseFrame() + { + CloseFrame closeFrame = new CloseFrame(); + + closeFrame.setRsv2(true); + } + + @Test( expected=IllegalArgumentException.class ) + public void testGenerateRSV3CloseFrame() + { + CloseFrame closeFrame = new CloseFrame(); + + closeFrame.setRsv3(true); + } +}