ghostream/auth/auth_test.go

49 lines
1.2 KiB
Go
Raw Normal View History

package auth
2020-10-01 18:11:43 +00:00
import (
2020-10-09 20:17:07 +00:00
"testing"
2020-10-01 18:11:43 +00:00
"gitlab.crans.org/nounous/ghostream/auth/basic"
"gitlab.crans.org/nounous/ghostream/auth/ldap"
)
func TestLoadConfiguration(t *testing.T) {
2020-10-09 20:42:09 +00:00
// Test to create a basic authentification backend
2020-10-09 20:17:07 +00:00
_, err := New(&Options{
Enabled: true,
Backend: "basic",
Basic: basic.Options{Credentials: make(map[string]string)},
})
2020-10-01 18:11:43 +00:00
if err != nil {
2020-10-09 21:08:50 +00:00
t.Errorf("Creating basic authentication backend failed: %s", err)
2020-10-01 18:11:43 +00:00
}
2020-10-09 20:42:09 +00:00
// Test to create a LDAP authentification backend
// FIXME Should fail as there is no LDAP server
2020-10-09 20:17:07 +00:00
_, err = New(&Options{
Enabled: true,
Backend: "ldap",
LDAP: ldap.Options{URI: "ldap://127.0.0.1:389", UserDn: "cn=users,dc=example,dc=com"},
})
2020-10-01 18:11:43 +00:00
if err == nil {
2020-10-09 21:08:50 +00:00
t.Errorf("Creating ldap authentication backend successed mysteriously: %s", err)
2020-10-01 18:11:43 +00:00
}
2020-10-09 20:42:09 +00:00
// Test to bypass authentification backend
backend, err := New(&Options{
Enabled: false,
})
if backend != nil {
2020-10-09 21:08:50 +00:00
t.Errorf("Failed to bypass authentication backend: %s", err)
}
// Test bad authentification backend
_, err = New(&Options{
Enabled: true,
Backend: "idonotexist",
})
if err == nil {
t.Error("Failed to fail authentication backend init:")
2020-10-09 20:42:09 +00:00
}
2020-10-01 18:11:43 +00:00
}