// Copyright (C) 2019 Marius Schellenberger

package server

import (
	"testing"
)

func TestXsrf(t *testing.T) {
	sec := genKey(keySize)
	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")
	}
}
