Skip to content

Commit

Permalink
Fix cookie source scheme (#2708)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored Jul 22, 2024
1 parent cd4aa95 commit f5ebfa6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
33 changes: 33 additions & 0 deletions lib/PuppeteerSharp.Tests/CookiesTests/SetCookiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
4 changes: 4 additions & 0 deletions lib/PuppeteerSharp/CookieSourceScheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
// * 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;

/// <summary>
/// Represents the source scheme of the origin that originally set the cookie. A value of
/// "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.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum CookieSourceScheme
{
/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions lib/PuppeteerSharp/PuppeteerSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<Description>Headless Browser .NET API</Description>
<PackageId>PuppeteerSharp</PackageId>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageVersion>18.0.4</PackageVersion>
<ReleaseVersion>18.0.4</ReleaseVersion>
<AssemblyVersion>18.0.4</AssemblyVersion>
<FileVersion>18.0.4</FileVersion>
<PackageVersion>18.0.5</PackageVersion>
<ReleaseVersion>18.0.5</ReleaseVersion>
<AssemblyVersion>18.0.5</AssemblyVersion>
<FileVersion>18.0.5</FileVersion>
<SynchReleaseVersion>false</SynchReleaseVersion>
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
<DebugType>embedded</DebugType>
Expand Down

0 comments on commit f5ebfa6

Please sign in to comment.