Revert "Support 1012, 1013 and 1014 WebSocket status code"

This reverts commit db6d94f82a.
This commit is contained in:
Norman Maurer 2018-12-14 18:24:30 +01:00
parent db6d94f82a
commit 29d185b796
2 changed files with 1 additions and 56 deletions

View File

@ -451,7 +451,7 @@ public class WebSocket08FrameDecoder extends ByteToMessageDecoder
// Must have 2 byte integer within the valid range
int statusCode = buffer.readShort();
if (statusCode >= 0 && statusCode <= 999 || statusCode >= 1004 && statusCode <= 1006
|| statusCode >= 1015 && statusCode <= 2999) {
|| statusCode >= 1012 && statusCode <= 2999) {
protocolViolation(ctx, "Invalid close frame getStatus code: " + statusCode);
}

View File

@ -12,20 +12,11 @@
*/
package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.junit.Test;
import static org.junit.Assert.*;
import org.mockito.Mockito;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class WebSocket08FrameDecoderTest {
@Test
@ -35,50 +26,4 @@ public class WebSocket08FrameDecoderTest {
decoder.channelInactive(ctx);
Mockito.verify(ctx).fireChannelInactive();
}
@Test
public void supportIanaStatusCodes() throws Exception {
Set<Integer> forbiddenIanaCodes = new HashSet<Integer>();
forbiddenIanaCodes.add(1004);
forbiddenIanaCodes.add(1005);
forbiddenIanaCodes.add(1006);
Set<Integer> validIanaCodes = new HashSet<Integer>();
for (int i = 1000; i < 1015; i++) {
validIanaCodes.add(i);
}
validIanaCodes.removeAll(forbiddenIanaCodes);
ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);
Mockito.when(ctx.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
Channel channel = Mockito.mock(Channel.class);
Mockito.when(channel.isActive()).thenReturn(false);
Mockito.when(ctx.channel()).thenReturn(channel);
List<Object> out = new ArrayList<Object>();
for (int statusCode: validIanaCodes) {
WebSocket08FrameEncoder encoder = new WebSocket08FrameEncoder(true);
WebSocket08FrameDecoder decoder = new WebSocket08FrameDecoder(true, true, 65535, false);
CloseWebSocketFrame inputFrame = new CloseWebSocketFrame(statusCode, "Bye");
try {
encoder.encode(ctx, inputFrame, out);
ByteBuf serializedCloseFrame = (ByteBuf) out.get(0);
out.clear();
decoder.decode(ctx, serializedCloseFrame, out);
CloseWebSocketFrame outputFrame = (CloseWebSocketFrame) out.get(0);
out.clear();
try {
assertEquals(statusCode, outputFrame.statusCode());
} finally {
outputFrame.release();
}
} finally {
inputFrame.release();
}
}
}
}