Skip to content

Commit

Permalink
Get TLS version from request (#1239)
Browse files Browse the repository at this point in the history
* Get TLS version from request

* Remove usings

* short lines

* Move CurateProtocol to a generic place

* cr

* Add package

* Check why is getting stuck

* Update core versions

* Reset previous change
  • Loading branch information
kblok committed Aug 5, 2019
1 parent e0d0018 commit 3af9b60
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions lib/PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0005" />
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Issues\" />
Expand Down
36 changes: 27 additions & 9 deletions lib/PuppeteerSharp.Tests/PuppeteerTests/IgnoreHttpsErrorsTests.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<ITlsHandshakeFeature>().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]
Expand All @@ -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<ITlsHandshakeFeature>().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]
Expand Down
16 changes: 14 additions & 2 deletions lib/PuppeteerSharp.Tests/PuppeteerTests/PuppeteerConnectTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<ITlsHandshakeFeature>().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));
}
}

Expand Down
5 changes: 5 additions & 0 deletions lib/PuppeteerSharp.Tests/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 3af9b60

Please sign in to comment.