diff --git a/lib/PuppeteerSharp.TestServer/PuppeteerSharp.TestServer.csproj b/lib/PuppeteerSharp.TestServer/PuppeteerSharp.TestServer.csproj index 6e7b203a9..39a8a7775 100644 --- a/lib/PuppeteerSharp.TestServer/PuppeteerSharp.TestServer.csproj +++ b/lib/PuppeteerSharp.TestServer/PuppeteerSharp.TestServer.csproj @@ -13,9 +13,7 @@ - - - - + + diff --git a/lib/PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj b/lib/PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj index 61a770b3a..a502b4eac 100644 --- a/lib/PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj +++ b/lib/PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj @@ -13,6 +13,7 @@ + diff --git a/lib/PuppeteerSharp.Tests/PuppeteerTests/IgnoreHttpsErrorsTests.cs b/lib/PuppeteerSharp.Tests/PuppeteerTests/IgnoreHttpsErrorsTests.cs index 358ca8828..80817e5fb 100644 --- a/lib/PuppeteerSharp.Tests/PuppeteerTests/IgnoreHttpsErrorsTests.cs +++ b/lib/PuppeteerSharp.Tests/PuppeteerTests/IgnoreHttpsErrorsTests.cs @@ -1,13 +1,9 @@ using System; using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; using System.Net; -using System.Runtime.InteropServices; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http; -using PuppeteerSharp.Helpers; using Xunit; using Xunit.Abstractions; @@ -25,10 +21,21 @@ public IgnoreHttpsErrorsTests(ITestOutputHelper output) : base(output) [Fact] public async Task ShouldWork() { - var response = await Page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html"); + var requestTask = HttpsServer.WaitForRequest( + "/empty.html", + request => request.HttpContext.Features.Get().Protocol); + var responseTask = Page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html"); + + await Task.WhenAll( + requestTask, + responseTask); + + var response = responseTask.Result; Assert.Equal(HttpStatusCode.OK, response.Status); Assert.NotNull(response.SecurityDetails); - Assert.Equal("TLS 1.2", response.SecurityDetails.Protocol); + Assert.Equal( + TestUtils.CurateProtocol(requestTask.Result.ToString()), + TestUtils.CurateProtocol(response.SecurityDetails.Protocol)); } [Fact] @@ -39,11 +46,22 @@ public async Task NetworkRedirectsShouldReportSecurityDetails() Page.Response += (sender, e) => responses.Add(e.Response); - await Page.GoToAsync(TestConstants.HttpsPrefix + "/plzredirect"); + var requestTask = HttpsServer.WaitForRequest( + "/empty.html", + request => request.HttpContext.Features.Get().Protocol); + var responseTask = Page.GoToAsync(TestConstants.HttpsPrefix + "/plzredirect"); + + await Task.WhenAll( + requestTask, + responseTask); + + var response = responseTask.Result; Assert.Equal(2, responses.Count); Assert.Equal(HttpStatusCode.Found, responses[0].Status); - Assert.Equal("TLS 1.2", responses[0].SecurityDetails.Protocol); + Assert.Equal( + TestUtils.CurateProtocol(requestTask.Result.ToString()), + TestUtils.CurateProtocol(response.SecurityDetails.Protocol)); } [Fact] diff --git a/lib/PuppeteerSharp.Tests/PuppeteerTests/PuppeteerConnectTests.cs b/lib/PuppeteerSharp.Tests/PuppeteerTests/PuppeteerConnectTests.cs index 0e5ab8f02..76b971f72 100644 --- a/lib/PuppeteerSharp.Tests/PuppeteerTests/PuppeteerConnectTests.cs +++ b/lib/PuppeteerSharp.Tests/PuppeteerTests/PuppeteerConnectTests.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Connections.Features; using PuppeteerSharp.Transport; using Xunit; using Xunit.Abstractions; @@ -62,10 +63,21 @@ public async Task ShouldSupportIgnoreHTTPSErrorsOption() })) using (var page = await browser.NewPageAsync()) { - var response = await page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html"); + var requestTask = HttpsServer.WaitForRequest( + "/empty.html", + request => request.HttpContext.Features.Get().Protocol); + var responseTask = page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html"); + + await Task.WhenAll( + requestTask, + responseTask); + + var response = responseTask.Result; Assert.True(response.Ok); Assert.NotNull(response.SecurityDetails); - Assert.Equal("TLS 1.2", response.SecurityDetails.Protocol); + Assert.Equal( + TestUtils.CurateProtocol(requestTask.Result.ToString()), + TestUtils.CurateProtocol(response.SecurityDetails.Protocol)); } } diff --git a/lib/PuppeteerSharp.Tests/TestUtils.cs b/lib/PuppeteerSharp.Tests/TestUtils.cs index c5fd673aa..d9b197d6a 100644 --- a/lib/PuppeteerSharp.Tests/TestUtils.cs +++ b/lib/PuppeteerSharp.Tests/TestUtils.cs @@ -84,5 +84,10 @@ internal static async Task WaitForCookieInChromiumFileAsync(string path, string } } internal static bool IsFavicon(Request request) => request.Url.Contains("favicon.ico"); + internal static string CurateProtocol(string protocol) + => protocol + .ToLower() + .Replace(" ", string.Empty) + .Replace(".", string.Empty); } }