Nuestro burocrata preferido: Sam Lowry https://lowry.sindominio.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
lowry/ldap/user_test.go

89 lines
1.8 KiB

package ldap
import "testing"
const (
user = "user"
userPass = "foobar"
newPass = "newpass"
)
func TestValidate(t *testing.T) {
l := testLdap()
err := l.ValidateUser(user, userPass)
if err != nil {
t.Errorf("Error on ValidateUser(): %v", err)
}
}
func TestValidateFails(t *testing.T) {
l := testLdap()
err := l.ValidateUser(user, userPass+"bar")
if err == nil {
t.Errorf("ValidateUser() didn't fail to auth the user")
}
}
func TestChangePass(t *testing.T) {
l := testLdap()
err := l.ChangePass(user, userPass, newPass)
if err != nil {
t.Errorf("Error on ChangePass(): %v", err)
}
err = l.ValidateUser(user, newPass)
if err != nil {
t.Errorf("Error on ValidateUser(): %v", err)
}
err = l.ChangePass(user, newPass, userPass)
if err != nil {
t.Errorf("Error on the second ChangePass(): %v", err)
}
}
func TestChangePassRO(t *testing.T) {
l := testLdap()
l.RO = true
err := l.ChangePass(user, userPass, newPass)
if err != nil {
t.Errorf("Error on ChangePass(): %v", err)
}
err = l.ValidateUser(user, newPass)
if err == nil {
t.Errorf("ValidateUser() didn't fail to auth the user")
}
}
func TestListUsers(t *testing.T) {
l := testLdap()
userCount := 0
users, err := l.ListUsers()
if err != nil {
t.Errorf("ListUsers() failed: %v", err)
}
for _, user := range users {
if user.Name == "user" {
userCount++
if user.UID != 1000 {
t.Errorf("Expected 1000 found: %v", user.UID)
}
if user.Shell != "/bin/bash" {
t.Errorf("Expected /bin/bash found: %v", user.Shell)
}
}
if user.Name == "superuser" {
userCount++
if user.UID != 1001 {
t.Errorf("Expected 1001 found: %v", user.UID)
}
if user.Shell != "/bin/bash" {
t.Errorf("Expected /bin/bash found: %v", user.Shell)
}
}
}
if userCount != 2 {
t.Errorf("Not the righ number of users: %v", users)
}
}