From 796617c612583ea4ff09422c38a77a24523c3eac Mon Sep 17 00:00:00 2001 From: Katya Sokolova Date: Tue, 2 Aug 2022 11:02:26 +0200 Subject: [PATCH 1/6] Fix sending end stream for websocket over H/2 --- .../SocketsHttpHandler/Http2Connection.cs | 2 +- .../Http/SocketsHttpHandler/Http2Stream.cs | 7 ++- .../tests/ConnectTest.Http2.cs | 48 ++++++++++----- .../tests/SendReceiveTest.Http2.cs | 61 +++++++++++++++++++ .../System.Net.WebSockets.Client.Tests.csproj | 1 + 5 files changed, 101 insertions(+), 18 deletions(-) create mode 100644 src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs index e026419270f4a..2ac32cfb3002d 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs @@ -1599,7 +1599,7 @@ private async ValueTask SendHeadersAsync(HttpRequestMessage request // Start the write. This serializes access to write to the connection, and ensures that HEADERS // and CONTINUATION frames stay together, as they must do. We use the lock as well to ensure new // streams are created and started in order. - await PerformWriteAsync(totalSize, (thisRef: this, http2Stream, headerBytes, endStream: (request.Content == null), mustFlush), static (s, writeBuffer) => + await PerformWriteAsync(totalSize, (thisRef: this, http2Stream, headerBytes, endStream: (request.Content == null && !http2Stream.WebSocketEstablished), mustFlush), static (s, writeBuffer) => { if (NetEventSource.Log.IsEnabled()) s.thisRef.Trace(s.http2Stream.StreamId, $"Started writing. Total header bytes={s.headerBytes.Length}"); diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs index b3f82779a715d..1b178ecaca558 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs @@ -45,7 +45,6 @@ private sealed class Http2Stream : IValueTaskSource, IHttpStreamHeadersHandler, private StreamCompletionState _requestCompletionState; private StreamCompletionState _responseCompletionState; private ResponseProtocolState _responseProtocolState; - private bool _webSocketEstablished; // If this is not null, then we have received a reset from the server // (i.e. RST_STREAM or general IO error processing the connection) @@ -157,6 +156,8 @@ public void Initialize(int streamId, int initialWindowSize) public Http2Connection Connection => _connection; + public bool WebSocketEstablished { get; private set; } + public HttpResponseMessage GetAndClearResponse() { // Once SendAsync completes, the Http2Stream should no longer hold onto the response message. @@ -637,7 +638,7 @@ private void OnStatus(int statusCode) { if (statusCode == 200 && _response.RequestMessage!.IsWebSocketH2Request()) { - _webSocketEstablished = true; + WebSocketEstablished = true; } _responseProtocolState = ResponseProtocolState.ExpectingHeaders; @@ -1047,7 +1048,7 @@ public async Task ReadResponseHeadersAsync(CancellationToken cancellationToken) MoveTrailersToResponseMessage(_response); responseContent.SetStream(EmptyReadStream.Instance); } - else if (_webSocketEstablished) + else if (WebSocketEstablished) { responseContent.SetStream(new Http2ReadWriteStream(this)); } diff --git a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs index 241063ab891b2..e52c0f046777f 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs @@ -19,19 +19,29 @@ public class ConnectTest_Http2 : ClientWebSocketTestBase { public ConnectTest_Http2(ITestOutputHelper output) : base(output) { } - [Fact] + [Theory] + [InlineData(false)] + [InlineData(true)] [SkipOnPlatform(TestPlatforms.Browser, "Self-signed certificates are not supported on browser")] - public async Task ConnectAsync_VersionNotSupported_Throws() + public async Task ConnectAsync_VersionNotSupported_Throws(bool useHandler) { await Http2LoopbackServer.CreateClientAndServerAsync(async uri => { - using (var clientSocket = new ClientWebSocket()) + using (var cws = new ClientWebSocket()) using (var cts = new CancellationTokenSource(TimeOutMilliseconds)) { - clientSocket.Options.HttpVersion = HttpVersion.Version20; - clientSocket.Options.HttpVersionPolicy = Http.HttpVersionPolicy.RequestVersionExact; - using var handler = CreateSocketsHttpHandler(allowAllCertificates: true); - Task t = clientSocket.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); + cws.Options.HttpVersion = HttpVersion.Version20; + cws.Options.HttpVersionPolicy = Http.HttpVersionPolicy.RequestVersionExact; + Task t; + if (useHandler) + { + using var handler = new SocketsHttpHandler(); + t = cws.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); + } + else + { + t = cws.ConnectAsync(uri, cts.Token); + } var ex = await Assert.ThrowsAnyAsync(() => t); Assert.IsType(ex.InnerException); Assert.True(ex.InnerException.Data.Contains("SETTINGS_ENABLE_CONNECT_PROTOCOL")); @@ -40,13 +50,15 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => async server => { Http2LoopbackConnection connection = await server.EstablishConnectionAsync(new SettingsEntry { SettingId = SettingId.EnableConnect, Value = 0 }); - }, new Http2Options() { WebSocketEndpoint = true } + }, new Http2Options() { WebSocketEndpoint = true, UseSsl = false } ); } - [Fact] + [Theory] + [InlineData(false)] + [InlineData(true)] [SkipOnPlatform(TestPlatforms.Browser, "Self-signed certificates are not supported on browser")] - public async Task ConnectAsync_VersionSupported_Success() + public async Task ConnectAsync_VersionSupported_Success(bool useHandler) { await Http2LoopbackServer.CreateClientAndServerAsync(async uri => { @@ -55,16 +67,24 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => { cws.Options.HttpVersion = HttpVersion.Version20; cws.Options.HttpVersionPolicy = Http.HttpVersionPolicy.RequestVersionExact; - using var handler = CreateSocketsHttpHandler(allowAllCertificates: true); - await cws.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); + if (useHandler) + { + using var handler = new SocketsHttpHandler(); + await cws.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); + } + else + { + await cws.ConnectAsync(uri, cts.Token); + } + } }, async server => { Http2LoopbackConnection connection = await server.EstablishConnectionAsync(new SettingsEntry { SettingId = SettingId.EnableConnect, Value = 1 }); - (int streamId, HttpRequestData requestData) = await connection.ReadAndParseRequestHeaderAsync(readBody : false); + (int streamId, HttpRequestData requestData) = await connection.ReadAndParseRequestHeaderAsync(readBody: false); await connection.SendResponseHeadersAsync(streamId, endStream: false, HttpStatusCode.OK); - }, new Http2Options() { WebSocketEndpoint = true } + }, new Http2Options() { WebSocketEndpoint = true, UseSsl = false } ); } } diff --git a/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs new file mode 100644 index 0000000000000..5ba22290ae879 --- /dev/null +++ b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs @@ -0,0 +1,61 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Net.Http; +using System.Net.Sockets; +using System.Net.Test.Common; +using System.Threading; +using System.Threading.Tasks; + +using Xunit; +using Xunit.Abstractions; + +namespace System.Net.WebSockets.Client.Tests +{ + public abstract class SendReceiveTest_Http2 : ClientWebSocketTestBase + { + public SendReceiveTest_Http2(ITestOutputHelper output) : base(output) { } + + [Theory] + [InlineData(false)] + [InlineData(true)] + [SkipOnPlatform(TestPlatforms.Browser, "Self-signed certificates are not supported on browser")] + public async Task SendReceive_Success(bool useHandler) + { + await Http2LoopbackServer.CreateClientAndServerAsync(async uri => + { + using (var cws = new ClientWebSocket()) + using (var cts = new CancellationTokenSource(TimeOutMilliseconds)) + { + cws.Options.HttpVersion = HttpVersion.Version20; + cws.Options.HttpVersionPolicy = Http.HttpVersionPolicy.RequestVersionExact; + if (useHandler) + { + using var handler = new SocketsHttpHandler(); + await cws.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); + } + else + { + await cws.ConnectAsync(uri, cts.Token); + } + + await cws.SendAsync(new byte[] { 2, 3, 4 }, WebSocketMessageType.Binary, true, cts.Token); + + await cws.ReceiveAsync(Array.Empty(), cts.Token); + } + }, + async server => + { + Http2LoopbackConnection connection = await server.EstablishConnectionAsync(new SettingsEntry { SettingId = SettingId.EnableConnect, Value = 1 }); + (int streamId, HttpRequestData requestData) = await connection.ReadAndParseRequestHeaderAsync(readBody: false); + // send status 200 OK to establish websocket + await connection.SendResponseHeadersAsync(streamId, endStream: false).ConfigureAwait(false); + + // send reply + await connection.SendResponseDataAsync(streamId, new byte[] { 2, 4, 5, 6 }, endStream: false); + + }, new Http2Options() { WebSocketEndpoint = true, UseSsl = false } + ); + } + } +} diff --git a/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj b/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj index 8615693825d14..7aff0244108ee 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj +++ b/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj @@ -70,6 +70,7 @@ + From c88e46b846466d40868cec70250c2e54f734064e Mon Sep 17 00:00:00 2001 From: Katya Sokolova Date: Tue, 2 Aug 2022 16:34:12 +0200 Subject: [PATCH 2/6] feedback --- .../SocketsHttpHandler/Http2Connection.cs | 2 +- .../Http/SocketsHttpHandler/Http2Stream.cs | 6 +- .../tests/ConnectTest.Http2.cs | 62 +++++++++++++++++-- .../tests/SendReceiveTest.Http2.cs | 58 +++++++++++++++-- 4 files changed, 113 insertions(+), 15 deletions(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs index 2ac32cfb3002d..85e7e5df694a5 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs @@ -1599,7 +1599,7 @@ private async ValueTask SendHeadersAsync(HttpRequestMessage request // Start the write. This serializes access to write to the connection, and ensures that HEADERS // and CONTINUATION frames stay together, as they must do. We use the lock as well to ensure new // streams are created and started in order. - await PerformWriteAsync(totalSize, (thisRef: this, http2Stream, headerBytes, endStream: (request.Content == null && !http2Stream.WebSocketEstablished), mustFlush), static (s, writeBuffer) => + await PerformWriteAsync(totalSize, (thisRef: this, http2Stream, headerBytes, endStream: (request.Content == null && !http2Stream.ConnectProtocolEstablished), mustFlush), static (s, writeBuffer) => { if (NetEventSource.Log.IsEnabled()) s.thisRef.Trace(s.http2Stream.StreamId, $"Started writing. Total header bytes={s.headerBytes.Length}"); diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs index 4c8970efe0adf..1ecb968fa322a 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Stream.cs @@ -157,7 +157,7 @@ public void Initialize(int streamId, int initialWindowSize) public Http2Connection Connection => _connection; - public bool WebSocketEstablished { get; private set; } + public bool ConnectProtocolEstablished { get; private set; } public HttpResponseMessage GetAndClearResponse() { @@ -639,7 +639,7 @@ private void OnStatus(int statusCode) { if (statusCode == 200 && _response.RequestMessage!.IsWebSocketH2Request()) { - WebSocketEstablished = true; + ConnectProtocolEstablished = true; } _responseProtocolState = ResponseProtocolState.ExpectingHeaders; @@ -1042,7 +1042,7 @@ public async Task ReadResponseHeadersAsync(CancellationToken cancellationToken) MoveTrailersToResponseMessage(_response); responseContent.SetStream(EmptyReadStream.Instance); } - else if (WebSocketEstablished) + else if (ConnectProtocolEstablished) { responseContent.SetStream(new Http2ReadWriteStream(this)); } diff --git a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs index e52c0f046777f..fb131555ca1bc 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs @@ -22,8 +22,7 @@ public ConnectTest_Http2(ITestOutputHelper output) : base(output) { } [Theory] [InlineData(false)] [InlineData(true)] - [SkipOnPlatform(TestPlatforms.Browser, "Self-signed certificates are not supported on browser")] - public async Task ConnectAsync_VersionNotSupported_Throws(bool useHandler) + public async Task ConnectAsync_VersionNotSupported_NoSsl_Throws(bool useHandler) { await Http2LoopbackServer.CreateClientAndServerAsync(async uri => { @@ -35,7 +34,7 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => Task t; if (useHandler) { - using var handler = new SocketsHttpHandler(); + var handler = new SocketsHttpHandler(); t = cws.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); } else @@ -54,11 +53,37 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => ); } + [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "Self-signed certificates are not supported on browser")] + public async Task ConnectAsync_VersionNotSupported_WithSsl_Throws() + { + await Http2LoopbackServer.CreateClientAndServerAsync(async uri => + { + using (var cws = new ClientWebSocket()) + using (var cts = new CancellationTokenSource(TimeOutMilliseconds)) + { + cws.Options.HttpVersion = HttpVersion.Version20; + cws.Options.HttpVersionPolicy = Http.HttpVersionPolicy.RequestVersionExact; + Task t; + var handler = CreateSocketsHttpHandler(allowAllCertificates: true); + t = cws.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); + + var ex = await Assert.ThrowsAnyAsync(() => t); + Assert.IsType(ex.InnerException); + Assert.True(ex.InnerException.Data.Contains("SETTINGS_ENABLE_CONNECT_PROTOCOL")); + } + }, + async server => + { + Http2LoopbackConnection connection = await server.EstablishConnectionAsync(new SettingsEntry { SettingId = SettingId.EnableConnect, Value = 0 }); + }, new Http2Options() { WebSocketEndpoint = true, UseSsl = true } + ); + } + [Theory] [InlineData(false)] [InlineData(true)] - [SkipOnPlatform(TestPlatforms.Browser, "Self-signed certificates are not supported on browser")] - public async Task ConnectAsync_VersionSupported_Success(bool useHandler) + public async Task ConnectAsync_VersionSupported_NoSsl_Success(bool useHandler) { await Http2LoopbackServer.CreateClientAndServerAsync(async uri => { @@ -69,7 +94,7 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => cws.Options.HttpVersionPolicy = Http.HttpVersionPolicy.RequestVersionExact; if (useHandler) { - using var handler = new SocketsHttpHandler(); + var handler = new SocketsHttpHandler(); await cws.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); } else @@ -87,5 +112,30 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => }, new Http2Options() { WebSocketEndpoint = true, UseSsl = false } ); } + + [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "Self-signed certificates are not supported on browser")] + public async Task ConnectAsync_VersionSupported_WithSsl_Success() + { + await Http2LoopbackServer.CreateClientAndServerAsync(async uri => + { + using (var cws = new ClientWebSocket()) + using (var cts = new CancellationTokenSource(TimeOutMilliseconds)) + { + cws.Options.HttpVersion = HttpVersion.Version20; + cws.Options.HttpVersionPolicy = Http.HttpVersionPolicy.RequestVersionExact; + + var handler = CreateSocketsHttpHandler(allowAllCertificates: true); + await cws.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); + } + }, + async server => + { + Http2LoopbackConnection connection = await server.EstablishConnectionAsync(new SettingsEntry { SettingId = SettingId.EnableConnect, Value = 1 }); + (int streamId, HttpRequestData requestData) = await connection.ReadAndParseRequestHeaderAsync(readBody: false); + await connection.SendResponseHeadersAsync(streamId, endStream: false, HttpStatusCode.OK); + }, new Http2Options() { WebSocketEndpoint = true, UseSsl = true } + ); + } } } diff --git a/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs index 5ba22290ae879..1c6552f8e7fa0 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Linq; using System.Net.Http; using System.Net.Sockets; using System.Net.Test.Common; @@ -10,6 +11,8 @@ using Xunit; using Xunit.Abstractions; +using static System.Net.Http.Functional.Tests.TestHelper; + namespace System.Net.WebSockets.Client.Tests { public abstract class SendReceiveTest_Http2 : ClientWebSocketTestBase @@ -19,9 +22,9 @@ public SendReceiveTest_Http2(ITestOutputHelper output) : base(output) { } [Theory] [InlineData(false)] [InlineData(true)] - [SkipOnPlatform(TestPlatforms.Browser, "Self-signed certificates are not supported on browser")] - public async Task SendReceive_Success(bool useHandler) + public async Task ReceiveNoThrowAfterSend_NoSsl(bool useHandler) { + var serverMessage = new byte[] { 4, 5, 6 }; await Http2LoopbackServer.CreateClientAndServerAsync(async uri => { using (var cws = new ClientWebSocket()) @@ -31,7 +34,7 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => cws.Options.HttpVersionPolicy = Http.HttpVersionPolicy.RequestVersionExact; if (useHandler) { - using var handler = new SocketsHttpHandler(); + var handler = new SocketsHttpHandler(); await cws.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); } else @@ -41,7 +44,9 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => await cws.SendAsync(new byte[] { 2, 3, 4 }, WebSocketMessageType.Binary, true, cts.Token); - await cws.ReceiveAsync(Array.Empty(), cts.Token); + var readBuffer = new byte[serverMessage.Length]; + await cws.ReceiveAsync(readBuffer, cts.Token); + Assert.Equal(serverMessage, readBuffer); } }, async server => @@ -52,10 +57,53 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => await connection.SendResponseHeadersAsync(streamId, endStream: false).ConfigureAwait(false); // send reply - await connection.SendResponseDataAsync(streamId, new byte[] { 2, 4, 5, 6 }, endStream: false); + byte binaryMessageType = 2; + var prefix = new byte[] { binaryMessageType, (byte)serverMessage.Length }; + byte[] constructMessage = prefix.Concat(serverMessage).ToArray(); + await connection.SendResponseDataAsync(streamId, constructMessage, endStream: false); }, new Http2Options() { WebSocketEndpoint = true, UseSsl = false } ); } + + [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "Self-signed certificates are not supported on browser")] + public async Task ReceiveNoThrowAfterSend_WithSsl() + { + var serverMessage = new byte[] { 4, 5, 6 }; + await Http2LoopbackServer.CreateClientAndServerAsync(async uri => + { + using (var cws = new ClientWebSocket()) + using (var cts = new CancellationTokenSource(TimeOutMilliseconds)) + { + cws.Options.HttpVersion = HttpVersion.Version20; + cws.Options.HttpVersionPolicy = Http.HttpVersionPolicy.RequestVersionExact; + + var handler = CreateSocketsHttpHandler(allowAllCertificates: true); + await cws.ConnectAsync(uri, new HttpMessageInvoker(handler), cts.Token); + + await cws.SendAsync(new byte[] { 2, 3, 4 }, WebSocketMessageType.Binary, true, cts.Token); + + var readBuffer = new byte[serverMessage.Length]; + await cws.ReceiveAsync(readBuffer, cts.Token); + Assert.Equal(serverMessage, readBuffer); + } + }, + async server => + { + Http2LoopbackConnection connection = await server.EstablishConnectionAsync(new SettingsEntry { SettingId = SettingId.EnableConnect, Value = 1 }); + (int streamId, HttpRequestData requestData) = await connection.ReadAndParseRequestHeaderAsync(readBody: false); + // send status 200 OK to establish websocket + await connection.SendResponseHeadersAsync(streamId, endStream: false).ConfigureAwait(false); + + // send reply + byte binaryMessageType = 2; + var prefix = new byte[] { binaryMessageType, (byte)serverMessage.Length }; + byte[] constructMessage = prefix.Concat(serverMessage).ToArray(); + await connection.SendResponseDataAsync(streamId, constructMessage, endStream: false); + + }, new Http2Options() { WebSocketEndpoint = true, UseSsl = true } + ); + } } } From 92c82144ef96ec9af5bb20ef9aba48187bf83cfb Mon Sep 17 00:00:00 2001 From: Katya Sokolova Date: Tue, 2 Aug 2022 17:52:56 +0200 Subject: [PATCH 3/6] Update src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs Co-authored-by: Natalia Kondratyeva --- .../System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs index 1c6552f8e7fa0..5e8caa8534155 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs @@ -15,7 +15,7 @@ namespace System.Net.WebSockets.Client.Tests { - public abstract class SendReceiveTest_Http2 : ClientWebSocketTestBase + public class SendReceiveTest_Http2 : ClientWebSocketTestBase { public SendReceiveTest_Http2(ITestOutputHelper output) : base(output) { } From 0d78ed8ea4c698455c197e1bac93bd786769e127 Mon Sep 17 00:00:00 2001 From: Katya Sokolova Date: Wed, 3 Aug 2022 13:12:42 +0200 Subject: [PATCH 4/6] default usessl in tests --- .../System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs | 4 ++-- .../tests/SendReceiveTest.Http2.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs index fb131555ca1bc..707d6e18c03c4 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs @@ -76,7 +76,7 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => async server => { Http2LoopbackConnection connection = await server.EstablishConnectionAsync(new SettingsEntry { SettingId = SettingId.EnableConnect, Value = 0 }); - }, new Http2Options() { WebSocketEndpoint = true, UseSsl = true } + }, new Http2Options() { WebSocketEndpoint = true } ); } @@ -134,7 +134,7 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => Http2LoopbackConnection connection = await server.EstablishConnectionAsync(new SettingsEntry { SettingId = SettingId.EnableConnect, Value = 1 }); (int streamId, HttpRequestData requestData) = await connection.ReadAndParseRequestHeaderAsync(readBody: false); await connection.SendResponseHeadersAsync(streamId, endStream: false, HttpStatusCode.OK); - }, new Http2Options() { WebSocketEndpoint = true, UseSsl = true } + }, new Http2Options() { WebSocketEndpoint = true } ); } } diff --git a/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs index 5e8caa8534155..5ecef899a4bba 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs @@ -102,7 +102,7 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => byte[] constructMessage = prefix.Concat(serverMessage).ToArray(); await connection.SendResponseDataAsync(streamId, constructMessage, endStream: false); - }, new Http2Options() { WebSocketEndpoint = true, UseSsl = true } + }, new Http2Options() { WebSocketEndpoint = true } ); } } From 164179340a5459cdf324e7c13ed69ab7b2bfb5cb Mon Sep 17 00:00:00 2001 From: Katya Sokolova Date: Fri, 5 Aug 2022 11:48:00 +0200 Subject: [PATCH 5/6] Update src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs Co-authored-by: Stephen Toub --- .../System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs index 707d6e18c03c4..9c232da746046 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs @@ -101,7 +101,6 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => { await cws.ConnectAsync(uri, cts.Token); } - } }, async server => From d2d3ff8178362cdf4ee8121f785040741fff4757 Mon Sep 17 00:00:00 2001 From: Katya Sokolova Date: Fri, 5 Aug 2022 11:55:04 +0200 Subject: [PATCH 6/6] disable new tests on browser because sockets not supported --- .../System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs | 2 ++ .../System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs index 9c232da746046..d59b2e5a8721e 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/ConnectTest.Http2.cs @@ -22,6 +22,7 @@ public ConnectTest_Http2(ITestOutputHelper output) : base(output) { } [Theory] [InlineData(false)] [InlineData(true)] + [SkipOnPlatform(TestPlatforms.Browser, "System.Net.Sockets is not supported on this platform")] public async Task ConnectAsync_VersionNotSupported_NoSsl_Throws(bool useHandler) { await Http2LoopbackServer.CreateClientAndServerAsync(async uri => @@ -83,6 +84,7 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri => [Theory] [InlineData(false)] [InlineData(true)] + [SkipOnPlatform(TestPlatforms.Browser, "System.Net.Sockets is not supported on this platform")] public async Task ConnectAsync_VersionSupported_NoSsl_Success(bool useHandler) { await Http2LoopbackServer.CreateClientAndServerAsync(async uri => diff --git a/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs index 5ecef899a4bba..5f3be83d5bfb7 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.Http2.cs @@ -22,6 +22,7 @@ public SendReceiveTest_Http2(ITestOutputHelper output) : base(output) { } [Theory] [InlineData(false)] [InlineData(true)] + [SkipOnPlatform(TestPlatforms.Browser, "System.Net.Sockets is not supported on this platform")] public async Task ReceiveNoThrowAfterSend_NoSsl(bool useHandler) { var serverMessage = new byte[] { 4, 5, 6 };