-
Notifications
You must be signed in to change notification settings - Fork 12
enforce qualified user group #519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| Terminology: | ||
|
|
||
| - **qualified user**: a user who is currently a PI or a member of at least one PI group | ||
| - **unqualified user**: inverse of qualified | ||
| - **native user**: a user created by this account portal | ||
| - **non-native user**: inverse of native | ||
| - users created for administrative purposes should not be mixed with native users in the LDAP OUs given in `config.ini` or else this account portal may get confused |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
|
|
||
| use PHPUnit\Framework\Attributes\DataProvider; | ||
| use TRegx\PhpUnit\DataProviders\DataProvider as TRegxDataProvider; | ||
|
|
||
| class FoobarTest extends UnityWebPortalTestCase | ||
| { | ||
| public static function provider(): TRegxDataProvider | ||
| { | ||
| return TRegxDataProvider::list("foo", "bar"); | ||
| } | ||
|
|
||
| #[DataProvider("provider")] | ||
| public function testFoobar(string $x) | ||
| { | ||
| $this->assertTrue(true); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <?php | ||
| use UnityWebPortal\lib\UnityUser; | ||
| use UnityWebPortal\lib\UserFlag; | ||
| use UnityWebPortal\lib\UnityGroup; | ||
|
|
||
| class LeaveGroupTest extends UnityWebPortalTestCase | ||
| { | ||
| public function testLeaveGroupDisqualified() | ||
| { | ||
| global $USER, $LDAP, $SQL, $MAILER, $WEBHOOK; | ||
| $this->switchUser("Normal"); | ||
| $pi_gids = $USER->getPIGroupGIDs(); | ||
| $this->assertEquals(1, count($pi_gids)); | ||
| $gid = $pi_gids[0]; | ||
| $pi_group = new UnityGroup($gid, $LDAP, $SQL, $MAILER, $WEBHOOK); | ||
| $this->assertTrue($pi_group->memberUIDExists($USER->uid)); | ||
| $this->assertTrue($USER->getFlag(UserFlag::QUALIFIED)); | ||
| try { | ||
| http_post(__DIR__ . "/../../webroot/panel/groups.php", [ | ||
| "form_type" => "removePIForm", | ||
| "pi" => $gid, | ||
| ]); | ||
| $this->assertFalse($pi_group->memberUIDExists($USER->uid)); | ||
| $this->assertFalse($USER->getFlag(UserFlag::QUALIFIED)); | ||
| } finally { | ||
| if (!$pi_group->memberUIDExists($USER->uid)) { | ||
| $pi_group->newUserRequest($USER); | ||
| $pi_group->approveUser($USER); | ||
| } | ||
| $this->assertTrue($pi_group->memberUIDExists($USER->uid)); | ||
| $this->assertTrue($USER->getFlag(UserFlag::QUALIFIED)); | ||
| } | ||
| } | ||
|
|
||
| // if an admin goes messing around with LDAP entries by hand and also forgets to update the | ||
| // qualified users group, the portal should update the user's qualified status the next time | ||
| // they log in | ||
| public function testRemovedFromGroupManuallyDisqualifiedOnLogin() | ||
| { | ||
| global $USER, $LDAP, $SQL, $MAILER, $WEBHOOK; | ||
| $this->switchUser("Normal"); | ||
| $pi_gids = $USER->getPIGroupGIDs(); | ||
| $this->assertEquals(1, count($pi_gids)); | ||
| $gid = $pi_gids[0]; | ||
| $pi_group = new UnityGroup($gid, $LDAP, $SQL, $MAILER, $WEBHOOK); | ||
| $this->assertTrue($pi_group->memberUIDExists($USER->uid)); | ||
| $this->assertTrue($USER->getFlag(UserFlag::QUALIFIED)); | ||
| try { | ||
| $old_memberuids = $pi_group->getMemberUIDs(); | ||
| $new_memberuids = array_values( | ||
| array_filter($old_memberuids, fn($x) => $x !== $USER->uid), | ||
| ); | ||
| $pi_group_entry = $LDAP->getPIGroupEntry($pi_group->gid); | ||
| $pi_group_entry->setAttribute("memberuid", $new_memberuids); | ||
| $this->assertTrue($USER->getFlag(UserFlag::QUALIFIED)); | ||
| session_write_close(); | ||
| http_get(__DIR__ . "/../../resources/init.php"); | ||
| $this->assertFalse($USER->getFlag(UserFlag::QUALIFIED)); | ||
| } finally { | ||
| if (!$pi_group->memberUIDExists($USER->uid)) { | ||
| $pi_group->newUserRequest($USER); | ||
| $pi_group->approveUser($USER); | ||
| } | ||
| $this->assertTrue($pi_group->memberUIDExists($USER->uid)); | ||
| $this->assertTrue($USER->getFlag(UserFlag::QUALIFIED)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| use UnityWebPortal\lib\UserFlag; | ||
|
|
||
| class WorkerUpdateQualifiedUsersGroupTest extends UnityWebPortalTestCase | ||
| { | ||
| public function testQualifyUser() | ||
| { | ||
| global $USER, $LDAP, $SQL, $MAILER, $WEBHOOK; | ||
| $this->switchUser("EmptyPIGroupOwner"); | ||
| $pi_group = $USER->getPIGroup(); | ||
| $this->switchUser("Blank"); | ||
| $user = $USER; | ||
| $expectedOutput = ["added" => [$user->uid], "removed" => []]; | ||
| try { | ||
| $pi_group_entry = $LDAP->getPIGroupEntry($pi_group->gid); | ||
| $pi_group_entry->appendAttribute("memberuid", $user->uid); | ||
| [$_, $output_lines] = executeWorker("update-qualified-users-group.php"); | ||
| $output_str = implode("\n", $output_lines); | ||
| $output = jsonDecode($output_str, associative: true); | ||
| $this->assertEquals($expectedOutput, $output); | ||
simonLeary42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // refresh LDAP to pick up changes from subprocess | ||
| unset($GLOBALS["ldapconn"]); | ||
| $this->switchUser("Blank", validate: false); | ||
| $user = $USER; | ||
| $this->assertTrue($user->getFlag(UserFlag::QUALIFIED)); | ||
| } finally { | ||
| if ($pi_group->memberUIDExists($user->uid)) { | ||
| $pi_group->removeUser($user); | ||
| } | ||
| $this->assertFalse($user->getFlag(UserFlag::QUALIFIED)); | ||
| } | ||
| } | ||
|
|
||
| public function testDisqualifyUser() | ||
| { | ||
| global $USER, $LDAP, $SQL, $MAILER, $WEBHOOK; | ||
| $this->switchUser("Blank"); | ||
| $expectedOutput = ["added" => [], "removed" => [$USER->uid]]; | ||
| try { | ||
| $qualified_user_group = $LDAP->userFlagGroups["qualified"]; | ||
| $qualified_user_group->addMemberUID($USER->uid); | ||
| [$_, $output_lines] = executeWorker("update-qualified-users-group.php"); | ||
| $output_str = implode("\n", $output_lines); | ||
| $output = jsonDecode($output_str, associative: true); | ||
| $this->assertEquals($expectedOutput, $output); | ||
simonLeary42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // refresh LDAP to pick up changes from subprocess | ||
| unset($GLOBALS["ldapconn"]); | ||
| $this->switchUser("Blank", validate: false); | ||
| $this->assertFalse($USER->getFlag(UserFlag::QUALIFIED)); | ||
| } finally { | ||
| if ($USER->getFlag(UserFlag::QUALIFIED)) { | ||
| $USER->setFlag(UserFlag::QUALIFIED, false); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.