Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplication of partitionKey that resulted in invalid json #2826

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions lib/PuppeteerSharp.Tests/CookiesTests/SetCookiesTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
Expand Down Expand Up @@ -186,6 +187,43 @@ await Page.SetCookieAsync(new CookieParam
Assert.That(cookie.Session, Is.True);
}

[Test, Retry(2), PuppeteerTest("cookies.spec", "Cookie specs Page.setCookie", "should set a cookie with a partitionKey")]
public async Task ShouldSetACookieWithAPartitionKey()
{
var options = TestConstants.DefaultBrowserOptions();
options.AcceptInsecureCerts = true;

await using var browser = await Puppeteer.LaunchAsync(options, TestConstants.LoggerFactory);
await using var page = await browser.NewPageAsync();
await page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html");
var url = new Uri(page.Url);
var key = url.GetLeftPart(UriPartial.Authority);
await page.SetCookieAsync(new CookieParam
{
Url = url.AbsoluteUri,
Name = "partitionCookie",
Value = "partition",
Secure = true,
PartitionKey = key,
});
var cookies = await page.GetCookiesAsync();
Assert.That(cookies, Has.Exactly(1).Items);
var cookie = cookies.First();
Assert.That(cookie.Name, Is.EqualTo("partitionCookie"));
Assert.That(cookie.Value, Is.EqualTo("partition"));
Assert.That(cookie.Domain, Is.EqualTo(url.Host));
Assert.That(cookie.Path, Is.EqualTo("/"));
Assert.That(cookie.Expires, Is.EqualTo(-1));
Assert.That(cookie.Size, Is.EqualTo(24));
Assert.That(cookie.HttpOnly, Is.False);
Assert.That(cookie.Secure, Is.True);
Assert.That(cookie.Session, Is.True);
Assert.That(cookie.SourceScheme, Is.EqualTo(CookieSourceScheme.Secure));
if (TestConstants.IsChrome)
key = url.GetComponents(UriComponents.Scheme | UriComponents.Host, UriFormat.UriEscaped);
Assert.That(cookie.PartitionKey, Is.EqualTo(key));
}

[Test, Retry(2), PuppeteerTest("cookies.spec", "Cookie specs Page.setCookie", "should not set a cookie on a blank page")]
public async Task ShouldNotSetACookieOnABlankPage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override void Write(
{
if (value != null && writer != null)
{
writer.WriteStartObject("partitionKey");
writer.WriteStartObject();
writer.WriteString("topLevelSite", value);
writer.WriteBoolean("hasCrossSiteAncestor", false);
writer.WriteEndObject();
Expand Down
Loading