Ejemplo n.º 1
0
// testManagerUpdateUserDetail test update user operation and check the password hash function.
func testManagerUpdateUserDetail(t *testing.T, mngr authmodel.Manager, uid, gid string) {
	ps := "testing12345"
	app := false
	code := map[string]string{"tested": "notyet"}
	err := mngr.UpdateUserDetail(uid, &ps, &app, []string{"testing"}, code, nil, []string{gid})
	if err != nil {
		t.Fatal("cannot update user detail:", err)
	}

	u, err := mngr.FindUser(uid)
	if err != nil {
		t.Fatal("Cannot find user:"******"update user approved failed")
	}

	if len(u.Privileges) != 1 {
		t.Fatal("update user privileges failed")
	}

	if u.Privileges[0] != "testing" {
		t.Fatal("update user privileges failed")
	}

	if u.ConfirmCodes["tested"] != "notyet" {
		t.Fatal("update user confirm code failed")
	}

	if len(u.Groups) != 1 {
		t.Fatal("update user group failed")
	}

	if *u.Groups[0].Id != gid {
		t.Fatal("update user group failed")
	}

	err = mngr.ComparePassword(ps, u.Pwd)
	if err != nil {
		t.Fatal("password hash error:", err)
	}
}
Ejemplo n.º 2
0
// testManagerAddUser check if add user work
func testManagerAddUser(t *testing.T, mngr authmodel.Manager) string {
	ps := "zaq123456"
	u1, err := mngr.AddUser("*****@*****.**", ps, true)
	if err != nil {
		t.Fatal("cannot create new user:"******"must initial the LastActivity and JoinDay")
	}

	_, err = mngr.AddUser("*****@*****.**", ps, true)
	if err != authmodel.ErrDuplicateEmail {
		t.Fatal("must check for duplicate email:", err)
	}

	err = mngr.ComparePassword(ps, u1.Pwd)
	if err != nil {
		t.Fatal("password hash error:", err)
	}

	return *u1.Id
}