Skip to content
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

Fix unit tests in auth_plugin_test.php #101

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions tests/auth_plugin_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand 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 = '[email protected]';

$this->expectException(invalid_parameter_exception::class);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
);
}
}

}
Loading