Skip to content

Commit 177377e

Browse files
committed
add test for creating multiple users
1 parent a51489d commit 177377e

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

test/functional/NewUserTest.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ private function ensureUserDoesNotExist()
112112
}
113113
$all_users_group = $LDAP->getUserGroup();
114114
$all_member_uids = $all_users_group->getAttribute("memberuid");
115-
$new_uids = array_diff($all_member_uids, [$USER->uid]);
116115
if (in_array($USER->uid, $all_member_uids)) {
117116
$all_users_group->setAttribute(
118117
"memberuid",
119-
array_diff($all_member_uids, [$USER->uid])
118+
// array_diff will break the contiguity of the array indexes
119+
// ldap_mod_replace requires contiguity, array_values restores contiguity
120+
array_values(array_diff($all_member_uids, [$USER->uid]))
120121
);
121122
$all_users_group->write();
122123
assert(!in_array($USER->uid, $all_users_group->getAttribute("memberuid")));
@@ -221,6 +222,41 @@ public function testCreateUserByJoinGoupByPI()
221222
}
222223
}
223224

225+
public function testCreateMultipleUsersByJoinGoupByPI()
226+
{
227+
global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK;
228+
$pi_user_args = getUserIsPIHasNoMembersNoMemberRequests();
229+
switchUser(...$pi_user_args);
230+
$pi_group = $USER->getPIGroup();
231+
$gid = $pi_group->gid;
232+
$this->assertTrue($pi_group->exists());
233+
$users_to_create_args = getNonexistentUsersWithExistentOrg();
234+
try {
235+
foreach ($users_to_create_args as $user_to_create_args) {
236+
switchUser(...$user_to_create_args);
237+
$this->assertTrue(!$USER->exists());
238+
$this->assertTrue(!$pi_group->userExists($USER));
239+
$this->assertRequestedMembership(false, $gid);
240+
$this->requestGroupMembership($pi_group->gid);
241+
$this->assertRequestedMembership(true, $gid);
242+
$approve_uid = $USER->uid;
243+
switchUser(...$pi_user_args);
244+
// $this->assertTrue(!$pi_group->userExists($USER));
245+
$this->approveUserByPI($approve_uid);
246+
switchUser(...$user_to_create_args);
247+
$this->assertTrue(!$pi_group->requestExists($USER));
248+
$this->assertRequestedMembership(false, $gid);
249+
$this->assertTrue($pi_group->userExists($USER));
250+
$this->assertTrue($USER->exists());
251+
}
252+
} finally {
253+
foreach ($users_to_create_args as $user_to_create_args) {
254+
switchUser(...$user_to_create_args);
255+
$this->ensureUserNotInPIGroup($pi_group);
256+
$this->ensureUserDoesNotExist();
257+
}
258+
}
259+
}
224260

225261
public function testCreateUserByJoinGoupByAdmin()
226262
{

test/phpunit-bootstrap.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ function getNonExistentUser()
177177
return ["user2001@org998.test", "foo", "bar", "user2001@org998.test"];
178178
}
179179

180+
function getNonexistentUsersWithExistentOrg()
181+
{
182+
return [
183+
["user2003@org1.test", "foo", "bar", "user2003@org1.test"],
184+
["user2004@org1.test", "foo", "bar", "user2004@org1.test"],
185+
];
186+
}
187+
180188
function getAdminUser()
181189
{
182190
return ["user1@org1.test", "foo", "bar", "user1@org1.test"];

tools/docker-dev/web/htpasswd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,10 @@ user1304@org1.test:$apr1$Rgrex74Z$rgJx6sCnGQN9UVMmhVG2R1
13021302
user1313@org1.test:$apr1$Rgrex74Z$rgJx6sCnGQN9UVMmhVG2R1
13031303
user1322@org14.test:$apr1$Rgrex74Z$rgJx6sCnGQN9UVMmhVG2R1
13041304
user1326@org14.test:$apr1$Rgrex74Z$rgJx6sCnGQN9UVMmhVG2R1
1305+
# nonexistent users
13051306
user2000@org2.test:$apr1$Rgrex74Z$rgJx6sCnGQN9UVMmhVG2R1
13061307
user2001@org998.test:$apr1$Rgrex74Z$rgJx6sCnGQN9UVMmhVG2R1
13071308
user2002@org999.test:$apr1$Rgrex74Z$rgJx6sCnGQN9UVMmhVG2R1
1309+
# nonexistent users with an existent org
1310+
user2003@org1.test:$apr1$Rgrex74Z$rgJx6sCnGQN9UVMmhVG2R1
1311+
user2004@org1.test:$apr1$Rgrex74Z$rgJx6sCnGQN9UVMmhVG2R1

0 commit comments

Comments
 (0)