From edeb6feadbe0db3af675236fe5d563ab786ba78d Mon Sep 17 00:00:00 2001 From: marci4 Date: Thu, 28 May 2020 20:40:16 +0200 Subject: [PATCH 1/2] Make Protocols less strict --- src/main/example/ChatServer.java | 8 + .../SecWebSocketProtocolServerExample.java | 54 +++++ .../java/org/java_websocket/WebSocket.java | 9 + .../org/java_websocket/WebSocketImpl.java | 10 + .../client/WebSocketClient.java | 4 + .../java_websocket/protocols/Protocol.java | 3 + .../ProtoclHandshakeRejectionTest.java | 184 ++++++++++++++++-- .../protocols/ProtocolTest.java | 8 +- 8 files changed, 262 insertions(+), 18 deletions(-) create mode 100644 src/main/example/SecWebSocketProtocolServerExample.java diff --git a/src/main/example/ChatServer.java b/src/main/example/ChatServer.java index d1202911..7439add7 100644 --- a/src/main/example/ChatServer.java +++ b/src/main/example/ChatServer.java @@ -29,11 +29,15 @@ import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; +import java.util.Collections; import org.java_websocket.WebSocket; import org.java_websocket.WebSocketImpl; +import org.java_websocket.drafts.Draft; +import org.java_websocket.drafts.Draft_6455; import org.java_websocket.framing.Framedata; import org.java_websocket.handshake.ClientHandshake; +import org.java_websocket.protocols.IProtocol; import org.java_websocket.server.WebSocketServer; /** @@ -49,6 +53,10 @@ public ChatServer( InetSocketAddress address ) { super( address ); } + public ChatServer(int port, Draft_6455 draft) { + super( new InetSocketAddress( port ), Collections.singletonList(draft)); + } + @Override public void onOpen( WebSocket conn, ClientHandshake handshake ) { conn.send("Welcome to the server!"); //This method sends a message to the new client diff --git a/src/main/example/SecWebSocketProtocolServerExample.java b/src/main/example/SecWebSocketProtocolServerExample.java new file mode 100644 index 00000000..91196124 --- /dev/null +++ b/src/main/example/SecWebSocketProtocolServerExample.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2010-2020 Nathan Rajlich + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +import org.java_websocket.drafts.Draft_6455; +import org.java_websocket.extensions.IExtension; +import org.java_websocket.protocols.IProtocol; +import org.java_websocket.protocols.Protocol; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Collections; + +/** + * This example demonstrates how to use a specific Sec-WebSocket-Protocol for your connection. + */ +public class SecWebSocketProtocolServerExample { + + public static void main( String[] args ) throws URISyntaxException { + // This draft only allows you to use the specific Sec-WebSocket-Protocol without a fallback. + Draft_6455 draft_ocppOnly = new Draft_6455(Collections.emptyList(), Collections.singletonList(new Protocol("ocpp2.0"))); + + // This draft allows the specific Sec-WebSocket-Protocol and also provides a fallback, if the other endpoint does not accept the specific Sec-WebSocket-Protocol + ArrayList protocols = new ArrayList(); + protocols.add(new Protocol("ocpp2.0")); + protocols.add(new Protocol("")); + Draft_6455 draft_ocppAndFallBack = new Draft_6455(Collections.emptyList(), protocols); + + ChatServer chatServer = new ChatServer(8887, draft_ocppOnly); + chatServer.start(); + } +} diff --git a/src/main/java/org/java_websocket/WebSocket.java b/src/main/java/org/java_websocket/WebSocket.java index c4d0441c..5bc6c74f 100644 --- a/src/main/java/org/java_websocket/WebSocket.java +++ b/src/main/java/org/java_websocket/WebSocket.java @@ -34,6 +34,7 @@ import org.java_websocket.enums.ReadyState; import org.java_websocket.exceptions.WebsocketNotConnectedException; import org.java_websocket.framing.Framedata; +import org.java_websocket.protocols.IProtocol; import javax.net.ssl.SSLSession; @@ -224,4 +225,12 @@ public interface WebSocket { * @since 1.4.1 */ SSLSession getSSLSession() throws IllegalArgumentException; + + /** + * Returns the used Sec-WebSocket-Protocol for this websocket connection + * @return the Sec-WebSocket-Protocol or null, if no draft available + * @throws IllegalArgumentException the underlying draft does not support a Sec-WebSocket-Protocol + * @since 1.5.2 + */ + IProtocol getProtocol(); } \ No newline at end of file diff --git a/src/main/java/org/java_websocket/WebSocketImpl.java b/src/main/java/org/java_websocket/WebSocketImpl.java index 3459438e..fe073df8 100644 --- a/src/main/java/org/java_websocket/WebSocketImpl.java +++ b/src/main/java/org/java_websocket/WebSocketImpl.java @@ -34,6 +34,7 @@ import org.java_websocket.framing.Framedata; import org.java_websocket.framing.PingFrame; import org.java_websocket.handshake.*; +import org.java_websocket.protocols.IProtocol; import org.java_websocket.server.WebSocketServer.WebSocketWorker; import org.java_websocket.util.Charsetfunctions; @@ -832,6 +833,15 @@ public SSLSession getSSLSession() { return ((ISSLChannel) channel).getSSLEngine().getSession(); } + @Override + public IProtocol getProtocol() { + if (draft == null) + return null; + if (!(draft instanceof Draft_6455)) + throw new IllegalArgumentException("This draft does not support Sec-WebSocket-Protocol"); + return ((Draft_6455) draft).getProtocol(); + } + @Override public void setAttachment(T attachment) { this.attachment = attachment; diff --git a/src/main/java/org/java_websocket/client/WebSocketClient.java b/src/main/java/org/java_websocket/client/WebSocketClient.java index 4d735dee..58e37885 100644 --- a/src/main/java/org/java_websocket/client/WebSocketClient.java +++ b/src/main/java/org/java_websocket/client/WebSocketClient.java @@ -59,6 +59,7 @@ import org.java_websocket.handshake.HandshakeImpl1Client; import org.java_websocket.handshake.Handshakedata; import org.java_websocket.handshake.ServerHandshake; +import org.java_websocket.protocols.IProtocol; /** * A subclass must implement at least onOpen, onClose, and onMessage to be @@ -913,6 +914,9 @@ public SSLSession getSSLSession() { return engine.getSSLSession(); } + @Override + public IProtocol getProtocol() { return engine.getProtocol();} + /** * Method to give some additional info for specific IOExceptions * @param e the IOException causing a eot. diff --git a/src/main/java/org/java_websocket/protocols/Protocol.java b/src/main/java/org/java_websocket/protocols/Protocol.java index 4c3ba70f..9c63115a 100644 --- a/src/main/java/org/java_websocket/protocols/Protocol.java +++ b/src/main/java/org/java_websocket/protocols/Protocol.java @@ -56,6 +56,9 @@ public Protocol( String providedProtocol ) { @Override public boolean acceptProvidedProtocol( String inputProtocolHeader ) { + if ("".equals(providedProtocol)) { + return true; + } String protocolHeader = patternSpace.matcher(inputProtocolHeader).replaceAll(""); String[] headers = patternComma.split(protocolHeader); for( String header : headers ) { diff --git a/src/test/java/org/java_websocket/protocols/ProtoclHandshakeRejectionTest.java b/src/test/java/org/java_websocket/protocols/ProtoclHandshakeRejectionTest.java index 6ee3d89b..6c0b8072 100644 --- a/src/test/java/org/java_websocket/protocols/ProtoclHandshakeRejectionTest.java +++ b/src/test/java/org/java_websocket/protocols/ProtoclHandshakeRejectionTest.java @@ -48,17 +48,14 @@ import java.util.Collections; import java.util.Scanner; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; public class ProtoclHandshakeRejectionTest { private static final String additionalHandshake = "HTTP/1.1 101 Websocket Connection Upgrade\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n"; - private static int counter = 0; private static Thread thread; private static ServerSocket serverSocket; - private static boolean debugPrintouts = false; - private static int port; @BeforeClass @@ -70,7 +67,6 @@ public void run() { try { serverSocket = new ServerSocket( port ); serverSocket.setReuseAddress( true ); - int count = 1; while( true ) { Socket client = null; try { @@ -94,7 +90,6 @@ public void run() { } } OutputStream os = client.getOutputStream(); - count++; if( "/0".equals( testCase ) ) { os.write( Charsetfunctions.asciiBytes( additionalHandshake + getSecKey( seckey ) + "\r\n" ) ); os.flush(); @@ -175,6 +170,47 @@ public void run() { os.write( Charsetfunctions.asciiBytes( additionalHandshake + "\r\n" ) ); os.flush(); } + // Order check + if( "/20".equals( testCase ) ) { + os.write( Charsetfunctions.asciiBytes( additionalHandshake + getSecKey( seckey ) + "Sec-WebSocket-Protocol: chat1,chat2,chat3" + "\r\n\r\n" ) ); + os.flush(); + } + if( "/21".equals( testCase ) ) { + os.write( Charsetfunctions.asciiBytes( additionalHandshake +getSecKey( seckey ) + "Sec-WebSocket-Protocol: chat1,chat2,chat3" + "\r\n\r\n" ) ); + os.flush(); + } + if( "/22".equals( testCase ) ) { + os.write( Charsetfunctions.asciiBytes( additionalHandshake + getSecKey( seckey ) + "Sec-WebSocket-Protocol: chat1,chat2,chat3" + "\r\n\r\n" ) ); + os.flush(); + } + if( "/23".equals( testCase ) ) { + os.write( Charsetfunctions.asciiBytes( additionalHandshake + getSecKey( seckey ) + "Sec-WebSocket-Protocol: chat1,chat2,chat3" + "\r\n\r\n" ) ); + os.flush(); + } + if( "/24".equals( testCase ) ) { + os.write( Charsetfunctions.asciiBytes( additionalHandshake + getSecKey( seckey ) + "Sec-WebSocket-Protocol: chat1,chat2,chat3" + "\r\n\r\n" ) ); + os.flush(); + } + if( "/25".equals( testCase ) ) { + os.write( Charsetfunctions.asciiBytes( additionalHandshake + getSecKey( seckey ) + "Sec-WebSocket-Protocol: abc" + "\r\n\r\n" ) ); + os.flush(); + } + if( "/26".equals( testCase ) ) { + os.write( Charsetfunctions.asciiBytes( additionalHandshake + getSecKey( seckey ) + "\r\n\r\n" ) ); + os.flush(); + } + if( "/27".equals( testCase ) ) { + os.write( Charsetfunctions.asciiBytes( additionalHandshake + getSecKey( seckey ) + "Sec-WebSocket-Protocol: chat1,chat2,chat3" + "\r\n\r\n" ) ); + os.flush(); + } + if( "/28".equals( testCase ) ) { + os.write( Charsetfunctions.asciiBytes( additionalHandshake + getSecKey( seckey ) + "Sec-WebSocket-Protocol: abc" + "\r\n\r\n" ) ); + os.flush(); + } + if( "/29".equals( testCase ) ) { + os.write( Charsetfunctions.asciiBytes( additionalHandshake + getSecKey( seckey ) + "\r\n\r\n" ) ); + os.flush(); + } } catch ( IOException e ) { // } @@ -193,16 +229,14 @@ private static String getSecKey( String seckey ) { } @AfterClass - public static void successTests() throws InterruptedException, IOException { + public static void successTests() throws IOException { serverSocket.close(); thread.interrupt(); - if( debugPrintouts ) - System.out.println( counter + " successful tests" ); } @Test(timeout = 5000) public void testProtocolRejectionTestCase0() throws Exception { - testProtocolRejection( 0, new Draft_6455() ); + testProtocolRejection( 0, new Draft_6455(Collections.emptyList(), Collections.singletonList( new Protocol( "" ))) ); } @Test(timeout = 5000) @@ -312,6 +346,62 @@ public void testHandshakeRejectionTestCase19() throws Exception { testProtocolRejection( 19, new Draft_6455() ); } + @Test(timeout = 5000) + public void testHandshakeRejectionTestCase20() throws Exception { + testProtocolRejection( 20, new Draft_6455() ); + } + + @Test(timeout = 5000) + public void testHandshakeRejectionTestCase21() throws Exception { + ArrayList protocols = new ArrayList(); + protocols.add( new Protocol( "chat1" ) ); + protocols.add( new Protocol( "chat2" ) ); + protocols.add( new Protocol( "chat3" ) ); + testProtocolRejection( 21, new Draft_6455( Collections.emptyList(), protocols ) ); + } + + @Test(timeout = 5000) + public void testHandshakeRejectionTestCase22() throws Exception { + ArrayList protocols = new ArrayList(); + protocols.add( new Protocol( "chat2" ) ); + protocols.add( new Protocol( "chat3" ) ); + protocols.add( new Protocol( "chat1" ) ); + testProtocolRejection( 22, new Draft_6455( Collections.emptyList(), protocols ) ); + } + @Test(timeout = 5000) + public void testHandshakeRejectionTestCase23() throws Exception { + ArrayList protocols = new ArrayList(); + protocols.add( new Protocol( "chat3" ) ); + protocols.add( new Protocol( "chat2" ) ); + protocols.add( new Protocol( "chat1" ) ); + testProtocolRejection( 23, new Draft_6455( Collections.emptyList(), protocols ) ); + } + + @Test(timeout = 5000) + public void testHandshakeRejectionTestCase24() throws Exception { + testProtocolRejection( 24, new Draft_6455() ); + } + @Test(timeout = 5000) + public void testHandshakeRejectionTestCase25() throws Exception { + testProtocolRejection( 25, new Draft_6455() ); + } + @Test(timeout = 5000) + public void testHandshakeRejectionTestCase26() throws Exception { + testProtocolRejection( 26, new Draft_6455() ); + } + + @Test(timeout = 5000) + public void testHandshakeRejectionTestCase27() throws Exception { + testProtocolRejection( 27, new Draft_6455( Collections.emptyList(), Collections.singletonList( new Protocol( "opc" ) ) ) ); + } + @Test(timeout = 5000) + public void testHandshakeRejectionTestCase28() throws Exception { + testProtocolRejection( 28, new Draft_6455( Collections.emptyList(), Collections.singletonList( new Protocol( "opc" ) ) ) ); + } + @Test(timeout = 5000) + public void testHandshakeRejectionTestCase29() throws Exception { + testProtocolRejection( 29, new Draft_6455( Collections.emptyList(), Collections.singletonList( new Protocol( "opc" ) ) ) ); + } private void testProtocolRejection( int i, Draft_6455 draft ) throws Exception { final int finalI = i; final boolean[] threadReturned = { false }; @@ -320,6 +410,11 @@ private void testProtocolRejection( int i, Draft_6455 draft ) throws Exception { public void onOpen( ServerHandshake handshakedata ) { switch(finalI) { case 0: + case 1: + case 2: + case 3: + case 4: + case 5: case 6: case 7: case 8: @@ -327,7 +422,13 @@ public void onOpen( ServerHandshake handshakedata ) { case 13: case 14: case 17: - counter++; + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 26: threadReturned[0] = true; closeConnection( CloseFrame.ABNORMAL_CLOSE, "Bye" ); break; @@ -343,9 +444,60 @@ public void onMessage( String message ) { @Override public void onClose( int code, String reason, boolean remote ) { + switch (finalI) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 20: + case 24: + case 25: + case 26: + assertEquals("" ,getProtocol().getProvidedProtocol()); + break; + case 5: + case 9: + case 10: + case 11: + case 12: + case 13: + case 15: + case 16: + case 18: + case 19: + case 27: + case 28: + case 29: + assertNull(getProtocol()); + break; + case 6: + case 7: + case 8: + case 17: + assertEquals("chat" ,getProtocol().getProvidedProtocol()); + break; + case 14: + case 22: + assertEquals("chat2" ,getProtocol().getProvidedProtocol()); + break; + case 21: + assertEquals("chat1" ,getProtocol().getProvidedProtocol()); + break; + case 23: + assertEquals("chat3" ,getProtocol().getProvidedProtocol()); + break; + default: + fail(); + } if( code == CloseFrame.ABNORMAL_CLOSE ) { switch(finalI) { case 0: + case 1: + case 2: + case 3: + case 4: + case 5: case 6: case 7: case 8: @@ -353,16 +505,20 @@ public void onClose( int code, String reason, boolean remote ) { case 13: case 14: case 17: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 26: return; } } if( code != CloseFrame.PROTOCOL_ERROR ) { fail( "There should be a protocol error! " + finalI + " " + code ); } else if( reason.endsWith( "refuses handshake" ) ) { - if( debugPrintouts ) - System.out.println( "Protocol error for test case: " + finalI ); threadReturned[0] = true; - counter++; } else { fail( "The reason should be included!" ); } diff --git a/src/test/java/org/java_websocket/protocols/ProtocolTest.java b/src/test/java/org/java_websocket/protocols/ProtocolTest.java index faf32891..91d7b339 100644 --- a/src/test/java/org/java_websocket/protocols/ProtocolTest.java +++ b/src/test/java/org/java_websocket/protocols/ProtocolTest.java @@ -46,12 +46,12 @@ public void testConstructor() throws Exception { public void testAcceptProvidedProtocol() throws Exception { Protocol protocol0 = new Protocol( "" ); assertTrue( protocol0.acceptProvidedProtocol( "" ) ); - assertTrue( !protocol0.acceptProvidedProtocol( "chat" ) ); - assertTrue( !protocol0.acceptProvidedProtocol( "chat, test" ) ); - assertTrue( !protocol0.acceptProvidedProtocol( "chat, test," ) ); + assertTrue( protocol0.acceptProvidedProtocol( "chat" ) ); + assertTrue( protocol0.acceptProvidedProtocol( "chat, test" ) ); + assertTrue( protocol0.acceptProvidedProtocol( "chat, test," ) ); Protocol protocol1 = new Protocol( "chat" ); assertTrue( protocol1.acceptProvidedProtocol( "chat" ) ); - assertTrue( !protocol1.acceptProvidedProtocol( "test" ) ); + assertFalse( protocol1.acceptProvidedProtocol( "test" ) ); assertTrue( protocol1.acceptProvidedProtocol( "chat, test" ) ); assertTrue( protocol1.acceptProvidedProtocol( "test, chat" ) ); assertTrue( protocol1.acceptProvidedProtocol( "test,chat" ) ); From f1802ae73fb79f1a4b083ae07f044a1fda416241 Mon Sep 17 00:00:00 2001 From: marci4 Date: Thu, 28 May 2020 22:20:42 +0200 Subject: [PATCH 2/2] Update Draft_6455Test.java Adjust tests --- .../java_websocket/drafts/Draft_6455Test.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/java_websocket/drafts/Draft_6455Test.java b/src/test/java/org/java_websocket/drafts/Draft_6455Test.java index cbf41ced..af0b1bfa 100644 --- a/src/test/java/org/java_websocket/drafts/Draft_6455Test.java +++ b/src/test/java/org/java_websocket/drafts/Draft_6455Test.java @@ -132,7 +132,7 @@ public void testGetKnownExtensions() throws Exception { @Test public void testGetProtocol() throws Exception { - Draft_6455 draft_6455 = new Draft_6455(); + Draft_6455 draft_6455 = new Draft_6455(Collections.emptyList(), Collections.emptyList()); assertNull( draft_6455.getProtocol() ); draft_6455.acceptHandshakeAsServer( handshakedataProtocolExtension ); assertNull( draft_6455.getProtocol() ); @@ -194,7 +194,7 @@ public void testToString() throws Exception { Draft_6455 draft_6455 = new Draft_6455(); assertEquals( "Draft_6455 extension: DefaultExtension max frame size: 2147483647", draft_6455.toString() ); draft_6455.acceptHandshakeAsServer( handshakedataProtocolExtension ); - assertEquals( "Draft_6455 extension: DefaultExtension max frame size: 2147483647", draft_6455.toString() ); + assertEquals( "Draft_6455 extension: DefaultExtension protocol: max frame size: 2147483647", draft_6455.toString() ); draft_6455 = new Draft_6455( Collections.emptyList(), Collections.singletonList( new Protocol( "chat" ) ) ); assertEquals( "Draft_6455 extension: DefaultExtension max frame size: 2147483647", draft_6455.toString() ); draft_6455.acceptHandshakeAsServer( handshakedataProtocolExtension ); @@ -223,7 +223,7 @@ public void testEquals() throws Exception { draft1.acceptHandshakeAsServer( handshakedataProtocolExtension ); assertNotEquals( draft2, draft3 ); assertNotEquals( draft0, draft2 ); - assertEquals( draft0, draft1 ); + assertNotEquals( draft0, draft1 ); draft2 = draft2.copyInstance(); draft1 = draft1.copyInstance(); //unequal for draft draft2 due to a provided protocol @@ -231,7 +231,7 @@ public void testEquals() throws Exception { draft1.acceptHandshakeAsServer( handshakedataProtocol ); assertNotEquals( draft2, draft3 ); assertNotEquals( draft0, draft2 ); - assertEquals( draft0, draft1 ); + assertNotEquals( draft0, draft1 ); draft2 = draft2.copyInstance(); draft1 = draft1.copyInstance(); //unequal for draft draft0 due to a provided protocol (no protocol) @@ -297,14 +297,14 @@ public void testHashCode() throws Exception { public void acceptHandshakeAsServer() throws Exception { Draft_6455 draft_6455 = new Draft_6455(); assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsServer( handshakedata ) ); - assertEquals( HandshakeState.NOT_MATCHED, draft_6455.acceptHandshakeAsServer( handshakedataProtocol ) ); + assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsServer( handshakedataProtocol ) ); assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsServer( handshakedataExtension ) ); - assertEquals( HandshakeState.NOT_MATCHED, draft_6455.acceptHandshakeAsServer( handshakedataProtocolExtension ) ); + assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsServer( handshakedataProtocolExtension ) ); draft_6455 = new Draft_6455( new TestExtension() ); assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsServer( handshakedata ) ); - assertEquals( HandshakeState.NOT_MATCHED, draft_6455.acceptHandshakeAsServer( handshakedataProtocol ) ); + assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsServer( handshakedataProtocol ) ); assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsServer( handshakedataExtension ) ); - assertEquals( HandshakeState.NOT_MATCHED, draft_6455.acceptHandshakeAsServer( handshakedataProtocolExtension ) ); + assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsServer( handshakedataProtocolExtension ) ); draft_6455 = new Draft_6455( Collections.emptyList(), Collections.singletonList( new Protocol( "chat" ) ) ); assertEquals( HandshakeState.NOT_MATCHED, draft_6455.acceptHandshakeAsServer( handshakedata ) ); assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsServer( handshakedataProtocol ) ); @@ -336,7 +336,7 @@ public void acceptHandshakeAsClient() throws Exception { response.put( "Sec-WebSocket-Accept", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=" ); assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsClient( request, response ) ); response.put( "Sec-WebSocket-Protocol", "chat" ); - assertEquals( HandshakeState.NOT_MATCHED, draft_6455.acceptHandshakeAsClient( request, response ) ); + assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsClient( request, response ) ); draft_6455 = new Draft_6455( Collections.emptyList(), Collections.singletonList( new Protocol( "chat" ) ) ); assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsClient( request, response ) ); ArrayList protocols = new ArrayList(); @@ -344,7 +344,7 @@ public void acceptHandshakeAsClient() throws Exception { protocols.add( new Protocol( "chat" ) ); draft_6455 = new Draft_6455( Collections.emptyList(), protocols ); assertEquals( HandshakeState.MATCHED, draft_6455.acceptHandshakeAsClient( request, response ) ); - draft_6455 = new Draft_6455(); + draft_6455 =new Draft_6455(Collections.emptyList(), Collections.emptyList()); assertEquals( HandshakeState.NOT_MATCHED, draft_6455.acceptHandshakeAsClient( request, response ) ); protocols.clear(); protocols.add( new Protocol( "chat3" ) );