mirror of
https://github.com/volatiletech/authboss.git
synced 2024-12-10 10:40:07 +02:00
f12f10fa43
- This change was necessary because multi-tenancy sites could not use authboss properly.
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package authboss
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
type testClientStorerErr string
|
|
|
|
func (t testClientStorerErr) Put(key, value string) {}
|
|
func (t testClientStorerErr) Get(key string) (string, bool) {
|
|
return string(t), key == string(t)
|
|
}
|
|
func (t testClientStorerErr) Del(key string) {}
|
|
|
|
func TestClientStorerErr(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var cs testClientStorerErr
|
|
|
|
csw := clientStoreWrapper{&cs}
|
|
if _, err := csw.GetErr("hello"); err == nil {
|
|
t.Error("Expected an error")
|
|
}
|
|
|
|
cs = "hello"
|
|
if str, err := csw.GetErr("hello"); err != nil {
|
|
t.Error(err)
|
|
} else if str != "hello" {
|
|
t.Error("Wrong value:", str)
|
|
}
|
|
}
|
|
|
|
func TestFlashClearer(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
session := mockClientStore{FlashSuccessKey: "success", FlashErrorKey: "error"}
|
|
ab := New()
|
|
ab.SessionStoreMaker = func(w http.ResponseWriter, r *http.Request) ClientStorer {
|
|
return session
|
|
}
|
|
|
|
if msg := ab.FlashSuccess(nil, nil); msg != "success" {
|
|
t.Error("Unexpected flash success:", msg)
|
|
}
|
|
if msg, ok := session.Get(FlashSuccessKey); ok {
|
|
t.Error("Unexpected success flash:", msg)
|
|
}
|
|
|
|
if msg := ab.FlashError(nil, nil); msg != "error" {
|
|
t.Error("Unexpected flash error:", msg)
|
|
}
|
|
if msg, ok := session.Get(FlashErrorKey); ok {
|
|
t.Error("Unexpected error flash:", msg)
|
|
}
|
|
|
|
}
|