enhance: thread-safe CookieJar, SameSite cookie attr, dynamic Google countries
All checks were successful
CI / vet (pull_request) Successful in 40s
CI / build (pull_request) Successful in 1m22s
CI / test (pull_request) Successful in 1m28s

- Wrap staticCookieJar in struct with sync.RWMutex for thread safety
- Add SameSite field to Cookie struct with Strict/Lax/None constants
- Update Playwright cookie conversion functions for SameSite
- Replace hardcoded 4-country switch with dynamic country code generation

Closes #20, #22, #23
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 16:34:54 +00:00
parent 0ba9cc9b98
commit 963696cd62
5 changed files with 104 additions and 59 deletions

View File

@@ -101,10 +101,10 @@ func TestCookie_IsTargetMatch_InvalidURL(t *testing.T) {
}
func TestStaticCookieJar_GetAll(t *testing.T) {
jar := &staticCookieJar{
Cookie{Host: "a.com", Name: "a", Value: "1"},
Cookie{Host: "b.com", Name: "b", Value: "2"},
}
jar := &staticCookieJar{cookies: []Cookie{
{Host: "a.com", Name: "a", Value: "1"},
{Host: "b.com", Name: "b", Value: "2"},
}}
cookies, err := jar.GetAll()
if err != nil {
@@ -116,10 +116,10 @@ func TestStaticCookieJar_GetAll(t *testing.T) {
}
func TestStaticCookieJar_Get(t *testing.T) {
jar := &staticCookieJar{
Cookie{Host: "example.com", Path: "/", Name: "a", Value: "1"},
Cookie{Host: "other.com", Path: "/", Name: "b", Value: "2"},
}
jar := &staticCookieJar{cookies: []Cookie{
{Host: "example.com", Path: "/", Name: "a", Value: "1"},
{Host: "other.com", Path: "/", Name: "b", Value: "2"},
}}
cookies, err := jar.Get("https://example.com/page")
if err != nil {
@@ -150,9 +150,9 @@ func TestStaticCookieJar_Set_New(t *testing.T) {
}
func TestStaticCookieJar_Set_Update(t *testing.T) {
jar := &staticCookieJar{
Cookie{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}
jar := &staticCookieJar{cookies: []Cookie{
{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}}
err := jar.Set(Cookie{Host: "example.com", Path: "/", Name: "a", Value: "2"})
if err != nil {
t.Fatalf("Set() error: %v", err)
@@ -168,10 +168,10 @@ func TestStaticCookieJar_Set_Update(t *testing.T) {
}
func TestStaticCookieJar_Delete(t *testing.T) {
jar := &staticCookieJar{
Cookie{Host: "example.com", Path: "/", Name: "a", Value: "1"},
Cookie{Host: "other.com", Path: "/", Name: "b", Value: "2"},
}
jar := &staticCookieJar{cookies: []Cookie{
{Host: "example.com", Path: "/", Name: "a", Value: "1"},
{Host: "other.com", Path: "/", Name: "b", Value: "2"},
}}
err := jar.Delete(Cookie{Host: "example.com", Path: "/", Name: "a"})
if err != nil {
t.Fatalf("Delete() error: %v", err)
@@ -187,9 +187,9 @@ func TestStaticCookieJar_Delete(t *testing.T) {
}
func TestStaticCookieJar_Delete_NotFound(t *testing.T) {
jar := &staticCookieJar{
Cookie{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}
jar := &staticCookieJar{cookies: []Cookie{
{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}}
err := jar.Delete(Cookie{Host: "nonexistent.com", Path: "/", Name: "x"})
if err != nil {
t.Fatalf("Delete() error: %v", err)
@@ -202,9 +202,9 @@ func TestStaticCookieJar_Delete_NotFound(t *testing.T) {
}
func TestReadOnlyCookieJar_SetIsNoop(t *testing.T) {
inner := &staticCookieJar{
Cookie{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}
inner := &staticCookieJar{cookies: []Cookie{
{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}}
ro := ReadOnlyCookieJar{Jar: inner}
err := ro.Set(Cookie{Host: "example.com", Path: "/", Name: "new", Value: "val"})
@@ -219,9 +219,9 @@ func TestReadOnlyCookieJar_SetIsNoop(t *testing.T) {
}
func TestReadOnlyCookieJar_DeleteIsNoop(t *testing.T) {
inner := &staticCookieJar{
Cookie{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}
inner := &staticCookieJar{cookies: []Cookie{
{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}}
ro := ReadOnlyCookieJar{Jar: inner}
err := ro.Delete(Cookie{Host: "example.com", Path: "/", Name: "a"})
@@ -236,9 +236,9 @@ func TestReadOnlyCookieJar_DeleteIsNoop(t *testing.T) {
}
func TestReadOnlyCookieJar_GetAll(t *testing.T) {
inner := &staticCookieJar{
Cookie{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}
inner := &staticCookieJar{cookies: []Cookie{
{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}}
ro := ReadOnlyCookieJar{Jar: inner}
cookies, err := ro.GetAll()
@@ -251,9 +251,9 @@ func TestReadOnlyCookieJar_GetAll(t *testing.T) {
}
func TestReadOnlyCookieJar_Get(t *testing.T) {
inner := &staticCookieJar{
Cookie{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}
inner := &staticCookieJar{cookies: []Cookie{
{Host: "example.com", Path: "/", Name: "a", Value: "1"},
}}
ro := ReadOnlyCookieJar{Jar: inner}
cookies, err := ro.Get("https://example.com/page")