-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsession_fuzz_test.go
More file actions
38 lines (31 loc) · 873 Bytes
/
session_fuzz_test.go
File metadata and controls
38 lines (31 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//go:build go1.18
// +build go1.18
package mars
//go
import (
"fmt"
"net/http"
"testing"
)
func makeCookie(args Args) string {
session := make(Session)
session.SetDefaultExpiration()
for k, v := range args {
session[k] = fmt.Sprint(v)
}
return session.Cookie().Value
}
func FuzzSessionDecoding(f *testing.F) {
secretKey = generateRandomSecretKey()
f.Add(makeCookie(Args{"username": "roblillack"}))
f.Add(makeCookie(Args{"username": "roblillack", "lang": "de"}))
f.Add(makeCookie(Args{"username": "roblillack", "lang": "de", "orientation": "portrait"}))
f.Add(makeCookie(Args{"username": "roblillack", "bw": true}))
f.Add(makeCookie(Args{"no": 28963473, "bw": true}))
f.Fuzz(func(t *testing.T, cookieContent string) {
cookie := &http.Cookie{Value: cookieContent}
if session := GetSessionFromCookie(cookie); session == nil {
t.Fail()
}
})
}