mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 13:52:19 +00:00
Add more testing in auth package
This commit is contained in:
parent
87d2992bdf
commit
34e1e22bf1
@ -8,24 +8,32 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadConfiguration(t *testing.T) {
|
func TestLoadConfiguration(t *testing.T) {
|
||||||
|
// Test to create a basic authentification backend
|
||||||
_, err := New(&Options{
|
_, err := New(&Options{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Backend: "basic",
|
Backend: "basic",
|
||||||
Basic: basic.Options{Credentials: make(map[string]string)},
|
Basic: basic.Options{Credentials: make(map[string]string)},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Creating basic authentication backend failed:", err)
|
t.Error("Creating basic authentication backend failed:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test to create a LDAP authentification backend
|
||||||
|
// FIXME Should fail as there is no LDAP server
|
||||||
_, err = New(&Options{
|
_, err = New(&Options{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Backend: "ldap",
|
Backend: "ldap",
|
||||||
LDAP: ldap.Options{URI: "ldap://127.0.0.1:389", UserDn: "cn=users,dc=example,dc=com"},
|
LDAP: ldap.Options{URI: "ldap://127.0.0.1:389", UserDn: "cn=users,dc=example,dc=com"},
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO Maybe start a LDAP server?
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Creating ldap authentication backend successed mysteriously:", err)
|
t.Error("Creating ldap authentication backend successed mysteriously:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test to bypass authentification backend
|
||||||
|
backend, err := New(&Options{
|
||||||
|
Enabled: false,
|
||||||
|
})
|
||||||
|
if backend != nil {
|
||||||
|
t.Error("Failed to bypass authentication backend:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,18 @@ func TestBasicLogin(t *testing.T) {
|
|||||||
basicCredentials := make(map[string]string)
|
basicCredentials := make(map[string]string)
|
||||||
basicCredentials["demo"] = "$2b$15$LRnG3eIHFlYIguTxZOLH7eHwbQC/vqjnLq6nDFiHSUDKIU.f5/1H6"
|
basicCredentials["demo"] = "$2b$15$LRnG3eIHFlYIguTxZOLH7eHwbQC/vqjnLq6nDFiHSUDKIU.f5/1H6"
|
||||||
|
|
||||||
|
// Test good credentials
|
||||||
backend, _ := New(&Options{Credentials: basicCredentials})
|
backend, _ := New(&Options{Credentials: basicCredentials})
|
||||||
ok, err := backend.Login("demo", "demo")
|
ok, err := backend.Login("demo", "demo")
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Error("Error while logging with the basic authentication:", err)
|
t.Error("Error while logging with the basic authentication:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test bad credentials
|
||||||
|
ok, err = backend.Login("demo", "badpass")
|
||||||
|
if ok {
|
||||||
|
t.Error("Authentification failed to fail:", err)
|
||||||
|
}
|
||||||
|
|
||||||
backend.Close()
|
backend.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user