Skip to content

Commit

Permalink
fix(ui): Update default and max count for maxCookieNumber (argoproj#1…
Browse files Browse the repository at this point in the history
…4979)

* Update default and max count for maxCookieNumber

Signed-off-by: zvlb <[email protected]>
  • Loading branch information
zvlb authored and tesla59 committed Dec 16, 2023
1 parent dcbec03 commit 3d01c67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions util/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
const maxCookieLength = 4093

// max number of chunks a cookie can be broken into. To be compatible with
// widest range of browsers, we shouldn't create more than 30 cookies per domain
var maxCookieNumber = env.ParseNumFromEnv(common.EnvMaxCookieNumber, 10, 0, 30)
// widest range of browsers, you shouldn't create more than 30 cookies per domain
var maxCookieNumber = env.ParseNumFromEnv(common.EnvMaxCookieNumber, 20, 0, math.MaxInt64)

// MakeCookieMetadata generates a string representing a Web cookie. Yum!
func MakeCookieMetadata(key, value string, flags ...string) ([]string, error) {
Expand Down
10 changes: 9 additions & 1 deletion util/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ func TestCookieMaxLength(t *testing.T) {

// keys will be of format foo, foo-1, foo-2 ..
cookies, err = MakeCookieMetadata("foo", strings.Repeat("_", (maxCookieLength-5)*maxCookieNumber))
assert.EqualError(t, err, "the authentication token is 40880 characters long and requires 11 cookies but the max number of cookies is 10. Contact your Argo CD administrator to increase the max number of cookies")
assert.EqualError(t, err, "the authentication token is 81760 characters long and requires 21 cookies but the max number of cookies is 20. Contact your Argo CD administrator to increase the max number of cookies")
assert.Equal(t, 0, len(cookies))
}

func TestCookieWithAttributes(t *testing.T) {
flags := []string{"SameSite=lax", "httpOnly"}

cookies, err := MakeCookieMetadata("foo", "bar", flags...)
assert.NoError(t, err)
assert.Equal(t, "foo=bar; SameSite=lax; httpOnly", cookies[0])
}

func TestSplitCookie(t *testing.T) {
cookieValue := strings.Repeat("_", (maxCookieLength-6)*4)
cookies, err := MakeCookieMetadata("foo", cookieValue)
Expand Down

0 comments on commit 3d01c67

Please sign in to comment.