ghostream/auth/basic/basic_test.go

32 lines
710 B
Go
Raw Normal View History

package basic
2020-10-01 18:11:43 +00:00
import (
"testing"
)
func TestBasicLogin(t *testing.T) {
basicCredentials := make(map[string]string)
basicCredentials["demo"] = "$2b$10$xuU7XFwmRX2CMgdSaA8rM.4Y8.BtRNzhUedwN0G8tCegDRNUERTCS"
2020-10-01 18:11:43 +00:00
2020-10-09 20:42:09 +00:00
// Test good credentials
2020-10-01 18:11:43 +00:00
backend, _ := New(&Options{Credentials: basicCredentials})
2021-02-25 16:38:09 +00:00
ok, _, err := backend.Login("demo", "demo")
2020-10-01 18:11:43 +00:00
if !ok {
t.Error("Error while logging with the basic authentication:", err)
}
2020-10-09 20:42:09 +00:00
// Test bad username
2021-02-25 16:38:09 +00:00
ok, _, err = backend.Login("baduser", "demo")
if ok {
t.Error("Authentification failed to fail:", err)
}
// Test bad password
2021-02-25 16:38:09 +00:00
ok, _, err = backend.Login("demo", "badpass")
2020-10-09 20:42:09 +00:00
if ok {
t.Error("Authentification failed to fail:", err)
}
2020-10-01 18:11:43 +00:00
backend.Close()
}