Skip to content

Commit

Permalink
test: check secure cookies (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
canstand authored Apr 2, 2024
1 parent 2fb5d39 commit 872a873
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/browser_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,32 @@ func TestBrowserContextOnResponse(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "<!DOCTYPE html>\n<title>Woof-Woof</title>\n", string(body))
}

func TestBrowserContextGetSecureCookies(t *testing.T) {
BeforeEach(t, playwright.BrowserNewContextOptions{
IgnoreHttpsErrors: playwright.Bool(true), // webkit requires https to support secure cookies
})

tlsServer := newTestServer(true)
defer tlsServer.testServer.Close()

tlsServer.SetRoute("/cookie.html", func(w http.ResponseWriter, r *http.Request) {
// set secure cookie
cookie := http.Cookie{
Name: "foo",
Value: "bar",
Secure: true,
HttpOnly: true,
}
http.SetCookie(w, &cookie)
})

_, err := page.Goto(fmt.Sprintf("%s/cookie.html", tlsServer.PREFIX))
require.NoError(t, err)
cookies, err := context.Cookies()
require.NoError(t, err)
require.Equal(t, 1, len(cookies))
require.Equal(t, "foo", cookies[0].Name)
require.Equal(t, "bar", cookies[0].Value)
require.True(t, cookies[0].Secure)
}

0 comments on commit 872a873

Please sign in to comment.