Beispiel #1
0
// testManagerDeleteUser check if delete user operation work.
func testManagerDeleteUser(t *testing.T, mngr authmodel.Manager, uid string) {
	err := mngr.DeleteUser(uid)
	if err != nil {
		t.Fatal("delete user failed:", err)
	}

	_, err = mngr.FindUser(uid)
	if err != authmodel.ErrNotFound {
		t.Fatal("delete user not work")
	}
}
Beispiel #2
0
// testManagerDeleteGroup recieve a group id and a user id who belong to that group.
// After group delettion, check if the group infomation of in user account removed or not.
func testManagerDeleteGroup(t *testing.T, mngr authmodel.Manager, gid, uid string) {
	err := mngr.DeleteGroup(gid)
	if err != nil {
		t.Fatal("delete group failed:", err)
	}

	u, err := mngr.FindUser(uid)
	if err != nil {
		t.Fatal("cannot find user:"******"delete group must remove group info in user")
	}
}
Beispiel #3
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)
	}
}
Beispiel #4
0
// testManagerAddUserDetail check if add user operation work
func testManagerAddUserDetail(t *testing.T, mngr authmodel.Manager, gid string) string {
	code := map[string]string{"tested": "notyet"}
	u, err := mngr.AddUserDetail("*****@*****.**", "test123edc", true, []string{"testing"}, code, nil, []string{gid})
	if err != nil {
		t.Fatal("cannot update user detail:", err)
	}

	u, err = mngr.FindUser(*u.Id)
	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")
	}

	return *u.Id
}