From 575579988d5cc246c2d06fc9338045b740e103ff Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Tue, 3 Jun 2025 13:28:59 -0400 Subject: [PATCH 01/11] PRG --- webroot/admin/content.php | 1 + webroot/admin/notices.php | 1 + webroot/admin/pi-mgmt.php | 1 + webroot/admin/user-mgmt.php | 1 + webroot/panel/account.php | 1 + webroot/panel/groups.php | 1 + webroot/panel/pi.php | 1 + 7 files changed, 7 insertions(+) diff --git a/webroot/admin/content.php b/webroot/admin/content.php index 2225c79a..3f1c5248 100644 --- a/webroot/admin/content.php +++ b/webroot/admin/content.php @@ -12,6 +12,7 @@ if (!empty($_POST["pageSel"])) { $SQL->editPage($_POST["pageSel"], $_POST["content"], $USER); } + UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; diff --git a/webroot/admin/notices.php b/webroot/admin/notices.php index 77e7e6e9..afdd940f 100644 --- a/webroot/admin/notices.php +++ b/webroot/admin/notices.php @@ -23,6 +23,7 @@ break; } + UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; diff --git a/webroot/admin/pi-mgmt.php b/webroot/admin/pi-mgmt.php index f5a2eb77..b1b399ef 100644 --- a/webroot/admin/pi-mgmt.php +++ b/webroot/admin/pi-mgmt.php @@ -50,6 +50,7 @@ break; } + UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; diff --git a/webroot/admin/user-mgmt.php b/webroot/admin/user-mgmt.php index 1568aa64..e3ad22a1 100644 --- a/webroot/admin/user-mgmt.php +++ b/webroot/admin/user-mgmt.php @@ -15,6 +15,7 @@ UnitySite::redirect($CONFIG["site"]["prefix"] . "/panel/account.php"); break; } + UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; diff --git a/webroot/panel/account.php b/webroot/panel/account.php index d074ed26..32e93383 100644 --- a/webroot/panel/account.php +++ b/webroot/panel/account.php @@ -72,6 +72,7 @@ } break; } + UnitySite::redirect($_SERVER['PHP_SELF']); } ?> diff --git a/webroot/panel/groups.php b/webroot/panel/groups.php index 8d982181..f9e54534 100644 --- a/webroot/panel/groups.php +++ b/webroot/panel/groups.php @@ -41,6 +41,7 @@ break; } } + UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; diff --git a/webroot/panel/pi.php b/webroot/panel/pi.php index 386a8ceb..9fb89547 100644 --- a/webroot/panel/pi.php +++ b/webroot/panel/pi.php @@ -31,6 +31,7 @@ break; } + UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; From 4c8160fa73a99d0325c477ea35d74edfc0dd552b Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Tue, 3 Jun 2025 13:38:49 -0400 Subject: [PATCH 02/11] add PRG into http_post function --- test/functional/CancelRequestTest.php | 48 +++++++++------------------ test/functional/ViewAsUserTest.php | 42 ++++++++++------------- test/phpunit-bootstrap.php | 4 +++ 3 files changed, 38 insertions(+), 56 deletions(-) diff --git a/test/functional/CancelRequestTest.php b/test/functional/CancelRequestTest.php index 36028d6e..8914f166 100644 --- a/test/functional/CancelRequestTest.php +++ b/test/functional/CancelRequestTest.php @@ -16,26 +16,18 @@ public function testCancelPIRequest() global $USER, $SQL; switchUser(...getNonExistentUser()); // First create a request - try { - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["new_user_sel" => "pi", "eula" => "agree", "confirm_pi" => "agree"] - ); - } catch (PhpUnitNoDieException $e) { - // Ignore the exception from http_post - } + http_post( + __DIR__ . "/../../webroot/panel/new_account.php", + ["new_user_sel" => "pi", "eula" => "agree", "confirm_pi" => "agree"] + ); $this->assertNumberGroupRequests(1); // Now try to cancel it - try { - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["cancel" => "true"] # value of cancel is arbitrary - ); - } catch (PhpUnitNoDieException $e) { - // Ignore the exception from http_post - } + http_post( + __DIR__ . "/../../webroot/panel/new_account.php", + ["cancel" => "true"] # value of cancel is arbitrary + ); $this->assertNumberGroupRequests(0); } @@ -45,26 +37,18 @@ public function testCancelGroupJoinRequest() global $USER, $SQL; switchUser(...getNonExistentUser()); - try { - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["new_user_sel" => "not_pi", "eula" => "agree", "pi" => getExistingPI()] - ); - } catch (PhpUnitNoDieException $e) { - // Ignore the exception from http_post - } + http_post( + __DIR__ . "/../../webroot/panel/new_account.php", + ["new_user_sel" => "not_pi", "eula" => "agree", "pi" => getExistingPI()] + ); $this->assertNumberGroupRequests(1); // Now try to cancel it - try { - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["cancel" => "true"] # value of cancel is arbitrary - ); - } catch (PhpUnitNoDieException $e) { - // Ignore the exception from http_post - } + http_post( + __DIR__ . "/../../webroot/panel/new_account.php", + ["cancel" => "true"] # value of cancel is arbitrary + ); $this->assertNumberGroupRequests(0); } diff --git a/test/functional/ViewAsUserTest.php b/test/functional/ViewAsUserTest.php index d38df358..4601c430 100644 --- a/test/functional/ViewAsUserTest.php +++ b/test/functional/ViewAsUserTest.php @@ -15,15 +15,13 @@ public function _testViewAsUser(array $beforeUser, array $afterUser) // $this->assertTrue($USER->isAdmin()); $beforeUid = $USER->getUID(); // $this->assertNotEquals($afterUid, $beforeUid); - try { - http_post( - __DIR__ . "/../../webroot/admin/user-mgmt.php", - [ - "form_name" => "viewAsUser", - "uid" => $afterUid, - ], - ); - } catch (PhpUnitNoDieException) {} + http_post( + __DIR__ . "/../../webroot/admin/user-mgmt.php", + [ + "form_name" => "viewAsUser", + "uid" => $afterUid, + ], + ); $this->assertArrayHasKey("viewUser", $_SESSION); // redirect means that php process dies and user's browser will initiate a new one // this makes `require_once autoload.php` run again and init.php changes $USER @@ -32,12 +30,10 @@ public function _testViewAsUser(array $beforeUser, array $afterUser) // now we should be new user $this->assertEquals($afterUid, $USER->getUID()); // $this->assertTrue($_SESSION["user_exists"]); - try { - http_post( - __DIR__ . "/../../resources/templates/header.php", - ["form_name" => "clearView"], - ); - } catch (PhpUnitNoDieException) {} + http_post( + __DIR__ . "/../../resources/templates/header.php", + ["form_name" => "clearView"], + ); $this->assertArrayNotHasKey("viewUser", $_SESSION); // redirect means that php process dies and user's browser will initiate a new one // this makes `require_once autoload.php` run again and init.php changes $USER @@ -69,15 +65,13 @@ public function testNonAdminViewAsAdmin() $adminUid = $USER->getUID(); $this->assertTrue($USER->isAdmin()); switchUser(...getNormalUser()); - try { - http_post( - __DIR__ . "/../../webroot/admin/user-mgmt.php", - [ - "form_name" => "viewAsUser", - "uid" => $adminUid, - ], - ); - } catch (PhpUnitNoDieException) {} + http_post( + __DIR__ . "/../../webroot/admin/user-mgmt.php", + [ + "form_name" => "viewAsUser", + "uid" => $adminUid, + ], + ); $this->assertArrayNotHasKey("viewUser", $_SESSION); } } diff --git a/test/phpunit-bootstrap.php b/test/phpunit-bootstrap.php index 1b95c51c..93522599 100644 --- a/test/phpunit-bootstrap.php +++ b/test/phpunit-bootstrap.php @@ -81,13 +81,17 @@ function http_post(string $phpfile, array $post_data): void $_SERVER["PHP_SELF"] = preg_replace("/.*webroot\//", "/", $phpfile); $_POST = $post_data; ob_start(); + $post_did_redirect = false; try { include $phpfile; + } catch (UnityWebPortal\lib\exceptions\PhpUnitNoDieException $e) { + $post_did_redirect = true; } finally { ob_get_clean(); // discard output unset($_POST); $_SERVER = $_PREVIOUS_SERVER; } + assert($post_did_redirect, "post did not redirect!"); } function http_get(string $phpfile, array $get_data = array()): void From 625076c2fb4a9599169bc526a5d79808557ac2ec Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Tue, 3 Jun 2025 16:00:53 -0400 Subject: [PATCH 03/11] let header handle redirect --- resources/templates/header.php | 20 ++++++++++++++------ webroot/admin/content.php | 1 - webroot/admin/notices.php | 1 - webroot/admin/pi-mgmt.php | 1 - webroot/admin/user-mgmt.php | 1 - webroot/index.php | 2 +- webroot/panel/account.php | 5 ++--- webroot/panel/groups.php | 1 - webroot/panel/new_account.php | 3 +-- webroot/panel/pi.php | 1 - webroot/panel/support.php | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/resources/templates/header.php b/resources/templates/header.php index 590f8943..caaca9ed 100644 --- a/resources/templates/header.php +++ b/resources/templates/header.php @@ -2,12 +2,20 @@ use UnityWebPortal\lib\UnitySite; -if ((@$_SESSION["is_admin"] ?? false) == true - && $_SERVER["REQUEST_METHOD"] == "POST" - && (@$_POST["form_name"] ?? null) == "clearView" -) { - unset($_SESSION["viewUser"]); - UnitySite::redirect($CONFIG["site"]["prefix"] . "/admin/user-mgmt.php"); +if (isset($_POST)) { + if ((@$_SESSION["is_admin"] ?? false) == true + && (@$_POST["form_name"] ?? null) == "clearView" + ) { + unset($_SESSION["viewUser"]); + UnitySite::redirect($CONFIG["site"]["prefix"] . "/admin/user-mgmt.php"); + } + // Webroot files need to handle their own POSTs before loading the header + // so that they can do UnitySite::badRequest before anything else has been printed. + // They also must not redirect like standard PRG practice because this + // header also needs to handle POST data. So this header does the PRG redirect + // for all pages. + UnitySite::redirect($_SERVER['PHP_SELF']); + unset($_POST); // unset ensures that header must not come before POST handling } if (isset($SSO)) { diff --git a/webroot/admin/content.php b/webroot/admin/content.php index 3f1c5248..2225c79a 100644 --- a/webroot/admin/content.php +++ b/webroot/admin/content.php @@ -12,7 +12,6 @@ if (!empty($_POST["pageSel"])) { $SQL->editPage($_POST["pageSel"], $_POST["content"], $USER); } - UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; diff --git a/webroot/admin/notices.php b/webroot/admin/notices.php index afdd940f..77e7e6e9 100644 --- a/webroot/admin/notices.php +++ b/webroot/admin/notices.php @@ -23,7 +23,6 @@ break; } - UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; diff --git a/webroot/admin/pi-mgmt.php b/webroot/admin/pi-mgmt.php index b1b399ef..f5a2eb77 100644 --- a/webroot/admin/pi-mgmt.php +++ b/webroot/admin/pi-mgmt.php @@ -50,7 +50,6 @@ break; } - UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; diff --git a/webroot/admin/user-mgmt.php b/webroot/admin/user-mgmt.php index e3ad22a1..1568aa64 100644 --- a/webroot/admin/user-mgmt.php +++ b/webroot/admin/user-mgmt.php @@ -15,7 +15,6 @@ UnitySite::redirect($CONFIG["site"]["prefix"] . "/panel/account.php"); break; } - UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; diff --git a/webroot/index.php b/webroot/index.php index d7090304..6ab2cdc0 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -2,7 +2,7 @@ require_once __DIR__ . "/../resources/autoload.php"; -require_once $LOC_HEADER; +include $LOC_HEADER; ?> diff --git a/webroot/panel/account.php b/webroot/panel/account.php index 32e93383..14047f3f 100644 --- a/webroot/panel/account.php +++ b/webroot/panel/account.php @@ -4,8 +4,6 @@ use UnityWebPortal\lib\UnitySite; -require_once $LOC_HEADER; - if ($_SERVER['REQUEST_METHOD'] == "POST") { switch (UnitySite::arrayGetOrBadRequest($_POST, "form_type")) { case "addKey": @@ -72,8 +70,9 @@ } break; } - UnitySite::redirect($_SERVER['PHP_SELF']); } + +include $LOC_HEADER; ?>

Account Settings

diff --git a/webroot/panel/groups.php b/webroot/panel/groups.php index f9e54534..8d982181 100644 --- a/webroot/panel/groups.php +++ b/webroot/panel/groups.php @@ -41,7 +41,6 @@ break; } } - UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; diff --git a/webroot/panel/new_account.php b/webroot/panel/new_account.php index 777157fa..d3afb6ec 100644 --- a/webroot/panel/new_account.php +++ b/webroot/panel/new_account.php @@ -42,9 +42,8 @@ } else { UnitySite::badRequest("neither 'new_user_sel' or 'cancel' are set!"); } - UnitySite::redirect($_SERVER['PHP_SELF']); } -require_once $LOC_HEADER; +include $LOC_HEADER; ?>

Request Account

diff --git a/webroot/panel/pi.php b/webroot/panel/pi.php index 9fb89547..386a8ceb 100644 --- a/webroot/panel/pi.php +++ b/webroot/panel/pi.php @@ -31,7 +31,6 @@ break; } - UnitySite::redirect($_SERVER['PHP_SELF']); } include $LOC_HEADER; diff --git a/webroot/panel/support.php b/webroot/panel/support.php index b38f5943..cfc91d2a 100644 --- a/webroot/panel/support.php +++ b/webroot/panel/support.php @@ -2,7 +2,7 @@ require "../../resources/autoload.php"; -require_once $LOC_HEADER; +include $LOC_HEADER; ?>

Support

From 9fe079a261253406ea0a8200befc867c5b7f5293 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Tue, 3 Jun 2025 16:02:03 -0400 Subject: [PATCH 04/11] more similar to original --- webroot/index.php | 2 +- webroot/panel/new_account.php | 2 +- webroot/panel/support.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/webroot/index.php b/webroot/index.php index 6ab2cdc0..d7090304 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -2,7 +2,7 @@ require_once __DIR__ . "/../resources/autoload.php"; -include $LOC_HEADER; +require_once $LOC_HEADER; ?> diff --git a/webroot/panel/new_account.php b/webroot/panel/new_account.php index d3afb6ec..cf4c4093 100644 --- a/webroot/panel/new_account.php +++ b/webroot/panel/new_account.php @@ -43,7 +43,7 @@ UnitySite::badRequest("neither 'new_user_sel' or 'cancel' are set!"); } } -include $LOC_HEADER; +require_once $LOC_HEADER; ?>

Request Account

diff --git a/webroot/panel/support.php b/webroot/panel/support.php index cfc91d2a..b38f5943 100644 --- a/webroot/panel/support.php +++ b/webroot/panel/support.php @@ -2,7 +2,7 @@ require "../../resources/autoload.php"; -include $LOC_HEADER; +require_once $LOC_HEADER; ?>

Support

From 835d9072835120fce4f8186fe10db9304956d4df Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Tue, 3 Jun 2025 16:10:41 -0400 Subject: [PATCH 05/11] fix infinite loop --- resources/templates/header.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/templates/header.php b/resources/templates/header.php index caaca9ed..269a6541 100644 --- a/resources/templates/header.php +++ b/resources/templates/header.php @@ -2,7 +2,7 @@ use UnityWebPortal\lib\UnitySite; -if (isset($_POST)) { +if ($_SERVER["REQUEST_METHOD"] == "POST") { if ((@$_SESSION["is_admin"] ?? false) == true && (@$_POST["form_name"] ?? null) == "clearView" ) { @@ -14,8 +14,8 @@ // They also must not redirect like standard PRG practice because this // header also needs to handle POST data. So this header does the PRG redirect // for all pages. - UnitySite::redirect($_SERVER['PHP_SELF']); unset($_POST); // unset ensures that header must not come before POST handling + UnitySite::redirect($_SERVER['PHP_SELF']); } if (isset($SSO)) { From 08cfc0081329188c2485f8e05e95cf1799899451 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Tue, 3 Jun 2025 16:34:49 -0400 Subject: [PATCH 06/11] clarity --- test/phpunit-bootstrap.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/phpunit-bootstrap.php b/test/phpunit-bootstrap.php index 93522599..61f7fa10 100644 --- a/test/phpunit-bootstrap.php +++ b/test/phpunit-bootstrap.php @@ -81,17 +81,18 @@ function http_post(string $phpfile, array $post_data): void $_SERVER["PHP_SELF"] = preg_replace("/.*webroot\//", "/", $phpfile); $_POST = $post_data; ob_start(); - $post_did_redirect = false; + $post_did_redirect_or_die = false; try { include $phpfile; } catch (UnityWebPortal\lib\exceptions\PhpUnitNoDieException $e) { - $post_did_redirect = true; + $post_did_redirect_or_die = true; } finally { ob_get_clean(); // discard output unset($_POST); $_SERVER = $_PREVIOUS_SERVER; } - assert($post_did_redirect, "post did not redirect!"); + // https://en.wikipedia.org/wiki/Post/Redirect/Get + assert($post_did_redirect_or_die, "post did not redirect or die!"); } function http_get(string $phpfile, array $get_data = array()): void From 01139febc438913148fa65ff1f49410d248d20c4 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Tue, 3 Jun 2025 16:46:45 -0400 Subject: [PATCH 07/11] require_once -> include --- webroot/index.php | 2 +- webroot/panel/new_account.php | 2 +- webroot/panel/support.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/webroot/index.php b/webroot/index.php index d7090304..6ab2cdc0 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -2,7 +2,7 @@ require_once __DIR__ . "/../resources/autoload.php"; -require_once $LOC_HEADER; +include $LOC_HEADER; ?> diff --git a/webroot/panel/new_account.php b/webroot/panel/new_account.php index cf4c4093..d3afb6ec 100644 --- a/webroot/panel/new_account.php +++ b/webroot/panel/new_account.php @@ -43,7 +43,7 @@ UnitySite::badRequest("neither 'new_user_sel' or 'cancel' are set!"); } } -require_once $LOC_HEADER; +include $LOC_HEADER; ?>

Request Account

diff --git a/webroot/panel/support.php b/webroot/panel/support.php index b38f5943..cfc91d2a 100644 --- a/webroot/panel/support.php +++ b/webroot/panel/support.php @@ -2,7 +2,7 @@ require "../../resources/autoload.php"; -require_once $LOC_HEADER; +include $LOC_HEADER; ?>

Support

From 512f8a9600614dc9dcc0f30df0dd8efab0e11288 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Wed, 4 Jun 2025 07:32:28 -0400 Subject: [PATCH 08/11] remove old file --- test/functional/CancelRequestTest.php | 55 --------------------------- 1 file changed, 55 deletions(-) delete mode 100644 test/functional/CancelRequestTest.php diff --git a/test/functional/CancelRequestTest.php b/test/functional/CancelRequestTest.php deleted file mode 100644 index 8914f166..00000000 --- a/test/functional/CancelRequestTest.php +++ /dev/null @@ -1,55 +0,0 @@ -assertEquals($x, count($SQL->getRequestsByUser($USER->getUID()))); - } - - public function testCancelPIRequest() - { - global $USER, $SQL; - switchUser(...getNonExistentUser()); - // First create a request - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["new_user_sel" => "pi", "eula" => "agree", "confirm_pi" => "agree"] - ); - - $this->assertNumberGroupRequests(1); - - // Now try to cancel it - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["cancel" => "true"] # value of cancel is arbitrary - ); - - $this->assertNumberGroupRequests(0); - } - - public function testCancelGroupJoinRequest() - { - global $USER, $SQL; - switchUser(...getNonExistentUser()); - - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["new_user_sel" => "not_pi", "eula" => "agree", "pi" => getExistingPI()] - ); - - $this->assertNumberGroupRequests(1); - - // Now try to cancel it - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["cancel" => "true"] # value of cancel is arbitrary - ); - - $this->assertNumberGroupRequests(0); - } -} From e3376062fdba1c2e05da5614a0e84fc8960f8f99 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Wed, 4 Jun 2025 07:36:28 -0400 Subject: [PATCH 09/11] remove from group before deleting user --- test/functional/NewUserTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/functional/NewUserTest.php b/test/functional/NewUserTest.php index 84e40f41..76851ed7 100644 --- a/test/functional/NewUserTest.php +++ b/test/functional/NewUserTest.php @@ -63,15 +63,15 @@ private function ensureUserDoesNotExist() { global $USER, $SQL, $LDAP; $SQL->deleteRequestsByUser($USER->getUID()); - if ($USER->exists()) { - $USER->getLDAPUser()->delete(); - assert(!$USER->exists()); - } $org = $USER->getOrgGroup(); if ($org->inOrg($USER)) { $org->removeUser($USER); assert(!$org->inOrg($USER)); } + if ($USER->exists()) { + $USER->getLDAPUser()->delete(); + assert(!$USER->exists()); + } $all_users_group = $LDAP->getUserGroup(); $all_member_uids = $all_users_group->getAttribute("memberuid"); $new_uids = array_diff($all_member_uids, [$USER->getUID()]); From 43ee084bde4d66f83c844adbf50213f8716f7d29 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Wed, 4 Jun 2025 07:37:01 -0400 Subject: [PATCH 10/11] allow post to pass to header --- webroot/panel/new_account.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/webroot/panel/new_account.php b/webroot/panel/new_account.php index d3afb6ec..4c831029 100644 --- a/webroot/panel/new_account.php +++ b/webroot/panel/new_account.php @@ -39,8 +39,6 @@ $pi_group->cancelGroupJoinRequest($user=$USER); } } - } else { - UnitySite::badRequest("neither 'new_user_sel' or 'cancel' are set!"); } } include $LOC_HEADER; From 8721eed050dc8b857c87ac348316a432d6f1d7de Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Wed, 4 Jun 2025 07:46:39 -0400 Subject: [PATCH 11/11] catch redirect exception is now in http_post --- test/functional/NewUserTest.php | 42 ++++++++++----------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/test/functional/NewUserTest.php b/test/functional/NewUserTest.php index 76851ed7..85e0f32d 100644 --- a/test/functional/NewUserTest.php +++ b/test/functional/NewUserTest.php @@ -14,44 +14,26 @@ private function assertNumberGroupRequests(int $x) private function requestGroupCreation() { - $redirectedOrDied = false; - try { - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["new_user_sel" => "pi", "eula" => "agree", "confirm_pi" => "agree"] - ); - } catch (\UnityWebPortal\lib\exceptions\PhpUnitNoDieException) { - $redirectedOrDied = true; - } - $this->assertTrue($redirectedOrDied); + http_post( + __DIR__ . "/../../webroot/panel/new_account.php", + ["new_user_sel" => "pi", "eula" => "agree", "confirm_pi" => "agree"] + ); } private function requestGroupMembership(string $gid) { - $redirectedOrDied = false; - try { - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["new_user_sel" => "not_pi", "eula" => "agree", "pi" => $gid] - ); - } catch (\UnityWebPortal\lib\exceptions\PhpUnitNoDieException) { - $redirectedOrDied = true; - } - $this->assertTrue($redirectedOrDied); + http_post( + __DIR__ . "/../../webroot/panel/new_account.php", + ["new_user_sel" => "not_pi", "eula" => "agree", "pi" => $gid] + ); } private function cancelAllRequests() { - $redirectedOrDied = false; - try { - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["cancel" => "true"] // value of cancel is arbitrary - ); - } catch (\UnityWebPortal\lib\exceptions\PhpUnitNoDieException) { - $redirectedOrDied = true; - } - $this->assertTrue($redirectedOrDied); + http_post( + __DIR__ . "/../../webroot/panel/new_account.php", + ["cancel" => "true"] // value of cancel is arbitrary + ); } // delete requests made by that user