jonhoo / fantoccini

A high-level API for programmatically interacting with web pages through WebDriver.
Apache License 2.0
1.68k stars 125 forks source link

Fix Cookie -> WebDriverCookie same_site parsing #192

Closed 10ne1 closed 2 years ago

10ne1 commented 2 years ago

Fetching all cookies from fantoccini client and loading them back reveals that same_site is not properly parsed when converting from Cookie -> WebDriverCookie.

For example, client.get_all_cookies() can return both the following same_site values in different cookies, the second of which is transformed by the map call into an Option::None which gets ignored by WebDriverCookie serde skip_serializing_if = "Option::is_none":

same_site: Some( None, ),

same_site: None,

An example error when calling client.add_cookie() with the above "same_site: None":

thread 'main' panicked at 'called Result::unwrap() on an Err value: Standard(WebDriver { error: InvalidArgument, message: "invalid argument: invalid 'sameSite'\n (Session info: chrome=98.0.4758.80)"

This fixes the error by parsing the top-level None value to a None string as expected by WebDriverCookie.

10ne1 commented 2 years ago

Oh, that's fascinating! I like the fix. Would you mind adding a test for this too?

Sure, I'll add a test.

Adding some more context on my use case in case you find it interesting: I need to share cookies between fantoccini/webdriver and reqwest for a hobby project, so I've been uncovering some corner cases on both sides (for e.g. I also just posted this fix for reqwest client cookie_store which was loosing some cookie info when adding/removing to its store).

codecov[bot] commented 2 years ago

Codecov Report

Merging #192 (23db532) into main (d60a41d) will not change coverage. The diff coverage is 66.66%.

Additional details and impacted files | [Impacted Files](https://codecov.io/gh/jonhoo/fantoccini/pull/192?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jon+Gjengset) | Coverage Δ | | |---|---|---| | [src/cookies.rs](https://codecov.io/gh/jonhoo/fantoccini/pull/192/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jon+Gjengset#diff-c3JjL2Nvb2tpZXMucnM=) | `94.11% <66.66%> (ø)` | |
jonhoo commented 2 years ago

Released in 0.20.0-rc.2 :tada: