forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support longer http cookie (argoproj#2917) (argoproj#5497)
* fix: support longer cookie Signed-off-by: kshamajain99 <kshamajain99@gmail.com>
- Loading branch information
1 parent
062dfc9
commit 49b6d00
Showing
11 changed files
with
169 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,41 @@ | ||
package http | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCookieMaxLength(t *testing.T) { | ||
cookies, err := MakeCookieMetadata("foo", "bar") | ||
assert.NoError(t, err) | ||
assert.Equal(t, "foo=bar", cookies[0]) | ||
|
||
// keys will be of format foo, foo-1, foo-2 .. | ||
cookies, err = MakeCookieMetadata("foo", strings.Repeat("_", (maxCookieLength-5)*maxCookieNumber)) | ||
assert.EqualError(t, err, "invalid cookie value, at 20440 long it is longer than the max length of 20435") | ||
assert.Equal(t, 0, len(cookies)) | ||
} | ||
|
||
cookie, err := MakeCookieMetadata("foo", "bar") | ||
func TestSplitCookie(t *testing.T) { | ||
cookieValue := strings.Repeat("_", (maxCookieLength-6)*4) | ||
cookies, err := MakeCookieMetadata("foo", cookieValue) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "foo=bar", cookie) | ||
assert.Equal(t, 4, len(cookies)) | ||
assert.Equal(t, 2, len(strings.Split(cookies[0], "="))) | ||
token := strings.Split(cookies[0], "=")[1] | ||
assert.Equal(t, 2, len(strings.Split(token, ":"))) | ||
assert.Equal(t, "4", strings.Split(token, ":")[0]) | ||
|
||
cookie, err = MakeCookieMetadata("foo", strings.Repeat("_", 4093-3)) | ||
assert.EqualError(t, err, "invalid cookie, at 4094 long it is longer than the max length of 4093") | ||
assert.Equal(t, "", cookie) | ||
cookies = append(cookies, "bar=this-entry-should-be-filtered") | ||
var cookieList []*http.Cookie | ||
for _, cookie := range cookies { | ||
parts := strings.Split(cookie, "=") | ||
cookieList = append(cookieList, &http.Cookie{Name: parts[0], Value: parts[1]}) | ||
} | ||
token, err = JoinCookies("foo", cookieList) | ||
assert.NoError(t, err) | ||
assert.Equal(t, cookieValue, token) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters