public void TestNeverSkip()
        {
            IWebSocketExtensionFilter neverSkip = NeverSkipWebSocketExtensionFilter.Instance;

            BinaryWebSocketFrame binaryFrame = new BinaryWebSocketFrame();

            Assert.False(neverSkip.MustSkip(binaryFrame));
            Assert.True(binaryFrame.Release());

            TextWebSocketFrame textFrame = new TextWebSocketFrame();

            Assert.False(neverSkip.MustSkip(textFrame));
            Assert.True(textFrame.Release());

            PingWebSocketFrame pingFrame = new PingWebSocketFrame();

            Assert.False(neverSkip.MustSkip(pingFrame));
            Assert.True(pingFrame.Release());

            PongWebSocketFrame pongFrame = new PongWebSocketFrame();

            Assert.False(neverSkip.MustSkip(pongFrame));
            Assert.True(pongFrame.Release());

            CloseWebSocketFrame closeFrame = new CloseWebSocketFrame();

            Assert.False(neverSkip.MustSkip(closeFrame));
            Assert.True(closeFrame.Release());

            ContinuationWebSocketFrame continuationFrame = new ContinuationWebSocketFrame();

            Assert.False(neverSkip.MustSkip(continuationFrame));
            Assert.True(continuationFrame.Release());
        }
Beispiel #2
0
        public void CloseFrameSentWhenServerChannelClosedSilently()
        {
            EmbeddedChannel client = CreateClient();
            EmbeddedChannel server = CreateServer();

            Assert.False(server.WriteInbound(client.ReadOutbound <object>()));
            Assert.False(client.WriteInbound(server.ReadOutbound <object>()));

            // When server channel closed without explicit close-frame
            server.CloseAsync();

            // Then client receives NORMAL_CLOSURE close-frame
            Assert.True(client.WriteInbound(server.ReadOutbound <object>()));
            Assert.False(server.Open);

            CloseWebSocketFrame closeMessage = client.ReadInbound <CloseWebSocketFrame>();

            Assert.Equal(closeMessage.StatusCode(), WebSocketCloseStatus.NormalClosure.Code);
            closeMessage.Release();

            client.CloseAsync();
            Assert.True(ReferenceCountUtil.Release(client.ReadOutbound <object>()));
            Assert.False(client.FinishAndReleaseAll());
            Assert.False(server.FinishAndReleaseAll());
        }
Beispiel #3
0
        public void ExplicitCloseFrameSentWhenClientChannelClosed()
        {
            WebSocketCloseStatus closeStatus = WebSocketCloseStatus.InvalidPayloadData;
            EmbeddedChannel      client      = CreateClient();
            EmbeddedChannel      server      = CreateServer();

            Assert.False(server.WriteInbound(client.ReadOutbound <object>()));
            Assert.False(client.WriteInbound(server.ReadOutbound <object>()));

            // When client channel closed with explicit close-frame
            Assert.True(client.WriteOutbound(new CloseWebSocketFrame(closeStatus)));
            client.CloseAsync();

            // Then client receives provided close-frame
            Assert.False(server.WriteInbound(client.ReadOutbound <object>()));
            Assert.False(client.Open);
            Assert.False(server.Open);

            CloseWebSocketFrame closeMessage = Decode <CloseWebSocketFrame>(server.ReadOutbound <IByteBuffer>());

            Assert.Equal(closeMessage.StatusCode(), closeStatus.Code);
            closeMessage.Release();

            Assert.False(client.FinishAndReleaseAll());
            Assert.False(server.FinishAndReleaseAll());
        }
Beispiel #4
0
        public void ExplicitCloseFrameSentWhenServerChannelClosed()
        {
            WebSocketCloseStatus closeStatus = WebSocketCloseStatus.EndpointUnavailable;
            EmbeddedChannel      client      = CreateClient();
            EmbeddedChannel      server      = CreateServer();

            Assert.False(server.WriteInbound(client.ReadOutbound <object>()));
            Assert.False(client.WriteInbound(server.ReadOutbound <object>()));

            // When server channel closed with explicit close-frame
            Assert.True(server.WriteOutbound(new CloseWebSocketFrame(closeStatus)));
            server.CloseAsync();

            // Then client receives provided close-frame
            Assert.True(client.WriteInbound(server.ReadOutbound <object>()));
            Assert.False(server.Open);

            CloseWebSocketFrame closeMessage = client.ReadInbound <CloseWebSocketFrame>();

            Assert.Equal(closeMessage.StatusCode(), closeStatus.Code);
            closeMessage.Release();

            client.CloseAsync();
            Assert.True(ReferenceCountUtil.Release(client.ReadOutbound <object>()));
            Assert.False(client.FinishAndReleaseAll());
            Assert.False(server.FinishAndReleaseAll());
        }
Beispiel #5
0
        public void CloseFrameSentWhenClientChannelClosedSilently()
        {
            EmbeddedChannel client = CreateClient();
            EmbeddedChannel server = CreateServer();

            Assert.False(server.WriteInbound(client.ReadOutbound <object>()));
            Assert.False(client.WriteInbound(server.ReadOutbound <object>()));

            // When client channel closed without explicit close-frame
            client.CloseAsync();

            // Then server receives NORMAL_CLOSURE close-frame
            Assert.False(server.WriteInbound(client.ReadOutbound <object>()));
            Assert.False(client.Open);
            Assert.False(server.Open);

            CloseWebSocketFrame closeMessage = Decode <CloseWebSocketFrame>(server.ReadOutbound <IByteBuffer>());

            Assert.Equal(closeMessage, new CloseWebSocketFrame(WebSocketCloseStatus.NormalClosure));
            closeMessage.Release();

            Assert.False(client.FinishAndReleaseAll());
            Assert.False(server.FinishAndReleaseAll());
        }