Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
100 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
lib/PuppeteerSharp.Tests/PuppeteerTests/IgnoreHttpsErrorsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
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.Http; | ||
using PuppeteerSharp.Helpers; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace PuppeteerSharp.Tests.PuppeteerTests | ||
{ | ||
[Collection("PuppeteerLoaderFixture collection")] | ||
public class IgnoreHttpsErrorsTests : PuppeteerPageBaseTest | ||
{ | ||
public IgnoreHttpsErrorsTests(ITestOutputHelper output) : base(output) | ||
{ | ||
DefaultOptions = TestConstants.DefaultBrowserOptions(); | ||
DefaultOptions.IgnoreHTTPSErrors = true; | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldWork() | ||
{ | ||
var response = await Page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html"); | ||
Assert.Equal(HttpStatusCode.OK, response.Status); | ||
Assert.NotNull(response.SecurityDetails); | ||
Assert.Equal("TLS 1.2", response.SecurityDetails.Protocol); | ||
} | ||
|
||
[Fact] | ||
public async Task NetworkRedirectsShouldReportSecurityDetails() | ||
{ | ||
var responses = new List<Response>(); | ||
HttpsServer.SetRedirect("/plzredirect", "/empty.html"); | ||
|
||
Page.Response += (sender, e) => responses.Add(e.Response); | ||
|
||
await Page.GoToAsync(TestConstants.HttpsPrefix + "/plzredirect"); | ||
|
||
Assert.Equal(2, responses.Count); | ||
Assert.Equal(HttpStatusCode.Found, responses[0].Status); | ||
Assert.Equal("TLS 1.2", responses[0].SecurityDetails.Protocol); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldWorkWithRequestInterception() | ||
{ | ||
await Page.SetRequestInterceptionAsync(true); | ||
Page.Request += async (sender, e) => await e.Request.ContinueAsync(); | ||
var response = await Page.GoToAsync(TestConstants.EmptyPage); | ||
Assert.Equal(HttpStatusCode.OK, response.Status); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldWorkWithMixedContent() | ||
{ | ||
HttpsServer.SetRoute("/mixedcontent.html", async (context) => | ||
{ | ||
await context.Response.WriteAsync($"<iframe src='{TestConstants.EmptyPage}'></iframe>"); | ||
}); | ||
await Page.GoToAsync(TestConstants.HttpsPrefix + "/mixedcontent.html", new NavigationOptions | ||
{ | ||
WaitUntil = new[] { WaitUntilNavigation.Load } | ||
}); | ||
Assert.Equal(2, Page.Frames.Length); | ||
// Make sure blocked iframe has functional execution context | ||
// @see https://github.com/GoogleChrome/puppeteer/issues/2709 | ||
Assert.Equal(3, await Page.Frames[0].EvaluateExpressionAsync<int>("1 + 2")); | ||
Assert.Equal(5, await Page.Frames[1].EvaluateExpressionAsync<int>("2 + 3")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
lib/PuppeteerSharp/Messaging/NetworkGetResponseBodyResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace PuppeteerSharp.Messaging | ||
{ | ||
internal class NetworkGetResponseBodyResponse | ||
{ | ||
[JsonProperty("body")] | ||
public string Body { get; set; } | ||
[JsonProperty("base64Encoded")] | ||
public bool Base64Encoded { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters