34 lines
552 B
Go
34 lines
552 B
Go
// Copyright (C) 2022 Marius Schellenberger
|
|
|
|
package server
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestXsrf(t *testing.T) {
|
|
sec, err := genKey(keySize)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(sec) != keySize {
|
|
t.Fatal("len(sec) != keySize")
|
|
}
|
|
xsrf := newXsrf(sec)
|
|
if xsrf == "" {
|
|
t.Fatal("xsrf is empty")
|
|
}
|
|
|
|
if !checkXsrf(xsrf, sec) {
|
|
t.Fatal("valid xsrf check failed")
|
|
}
|
|
|
|
if checkXsrf("test", sec) {
|
|
t.Fatal("invalid xsrf check succeeded")
|
|
}
|
|
|
|
rnd := genKey(keySize)
|
|
if checkXsrf(xsrf, rnd) {
|
|
t.Fatal("invalid xsrf check succeeded")
|
|
}
|
|
}
|