Línea 35... |
Línea 35... |
35 |
* @copyright 2017 Juan Leyva
|
35 |
* @copyright 2017 Juan Leyva
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
37 |
*/
|
37 |
*/
|
38 |
class login_lib_test extends \advanced_testcase {
|
38 |
class login_lib_test extends \advanced_testcase {
|
Línea 39... |
Línea 39... |
39 |
|
39 |
|
40 |
public function test_core_login_process_password_reset_one_time_without_username_protection() {
|
40 |
public function test_core_login_process_password_reset_one_time_without_username_protection(): void {
|
Línea 41... |
Línea 41... |
41 |
global $CFG;
|
41 |
global $CFG;
|
42 |
|
42 |
|
43 |
$this->resetAfterTest();
|
43 |
$this->resetAfterTest();
|
Línea 57... |
Línea 57... |
57 |
$this->assertMatchesRegularExpression('/A password reset was requested for your account/',
|
57 |
$this->assertMatchesRegularExpression('/A password reset was requested for your account/',
|
58 |
quoted_printable_decode($email->body));
|
58 |
quoted_printable_decode($email->body));
|
59 |
$sink->clear();
|
59 |
$sink->clear();
|
60 |
}
|
60 |
}
|
Línea 61... |
Línea 61... |
61 |
|
61 |
|
62 |
public function test_core_login_process_password_reset_two_consecutive_times_without_username_protection() {
|
62 |
public function test_core_login_process_password_reset_two_consecutive_times_without_username_protection(): void {
|
Línea 63... |
Línea 63... |
63 |
global $CFG;
|
63 |
global $CFG;
|
64 |
|
64 |
|
65 |
$this->resetAfterTest();
|
65 |
$this->resetAfterTest();
|
Línea 82... |
Línea 82... |
82 |
$this->assertMatchesRegularExpression('/A password reset was requested for your account/',
|
82 |
$this->assertMatchesRegularExpression('/A password reset was requested for your account/',
|
83 |
quoted_printable_decode($email->body));
|
83 |
quoted_printable_decode($email->body));
|
84 |
$sink->clear();
|
84 |
$sink->clear();
|
85 |
}
|
85 |
}
|
Línea 86... |
Línea 86... |
86 |
|
86 |
|
87 |
public function test_core_login_process_password_reset_three_consecutive_times_without_username_protection() {
|
87 |
public function test_core_login_process_password_reset_three_consecutive_times_without_username_protection(): void {
|
Línea 88... |
Línea 88... |
88 |
global $CFG;
|
88 |
global $CFG;
|
89 |
|
89 |
|
90 |
$this->resetAfterTest();
|
90 |
$this->resetAfterTest();
|
Línea 103... |
Línea 103... |
103 |
$this->assertSame('emailalreadysent', $status);
|
103 |
$this->assertSame('emailalreadysent', $status);
|
104 |
$emails = $sink->get_messages();
|
104 |
$emails = $sink->get_messages();
|
105 |
$this->assertCount(2, $emails); // Third time email is not sent.
|
105 |
$this->assertCount(2, $emails); // Third time email is not sent.
|
106 |
}
|
106 |
}
|
Línea 107... |
Línea 107... |
107 |
|
107 |
|
108 |
public function test_core_login_process_password_reset_one_time_with_username_protection() {
|
108 |
public function test_core_login_process_password_reset_one_time_with_username_protection(): void {
|
Línea 109... |
Línea 109... |
109 |
global $CFG;
|
109 |
global $CFG;
|
110 |
|
110 |
|
111 |
$this->resetAfterTest();
|
111 |
$this->resetAfterTest();
|
Línea 125... |
Línea 125... |
125 |
$this->assertMatchesRegularExpression('/A password reset was requested for your account/',
|
125 |
$this->assertMatchesRegularExpression('/A password reset was requested for your account/',
|
126 |
quoted_printable_decode($email->body));
|
126 |
quoted_printable_decode($email->body));
|
127 |
$sink->clear();
|
127 |
$sink->clear();
|
128 |
}
|
128 |
}
|
Línea 129... |
Línea 129... |
129 |
|
129 |
|
130 |
public function test_core_login_process_password_reset_with_preexisting_expired_request_without_username_protection() {
|
130 |
public function test_core_login_process_password_reset_with_preexisting_expired_request_without_username_protection(): void {
|
Línea 131... |
Línea 131... |
131 |
global $CFG, $DB;
|
131 |
global $CFG, $DB;
|
132 |
|
132 |
|
133 |
$this->resetAfterTest();
|
133 |
$this->resetAfterTest();
|
Línea 159... |
Línea 159... |
159 |
$this->assertMatchesRegularExpression('/A password reset was requested for your account/',
|
159 |
$this->assertMatchesRegularExpression('/A password reset was requested for your account/',
|
160 |
quoted_printable_decode($email->body));
|
160 |
quoted_printable_decode($email->body));
|
161 |
$sink->clear();
|
161 |
$sink->clear();
|
162 |
}
|
162 |
}
|
Línea 163... |
Línea 163... |
163 |
|
163 |
|
164 |
public function test_core_login_process_password_reset_disabled_auth() {
|
164 |
public function test_core_login_process_password_reset_disabled_auth(): void {
|
165 |
$this->resetAfterTest();
|
165 |
$this->resetAfterTest();
|
Línea 166... |
Línea 166... |
166 |
$user = $this->getDataGenerator()->create_user(array('auth' => 'oauth2'));
|
166 |
$user = $this->getDataGenerator()->create_user(array('auth' => 'oauth2'));
|
Línea 177... |
Línea 177... |
177 |
$this->assertMatchesRegularExpression('/Unfortunately your account on this site is disabled/',
|
177 |
$this->assertMatchesRegularExpression('/Unfortunately your account on this site is disabled/',
|
178 |
quoted_printable_decode($email->body));
|
178 |
quoted_printable_decode($email->body));
|
179 |
$sink->clear();
|
179 |
$sink->clear();
|
180 |
}
|
180 |
}
|
Línea 181... |
Línea 181... |
181 |
|
181 |
|
182 |
public function test_core_login_process_password_reset_auth_not_supporting_email_reset() {
|
182 |
public function test_core_login_process_password_reset_auth_not_supporting_email_reset(): void {
|
Línea 183... |
Línea 183... |
183 |
global $CFG;
|
183 |
global $CFG;
|
184 |
|
184 |
|
185 |
$this->resetAfterTest();
|
185 |
$this->resetAfterTest();
|
Línea 198... |
Línea 198... |
198 |
$this->assertMatchesRegularExpression('/Unfortunately passwords cannot be reset on this site/',
|
198 |
$this->assertMatchesRegularExpression('/Unfortunately passwords cannot be reset on this site/',
|
199 |
quoted_printable_decode($email->body));
|
199 |
quoted_printable_decode($email->body));
|
200 |
$sink->clear();
|
200 |
$sink->clear();
|
201 |
}
|
201 |
}
|
Línea 202... |
Línea 202... |
202 |
|
202 |
|
203 |
public function test_core_login_process_password_reset_missing_parameters() {
|
203 |
public function test_core_login_process_password_reset_missing_parameters(): void {
|
204 |
$this->expectException('moodle_exception');
|
204 |
$this->expectException('moodle_exception');
|
205 |
$this->expectExceptionMessage(get_string('cannotmailconfirm', 'error'));
|
205 |
$this->expectExceptionMessage(get_string('cannotmailconfirm', 'error'));
|
206 |
core_login_process_password_reset(null, null);
|
206 |
core_login_process_password_reset(null, null);
|
Línea 207... |
Línea 207... |
207 |
}
|
207 |
}
|
208 |
|
208 |
|
209 |
public function test_core_login_process_password_reset_invalid_username_with_username_protection() {
|
209 |
public function test_core_login_process_password_reset_invalid_username_with_username_protection(): void {
|
210 |
global $CFG;
|
210 |
global $CFG;
|
211 |
$this->resetAfterTest();
|
211 |
$this->resetAfterTest();
|
212 |
$CFG->protectusernames = 1;
|
212 |
$CFG->protectusernames = 1;
|
213 |
list($status, $notice, $url) = core_login_process_password_reset('72347234nasdfasdf/Ds', null);
|
213 |
list($status, $notice, $url) = core_login_process_password_reset('72347234nasdfasdf/Ds', null);
|
Línea 214... |
Línea 214... |
214 |
$this->assertEquals('emailpasswordconfirmmaybesent', $status);
|
214 |
$this->assertEquals('emailpasswordconfirmmaybesent', $status);
|
215 |
}
|
215 |
}
|
216 |
|
216 |
|
217 |
public function test_core_login_process_password_reset_invalid_username_without_username_protection() {
|
217 |
public function test_core_login_process_password_reset_invalid_username_without_username_protection(): void {
|
218 |
global $CFG;
|
218 |
global $CFG;
|
219 |
$this->resetAfterTest();
|
219 |
$this->resetAfterTest();
|
220 |
$CFG->protectusernames = 0;
|
220 |
$CFG->protectusernames = 0;
|
Línea 221... |
Línea 221... |
221 |
list($status, $notice, $url) = core_login_process_password_reset('72347234nasdfasdf/Ds', null);
|
221 |
list($status, $notice, $url) = core_login_process_password_reset('72347234nasdfasdf/Ds', null);
|
222 |
$this->assertEquals('emailpasswordconfirmnotsent', $status);
|
222 |
$this->assertEquals('emailpasswordconfirmnotsent', $status);
|
223 |
}
|
223 |
}
|
224 |
|
224 |
|
225 |
public function test_core_login_process_password_reset_invalid_email_without_username_protection() {
|
225 |
public function test_core_login_process_password_reset_invalid_email_without_username_protection(): void {
|
226 |
global $CFG;
|
226 |
global $CFG;
|
Línea 326... |
Línea 326... |
326 |
* @dataProvider forgot_password_data_provider
|
326 |
* @dataProvider forgot_password_data_provider
|
327 |
* @param array $data Key-value array containing username and email data.
|
327 |
* @param array $data Key-value array containing username and email data.
|
328 |
* @param array $errors Key-value array containing error messages for the username and email fields.
|
328 |
* @param array $errors Key-value array containing error messages for the username and email fields.
|
329 |
* @param array $options Options for $CFG->protectusernames, $CFG->allowaccountssameemail and $user->confirmed.
|
329 |
* @param array $options Options for $CFG->protectusernames, $CFG->allowaccountssameemail and $user->confirmed.
|
330 |
*/
|
330 |
*/
|
331 |
public function test_core_login_validate_forgot_password_data($data, $errors = [], $options = []) {
|
331 |
public function test_core_login_validate_forgot_password_data($data, $errors = [], $options = []): void {
|
332 |
$this->resetAfterTest();
|
332 |
$this->resetAfterTest();
|
Línea 333... |
Línea 333... |
333 |
|
333 |
|
334 |
// Set config settings we need for our environment.
|
334 |
// Set config settings we need for our environment.
|
335 |
$protectusernames = $options['protectusernames'] ?? 1;
|
335 |
$protectusernames = $options['protectusernames'] ?? 1;
|
Línea 381... |
Línea 381... |
381 |
/**
|
381 |
/**
|
382 |
* Test searching for the user record by matching the provided email address when resetting password.
|
382 |
* Test searching for the user record by matching the provided email address when resetting password.
|
383 |
*
|
383 |
*
|
384 |
* Email addresses should be handled as case-insensitive but accent sensitive.
|
384 |
* Email addresses should be handled as case-insensitive but accent sensitive.
|
385 |
*/
|
385 |
*/
|
386 |
public function test_core_login_process_password_reset_email_sensitivity() {
|
386 |
public function test_core_login_process_password_reset_email_sensitivity(): void {
|
387 |
global $CFG;
|
387 |
global $CFG;
|
388 |
require_once($CFG->libdir.'/phpmailer/moodle_phpmailer.php');
|
388 |
require_once($CFG->libdir.'/phpmailer/moodle_phpmailer.php');
|
Línea 389... |
Línea 389... |
389 |
|
389 |
|
390 |
$this->resetAfterTest();
|
390 |
$this->resetAfterTest();
|