예제 #1
0
func TestSessionClearAll(t *testing.T) {
	m := map[interface{}]interface{}{1: 2, 3: 4}
	s := session_util.UserIdSession{&sessions.Session{Values: m}}
	if len(m) != 2 {
		t.Fatal("Expected 2 things in map")
	}
	s.ClearAll()
	if len(m) != 0 {
		t.Error("Expected map to be empty")
	}
}
예제 #2
0
func TestXsrfTokenClearAll(t *testing.T) {
	s := session_util.UserIdSession{&sessions.Session{Values: make(map[interface{}]interface{})}}
	s.SetUserId(kUserId)
	xsrfToken := s.NewXsrfToken("MyPage", kNow.Add(15*time.Minute))
	if !s.VerifyXsrfToken(xsrfToken, "MyPage", kNow) {
		t.Error("Expected token to verify")
	}
	s.ClearAll()
	if s.VerifyXsrfToken(xsrfToken, "MyPage", kNow) {
		t.Error("Expected token not to verify. Session cleared")
	}
	s.SetUserId(kUserId)
	if s.VerifyXsrfToken(xsrfToken, "MyPage", kNow) {
		t.Error("Expected token not to verify. Secret should have changed.")
	}
}