@@ -1,6 +1,7 @@
11package validation
22
33import (
4+ "strings"
45 "testing"
56 "time"
67
@@ -9,8 +10,12 @@ import (
910)
1011
1112func TestValidateCookie(t *testing.T) {
13+ alphabet := "abcdefghijklmnopqrstuvwxyz"
14+
1215 validName := "_oauth2_proxy"
1316 invalidName := "_oauth2;proxy" // Separater character not allowed
17+ // 10 times the alphabet should be longer than 256 characters
18+ longName := strings.Repeat(alphabet, 10)
1419 validSecret := "secretthirtytwobytes+abcdefghijk"
1520 invalidSecret := "abcdef" // 6 bytes is not a valid size
1621 validBase64Secret := "c2VjcmV0dGhpcnR5dHdvYnl0ZXMrYWJjZGVmZ2hpams" // Base64 encoding of "secretthirtytwobytes+abcdefghijk"
@@ -25,6 +30,7 @@ func TestValidateCookie(t *testing.T) {
2530 }
2631
2732 invalidNameMsg := "invalid cookie name: \"_oauth2;proxy\""
33+ longNameMsg := "cookie name should be under 256 characters: cookie name is 260 characters"
2834 missingSecretMsg := "missing setting: cookie-secret"
2935 invalidSecretMsg := "cookie_secret must be 16, 24, or 32 bytes to create an AES cipher, but is 6 bytes"
3036 invalidBase64SecretMsg := "cookie_secret must be 16, 24, or 32 bytes to create an AES cipher, but is 10 bytes"
@@ -134,6 +140,23 @@ func TestValidateCookie(t *testing.T) {
134140 invalidNameMsg,
135141 },
136142 },
143+ {
144+ name: "with a name that is too long",
145+ cookie: options.Cookie{
146+ Name: longName,
147+ Secret: validSecret,
148+ Domains: emptyDomains,
149+ Path: "",
150+ Expire: time.Hour,
151+ Refresh: 15 * time.Minute,
152+ Secure: true,
153+ HTTPOnly: false,
154+ SameSite: "",
155+ },
156+ errStrings: []string{
157+ longNameMsg,
158+ },
159+ },
137160 {
138161 name: "with refresh longer than expire",
139162 cookie: options.Cookie{