From 31d230dfe66f68cfc8930f695f6f2e6357b685da Mon Sep 17 00:00:00 2001 From: Gurvan Giboire Date: Tue, 5 Dec 2023 11:50:56 -0500 Subject: [PATCH 1/2] Fix unit tests in auth_plugin_test.php --- tests/auth_plugin_test.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/auth_plugin_test.php b/tests/auth_plugin_test.php index 8e8f64f..d3c5eeb 100644 --- a/tests/auth_plugin_test.php +++ b/tests/auth_plugin_test.php @@ -45,6 +45,12 @@ class auth_plugin_test extends advanced_testcase { */ protected $user; + /** + * Path used for the redirection. + * @var string + */ + const REDIRECTION_PATH = "/redirection"; + /** * Initial set up. */ @@ -392,7 +398,7 @@ public function test_create_refuse_duplicate_username() { self::getDataGenerator()->create_user($originaluser); - $duplicateuser = clone($originaluser); + $duplicateuser = clone ($originaluser); $duplicateuser->email = 'duplicateuser@test.com'; $this->expectException(invalid_parameter_exception::class); @@ -422,7 +428,7 @@ public function test_create_refuse_duplicate_email() { self::getDataGenerator()->create_user($originaluser); - $duplicateuser = clone($originaluser); + $duplicateuser = clone ($originaluser); $duplicateuser->username = 'duplicateuser'; $this->expectException(invalid_parameter_exception::class); @@ -1039,10 +1045,12 @@ public function test_user_logout_userkey_when_required_return_not_set() { * Test when try to logout, but user is not logged in. */ public function test_user_logout_userkey_when_user_is_not_logged_in() { - $_POST['return'] = 'http://google.com'; + $_POST['return'] = self::REDIRECTION_PATH; $this->expectException(moodle_exception::class); - $this->expectExceptionMessage('Unsupported redirect to http://google.com detected, execution terminated.'); + $this->expectExceptionMessage( + sprintf("Unsupported redirect to %s detected, execution terminated.", SELF::REDIRECTION_PATH) + ); $this->auth->user_logout_userkey(); } @@ -1053,7 +1061,7 @@ public function test_user_logout_userkey_when_user_is_not_logged_in() { public function test_user_logout_userkey_when_user_logged_in_with_different_auth() { global $USER; - $_POST['return'] = 'http://google.com'; + $_POST['return'] = self::REDIRECTION_PATH; $this->setUser($this->user); try { @@ -1088,14 +1096,16 @@ public function test_user_logout_userkey_logging_out() { $this->setUser($this->user); $USER->auth = 'userkey'; - $_POST['return'] = 'http://google.com'; + $_POST['return'] = self::REDIRECTION_PATH; try { $this->auth->user_logout_userkey(); } catch (moodle_exception $e) { $this->assertFalse(isloggedin()); - $this->assertEquals('Unsupported redirect to http://google.com detected, execution terminated.', $e->getMessage()); + $this->assertEquals( + sprintf('Unsupported redirect to %s detected, execution terminated.', self::REDIRECTION_PATH), + $e->getMessage() + ); } } - } From 87a5ef01104bb4487e238caf1d91a164aa541cc0 Mon Sep 17 00:00:00 2001 From: Gurvan Giboire Date: Wed, 6 Dec 2023 08:07:24 -0500 Subject: [PATCH 2/2] fix upper case self --- tests/auth_plugin_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auth_plugin_test.php b/tests/auth_plugin_test.php index d3c5eeb..d295794 100644 --- a/tests/auth_plugin_test.php +++ b/tests/auth_plugin_test.php @@ -1049,7 +1049,7 @@ public function test_user_logout_userkey_when_user_is_not_logged_in() { $this->expectException(moodle_exception::class); $this->expectExceptionMessage( - sprintf("Unsupported redirect to %s detected, execution terminated.", SELF::REDIRECTION_PATH) + sprintf("Unsupported redirect to %s detected, execution terminated.", self::REDIRECTION_PATH) ); $this->auth->user_logout_userkey();