-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathauthenticate_user_test.go
52 lines (46 loc) · 1.13 KB
/
authenticate_user_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package pkg
import (
"testing"
pb "github.com/romnn/ldap-manager/pkg/grpc/gen"
)
// TestAuthenticateUser tests authenticating as a user
func TestAuthenticateUser(t *testing.T) {
test := new(Test).Start(t).Setup(t)
defer test.Teardown()
// create new user
username := "Test User"
password := "secret password"
req := &pb.NewUserRequest{
Username: username,
Password: password,
Email: "a@b.de",
FirstName: "roman",
LastName: "d",
}
if err := test.Manager.NewUser(req); err != nil {
t.Fatalf(
"failed to add user %q: %v",
username, err,
)
}
// check that authenticating the user using wrong password fails
if _, err := test.Manager.AuthenticateUser(&pb.LoginRequest{
Username: username,
Password: "wrong",
}); err == nil {
t.Fatalf(
"authenticating user %q with wrong password succeeded",
username,
)
}
// check if we can authenticate the user using correct password
if _, err := test.Manager.AuthenticateUser(&pb.LoginRequest{
Username: username,
Password: password,
}); err != nil {
t.Fatalf(
"cannot authenticate user %q with password %q: %v",
username, password, err,
)
}
}