@@ -54,59 +54,55 @@ func Test_copyCookie(t *testing.T) {
5454}
5555
5656func Test_splitCookie(t *testing.T) {
57− testCases := map[string]struct {
58− Cookie *http.Cookie
59− ExpectedSizes []int
60− }{
57+ testCases := map[string]*http.Cookie{
6158 "Short cookie name": {
62− Cookie: &http.Cookie{
63− Name: "short",
64− Value: strings.Repeat("v", 10000),
65− },
66− ExpectedSizes: []int{4089, 4089, 1822},
59+ Name: "short",
60+ Value: strings.Repeat("v", 10000),
6761 },
6862 "Long cookie name": {
69− Cookie: &http.Cookie{
70− Name: strings.Repeat("n", 251),
71− Value: strings.Repeat("a", 10000),
72− },
73− ExpectedSizes: []int{3843, 3843, 2314},
63+ Name: strings.Repeat("n", 251),
64+ Value: strings.Repeat("a", 10000),
7465 },
7566 "Max cookie name": {
76− Cookie: &http.Cookie{
77− Name: strings.Repeat("n", 256),
78− Value: strings.Repeat("a", 10000),
79− },
80− ExpectedSizes: []int{3840, 3840, 2320},
67+ Name: strings.Repeat("n", 256),
68+ Value: strings.Repeat("a", 10000),
8169 },
8270 "Suffix overflow cookie name": {
83− Cookie: &http.Cookie{
84− Name: strings.Repeat("n", 255),
85− Value: strings.Repeat("a", 10000),
86− },
87− ExpectedSizes: []int{3840, 3840, 2320},
71+ Name: strings.Repeat("n", 255),
72+ Value: strings.Repeat("a", 10000),
73+ },
74+ "Double digit suffix cookie name overflow": {
75+ Name: strings.Repeat("n", 253),
76+ Value: strings.Repeat("a", 50000),
8877 },
89− "Double digit suffix cookie name results in different sizes": {
90− Cookie: &http.Cookie{
91− Name: strings.Repeat("n", 253),
92− Value: strings.Repeat("a", 50000),
93− },
94− ExpectedSizes: []int{3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841, 3841,
95− 3840, 3840, 3840, 70},
78+ "With short name and attributes": {
79+ Name: "short",
80+ Value: strings.Repeat("v", 10000),
81+ Path: "/path",
82+ Domain: "x.y.z",
83+ Secure: true,
84+ HttpOnly: true,
85+ SameSite: http.SameSiteLaxMode,
9686 },
97− "Double digit suffix overflow cookie name results in same sizes": {
98− Cookie: &http.Cookie{
99− Name: strings.Repeat("n", 254),
100− Value: strings.Repeat("a", 50000),
101− },
102− ExpectedSizes: []int{3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840, 3840,
103− 3840, 3840, 3840, 80},
87+ "With max length name and attributes": {
88+ Name: strings.Repeat("n", 256),
89+ Value: strings.Repeat("v", 10000),
90+ Path: "/path",
91+ Domain: "x.y.z",
92+ Secure: true,
93+ HttpOnly: true,
94+ SameSite: http.SameSiteLaxMode,
10495 },
10596 }
10697 for testName, tc := range testCases {
10798 t.Run(testName, func(t *testing.T) {
108− for i, cookie := range splitCookie(tc.Cookie) {
109− assert.Equal(t, tc.ExpectedSizes[i], len(cookie.Value))
99+ splitCookies := splitCookie(tc)
100+ for i, cookie := range splitCookies {
101+ if i < len(splitCookies)-1 {
102+ assert.Equal(t, 4000, len(cookie.String()))
103+ } else {
104+ assert.GreaterOrEqual(t, 4000, len(cookie.String()))
105+ }
110106 }
111107 })
112108 }