-
Notifications
You must be signed in to change notification settings - Fork 55
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
Issue #55: [UPD] make userkey respect suspended status of users #87
base: MOODLE_33PLUS
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,15 @@ public function user_login_userkey() { | |
$this->userkeymanager->delete_keys($key->userid); | ||
|
||
$user = get_complete_user_data('id', $key->userid); | ||
if (!empty($user->suspended)) { | ||
$failurereason = AUTH_LOGIN_SUSPENDED; | ||
|
||
// Trigger login failed event. | ||
$event = \core\event\user_login_failed::create(array('userid' => $user->id, | ||
'other' => array('username' => $user->username, 'reason' => $failurereason))); | ||
$event->trigger(); | ||
throw new invalid_parameter_exception('User suspended'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this error will be displayed to a user, can we please replace this with moodle_exception + add a lang string so it could be localised. |
||
} | ||
complete_user_login($user); | ||
|
||
// Identify this session as using user key auth method. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,6 +237,25 @@ public function test_throwing_exception_if_user_is_not_exist() { | |
$this->expectExceptionMessage('Invalid parameter value detected (User is not exist)'); | ||
$actual = $this->auth->get_login_url($user); | ||
} | ||
/** | ||
* Test that auth plugin throws correct exception if we trying to request not existing user. | ||
*/ | ||
public function test_throwing_exception_if_user_is_suspended() { | ||
global $USER, $SESSION; | ||
|
||
$user = $this->getDataGenerator()->create_user(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is already created user for the test. You can use $this->user. |
||
$user->suspended = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need to save this state to DB. |
||
$this->setUser($user); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are you trying to test here? I don't think you need set a user here and then try to login again, but using a key. |
||
$this->assertEquals($USER->id, $user->id); | ||
|
||
$this->create_user_private_key(); | ||
$_POST['key'] = 'TestKey'; | ||
|
||
$this->expectException(invalid_parameter_exception::class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before checking this, can you please check that login failed event has been triggered? |
||
$this->expectExceptionMessage('Invalid parameter value detected (User is suspended)'); | ||
|
||
$this->auth->user_login_userkey(); | ||
} | ||
|
||
/** | ||
* Test that auth plugin throws correct exception if we trying to request user, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you really need this variable? Could be passed as is to the code below.