Skip to content

Commit f5ebfa6

Browse files
authored
Fix cookie source scheme (#2708)
1 parent cd4aa95 commit f5ebfa6

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.upstream.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,13 @@
13131313
"expectations": ["FAIL"],
13141314
"comment": "TODO: add a comment explaining why this expectation is required (include links to issues)"
13151315
},
1316+
{
1317+
"testIdPattern": "[cookies.spec] Cookie specs Page.setCookie should set cookie with all available properties",
1318+
"platforms": ["darwin", "linux", "win32"],
1319+
"parameters": ["firefox"],
1320+
"expectations": ["FAIL"],
1321+
"comment": "Chromium-specific test. The sourceScheme property is chromium-specific."
1322+
},
13161323
{
13171324
"testIdPattern": "[cookies.spec] Cookie specs Page.setCookie should set secure same-site cookies from a frame",
13181325
"platforms": ["darwin", "linux", "win32"],

lib/PuppeteerSharp.Tests/CookiesTests/SetCookiesTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,39 @@ await Page.SetCookieAsync(new CookieParam
131131
Assert.True(cookie.Session);
132132
}
133133

134+
[Test, Retry(2), PuppeteerTest("cookies.spec", "Cookie specs Page.setCookie", "should set cookie with all available properties")]
135+
public async Task ShouldSetCookieWithAllAvailableProperties()
136+
{
137+
await Page.GoToAsync(TestConstants.EmptyPage);
138+
139+
await Page.SetCookieAsync(new CookieParam
140+
{
141+
Name = "password",
142+
Value = "123456",
143+
Domain = "localhost",
144+
Path = "/",
145+
SameParty = false,
146+
Expires = -1,
147+
HttpOnly = false,
148+
Secure = false,
149+
SourceScheme = CookieSourceScheme.Unset,
150+
});
151+
152+
var cookies = await Page.GetCookiesAsync();
153+
Assert.That(cookies, Has.Exactly(1).Items);
154+
var cookie = cookies.First();
155+
Assert.AreEqual("password", cookie.Name);
156+
Assert.AreEqual("123456", cookie.Value);
157+
Assert.AreEqual("localhost", cookie.Domain);
158+
Assert.AreEqual("/", cookie.Path);
159+
Assert.AreEqual(-1, cookie.Expires);
160+
Assert.AreEqual(14, cookie.Size);
161+
Assert.False(cookie.HttpOnly);
162+
Assert.False(cookie.Secure);
163+
Assert.True(cookie.Session);
164+
Assert.AreEqual(CookieSourceScheme.Unset, cookie.SourceScheme);
165+
}
166+
134167
[Test, Retry(2), PuppeteerTest("cookies.spec", "Cookie specs Page.setCookie", "should set a cookie with a path")]
135168
public async Task ShouldSetACookieWithAPath()
136169
{

lib/PuppeteerSharp/CookieSourceScheme.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// * SOFTWARE.
2222

23+
using Newtonsoft.Json;
24+
using Newtonsoft.Json.Converters;
25+
2326
namespace PuppeteerSharp;
2427

2528
/// <summary>
2629
/// Represents the source scheme of the origin that originally set the cookie. A value of
2730
/// "Unset" allows protocol clients to emulate legacy cookie scope for the scheme.
2831
/// This is a temporary ability and it will be removed in the future.
2932
/// </summary>
33+
[JsonConverter(typeof(StringEnumConverter))]
3034
public enum CookieSourceScheme
3135
{
3236
/// <summary>

lib/PuppeteerSharp/PuppeteerSharp.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<Description>Headless Browser .NET API</Description>
1313
<PackageId>PuppeteerSharp</PackageId>
1414
<PackageReleaseNotes></PackageReleaseNotes>
15-
<PackageVersion>18.0.4</PackageVersion>
16-
<ReleaseVersion>18.0.4</ReleaseVersion>
17-
<AssemblyVersion>18.0.4</AssemblyVersion>
18-
<FileVersion>18.0.4</FileVersion>
15+
<PackageVersion>18.0.5</PackageVersion>
16+
<ReleaseVersion>18.0.5</ReleaseVersion>
17+
<AssemblyVersion>18.0.5</AssemblyVersion>
18+
<FileVersion>18.0.5</FileVersion>
1919
<SynchReleaseVersion>false</SynchReleaseVersion>
2020
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
2121
<DebugType>embedded</DebugType>

0 commit comments

Comments
 (0)