Пример #1
0
func TestSessionUserId(t *testing.T) {
	s := session_util.UserIdSession{&sessions.Session{Values: make(map[interface{}]interface{})}}
	s.SetUserId(kUserId)
	s.SetLastLogin(kNow)
	id, ok := s.UserId()
	if !ok {
		t.Error("Expected a UserId")
	}
	if id != kUserId {
		t.Errorf("Expected %d, got %d", kUserId, id)
	}

	s.ClearUserId()
	id, ok = s.UserId()
	if ok {
		t.Error("Did not expect a user Id.")
	}

	lastLogin, ok := s.LastLogin()
	if !ok {
		t.Error("Expected a last login")
	}
	if lastLogin != kNow {
		t.Errorf("Expected %v, got %v", kNow, lastLogin)
	}

	s.ClearLastLogin()
	_, ok = s.LastLogin()
	if ok {
		t.Error("Did not expect a last login.")
	}

}
Пример #2
0
func TestXsrfTokenUserLogsOut(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.ClearUserId()
	if s.VerifyXsrfToken(xsrfToken, "MyPage", kNow) {
		t.Error("Expected token not to verify. User logged out.")
	}
	s.SetUserId(kUserId)
	if s.VerifyXsrfToken(xsrfToken, "MyPage", kNow) {
		t.Error("Expected token not to verify. Secret should have changed.")
	}
}