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

Provide a consistent cookie API #1030

Merged
merged 9 commits into from
Sep 6, 2023
Merged

Provide a consistent cookie API #1030

merged 9 commits into from
Sep 6, 2023

Conversation

inancgumus
Copy link
Member

@inancgumus inancgumus commented Sep 5, 2023

What?

Refactors BrowserContext.addCookie to []*api.Cookie and improve its tests.

Why?

  • Provides a consistent API with the Cookies method. addCookies and Cookies both now use api.Cookie.
  • Separates Goja from the business logic.
  • Increases security by only accepting a well-defined api.Cookie type instead of letting users set cookies by using network.Cookie (which carries CDP internal data).
  • Makes code and tests more maintainable and robust.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

Updates: #6

It was unnecessarily setting network.Cookies to another slice.
BrowserContext.AddCookie needs the URL field to set cookies.
This is the first step in refactoring the AddCookies method.
We directly accept api.Cookies instead of network.Cookies and then
translating api.Cookies to network.Cookies.
We're starting to separate the CDP logic from the Goja logic.
This change improves the browser module's security by preventing users
to set internal CDP details using cookies.

Fix TestBrowserContextAddCookies
This lets us ensure no dependency exists between test cases.
Incorporates the happy path test (which was already existed) into the
test table and checks whether cookies are set with another field.

We don't join AddCookie and Cookies tests because they test the code
from different perspectives and in a more involved way for their own.
@inancgumus inancgumus requested a review from ankur22 September 5, 2023 09:06
@inancgumus inancgumus marked this pull request as ready for review September 5, 2023 09:06
Copy link
Collaborator

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great refactor! LGTM 🙂

@inancgumus inancgumus merged commit 46efce0 into main Sep 6, 2023
12 checks passed
@inancgumus inancgumus deleted the refactor/add-cookie branch September 6, 2023 13:09
@inancgumus inancgumus changed the title Refactor add cookie and improve tests Provide a consistent cookie API Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants