From f5ebfa64e98b0de4bbc599c7fec2756fb3676c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Mon, 22 Jul 2024 19:20:29 -0300 Subject: [PATCH] Fix cookie source scheme (#2708) --- .../TestExpectations.upstream.json | 7 ++++ .../CookiesTests/SetCookiesTests.cs | 33 +++++++++++++++++++ lib/PuppeteerSharp/CookieSourceScheme.cs | 4 +++ lib/PuppeteerSharp/PuppeteerSharp.csproj | 8 ++--- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.upstream.json b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.upstream.json index 7f7da06ce..2e6ddff10 100644 --- a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.upstream.json +++ b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.upstream.json @@ -1313,6 +1313,13 @@ "expectations": ["FAIL"], "comment": "TODO: add a comment explaining why this expectation is required (include links to issues)" }, + { + "testIdPattern": "[cookies.spec] Cookie specs Page.setCookie should set cookie with all available properties", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["firefox"], + "expectations": ["FAIL"], + "comment": "Chromium-specific test. The sourceScheme property is chromium-specific." + }, { "testIdPattern": "[cookies.spec] Cookie specs Page.setCookie should set secure same-site cookies from a frame", "platforms": ["darwin", "linux", "win32"], diff --git a/lib/PuppeteerSharp.Tests/CookiesTests/SetCookiesTests.cs b/lib/PuppeteerSharp.Tests/CookiesTests/SetCookiesTests.cs index 423272f71..7a7abb09e 100644 --- a/lib/PuppeteerSharp.Tests/CookiesTests/SetCookiesTests.cs +++ b/lib/PuppeteerSharp.Tests/CookiesTests/SetCookiesTests.cs @@ -131,6 +131,39 @@ await Page.SetCookieAsync(new CookieParam Assert.True(cookie.Session); } + [Test, Retry(2), PuppeteerTest("cookies.spec", "Cookie specs Page.setCookie", "should set cookie with all available properties")] + public async Task ShouldSetCookieWithAllAvailableProperties() + { + await Page.GoToAsync(TestConstants.EmptyPage); + + await Page.SetCookieAsync(new CookieParam + { + Name = "password", + Value = "123456", + Domain = "localhost", + Path = "/", + SameParty = false, + Expires = -1, + HttpOnly = false, + Secure = false, + SourceScheme = CookieSourceScheme.Unset, + }); + + var cookies = await Page.GetCookiesAsync(); + Assert.That(cookies, Has.Exactly(1).Items); + var cookie = cookies.First(); + Assert.AreEqual("password", cookie.Name); + Assert.AreEqual("123456", cookie.Value); + Assert.AreEqual("localhost", cookie.Domain); + Assert.AreEqual("/", cookie.Path); + Assert.AreEqual(-1, cookie.Expires); + Assert.AreEqual(14, cookie.Size); + Assert.False(cookie.HttpOnly); + Assert.False(cookie.Secure); + Assert.True(cookie.Session); + Assert.AreEqual(CookieSourceScheme.Unset, cookie.SourceScheme); + } + [Test, Retry(2), PuppeteerTest("cookies.spec", "Cookie specs Page.setCookie", "should set a cookie with a path")] public async Task ShouldSetACookieWithAPath() { diff --git a/lib/PuppeteerSharp/CookieSourceScheme.cs b/lib/PuppeteerSharp/CookieSourceScheme.cs index 596b87b7d..1c2551845 100644 --- a/lib/PuppeteerSharp/CookieSourceScheme.cs +++ b/lib/PuppeteerSharp/CookieSourceScheme.cs @@ -20,6 +20,9 @@ // * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // * SOFTWARE. +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + namespace PuppeteerSharp; /// @@ -27,6 +30,7 @@ namespace PuppeteerSharp; /// "Unset" allows protocol clients to emulate legacy cookie scope for the scheme. /// This is a temporary ability and it will be removed in the future. /// +[JsonConverter(typeof(StringEnumConverter))] public enum CookieSourceScheme { /// diff --git a/lib/PuppeteerSharp/PuppeteerSharp.csproj b/lib/PuppeteerSharp/PuppeteerSharp.csproj index f91b92eca..d166dcafb 100644 --- a/lib/PuppeteerSharp/PuppeteerSharp.csproj +++ b/lib/PuppeteerSharp/PuppeteerSharp.csproj @@ -12,10 +12,10 @@ Headless Browser .NET API PuppeteerSharp - 18.0.4 - 18.0.4 - 18.0.4 - 18.0.4 + 18.0.5 + 18.0.5 + 18.0.5 + 18.0.5 false false embedded