Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
 
18
namespace core;
19
 
20
/**
21
 * Authentication related tests.
22
 *
23
 * @package    core
24
 * @category   test
25
 * @copyright  2012 Petr Skoda {@link http://skodak.org}
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1441 ariadna 27
 * @covers \auth_plugin_base
1 efrain 28
 */
1441 ariadna 29
final class authlib_test extends \advanced_testcase {
11 efrain 30
    public function test_lockout(): void {
1 efrain 31
        global $CFG;
32
        require_once("$CFG->libdir/authlib.php");
33
 
34
        $this->resetAfterTest();
35
 
36
        $oldlog = ini_get('error_log');
37
        ini_set('error_log', "$CFG->dataroot/testlog.log"); // Prevent standard logging.
38
 
39
        unset_config('noemailever');
40
 
41
        set_config('lockoutthreshold', 0);
42
        set_config('lockoutwindow', 60*20);
43
        set_config('lockoutduration', 60*30);
44
 
45
        $user = $this->getDataGenerator()->create_user();
46
 
47
        // Test lockout is disabled when threshold not set.
48
 
49
        $this->assertFalse(login_is_lockedout($user));
50
        login_attempt_failed($user);
51
        login_attempt_failed($user);
52
        login_attempt_failed($user);
53
        login_attempt_failed($user);
54
        $this->assertFalse(login_is_lockedout($user));
55
 
56
        // Test lockout threshold works.
57
 
58
        set_config('lockoutthreshold', 3);
59
        login_attempt_failed($user);
60
        login_attempt_failed($user);
61
        $this->assertFalse(login_is_lockedout($user));
62
        $sink = $this->redirectEmails();
63
        login_attempt_failed($user);
64
        $this->assertCount(1, $sink->get_messages());
65
        $sink->close();
66
        $this->assertTrue(login_is_lockedout($user));
67
 
68
        // Test unlock works.
69
 
70
        login_unlock_account($user);
71
        $this->assertFalse(login_is_lockedout($user));
72
 
73
        // Test lockout window works.
74
 
75
        login_attempt_failed($user);
76
        login_attempt_failed($user);
77
        $this->assertFalse(login_is_lockedout($user));
78
        set_user_preference('login_failed_last', time()-60*20-10, $user);
79
        login_attempt_failed($user);
80
        $this->assertFalse(login_is_lockedout($user));
81
 
82
        // Test valid login resets window.
83
 
84
        login_attempt_valid($user);
85
        $this->assertFalse(login_is_lockedout($user));
86
        login_attempt_failed($user);
87
        login_attempt_failed($user);
88
        $this->assertFalse(login_is_lockedout($user));
89
 
90
        // Test lock duration works.
91
 
92
        $sink = $this->redirectEmails();
93
        login_attempt_failed($user);
94
        $this->assertCount(1, $sink->get_messages());
95
        $sink->close();
96
        $this->assertTrue(login_is_lockedout($user));
97
        set_user_preference('login_lockout', time()-60*30+10, $user);
98
        $this->assertTrue(login_is_lockedout($user));
99
        set_user_preference('login_lockout', time()-60*30-10, $user);
100
        $this->assertFalse(login_is_lockedout($user));
101
 
102
        // Test lockout ignored pref works.
103
 
104
        set_user_preference('login_lockout_ignored', 1, $user);
105
        login_attempt_failed($user);
106
        login_attempt_failed($user);
107
        login_attempt_failed($user);
108
        login_attempt_failed($user);
109
        $this->assertFalse(login_is_lockedout($user));
110
 
111
        ini_set('error_log', $oldlog);
112
    }
113
 
11 efrain 114
    public function test_authenticate_user_login(): void {
1 efrain 115
        global $CFG;
116
 
117
        $this->resetAfterTest();
118
 
119
        $oldlog = ini_get('error_log');
120
        ini_set('error_log', "$CFG->dataroot/testlog.log"); // Prevent standard logging.
121
 
122
        unset_config('noemailever');
123
 
124
        set_config('lockoutthreshold', 0);
125
        set_config('lockoutwindow', 60*20);
126
        set_config('lockoutduration', 60*30);
127
 
128
        $_SERVER['HTTP_USER_AGENT'] = 'no browser'; // Hack around missing user agent in CLI scripts.
129
 
130
        $user1 = $this->getDataGenerator()->create_user(array('username'=>'username1', 'password'=>'password1', 'email'=>'email1@example.com'));
131
        $user2 = $this->getDataGenerator()->create_user(array('username'=>'username2', 'password'=>'password2', 'email'=>'email2@example.com', 'suspended'=>1));
132
        $user3 = $this->getDataGenerator()->create_user(array('username'=>'username3', 'password'=>'password3', 'email'=>'email2@example.com', 'auth'=>'nologin'));
133
 
134
        // Normal login.
135
        $sink = $this->redirectEvents();
136
        $result = authenticate_user_login('username1', 'password1');
137
        $events = $sink->get_events();
138
        $sink->close();
139
        $this->assertEmpty($events);
140
        $this->assertInstanceOf('stdClass', $result);
141
        $this->assertEquals($user1->id, $result->id);
142
 
143
        // Normal login with reason.
144
        $reason = null;
145
        $sink = $this->redirectEvents();
146
        $result = authenticate_user_login('username1', 'password1', false, $reason);
147
        $events = $sink->get_events();
148
        $sink->close();
149
        $this->assertEmpty($events);
150
        $this->assertInstanceOf('stdClass', $result);
151
        $this->assertEquals(AUTH_LOGIN_OK, $reason);
152
 
153
        // Test login via email
154
        $reason = null;
155
        $this->assertEmpty($CFG->authloginviaemail);
156
        $sink = $this->redirectEvents();
157
        $result = authenticate_user_login('email1@example.com', 'password1', false, $reason);
158
        $sink->close();
159
        $this->assertFalse($result);
160
        $this->assertEquals(AUTH_LOGIN_NOUSER, $reason);
161
 
162
        set_config('authloginviaemail', 1);
163
        $this->assertNotEmpty($CFG->authloginviaemail);
164
        $sink = $this->redirectEvents();
165
        $result = authenticate_user_login('email1@example.com', 'password1');
166
        $events = $sink->get_events();
167
        $sink->close();
168
        $this->assertEmpty($events);
169
        $this->assertInstanceOf('stdClass', $result);
170
        $this->assertEquals($user1->id, $result->id);
171
 
172
        $reason = null;
173
        $sink = $this->redirectEvents();
174
        $result = authenticate_user_login('email2@example.com', 'password2', false, $reason);
175
        $events = $sink->get_events();
176
        $sink->close();
177
        $this->assertFalse($result);
178
        $this->assertEquals(AUTH_LOGIN_NOUSER, $reason);
179
        set_config('authloginviaemail', 0);
180
 
181
        $reason = null;
182
        // Capture failed login event.
183
        $sink = $this->redirectEvents();
184
        $result = authenticate_user_login('username1', 'nopass', false, $reason);
185
        $events = $sink->get_events();
186
        $sink->close();
187
        $event = array_pop($events);
188
 
189
        $this->assertFalse($result);
190
        $this->assertEquals(AUTH_LOGIN_FAILED, $reason);
191
        // Test Event.
192
        $this->assertInstanceOf('\core\event\user_login_failed', $event);
193
        $eventdata = $event->get_data();
194
        $this->assertSame($eventdata['other']['username'], 'username1');
195
        $this->assertSame($eventdata['other']['reason'], AUTH_LOGIN_FAILED);
196
        $this->assertEventContextNotUsed($event);
197
 
198
        // Capture failed login token.
199
        unset($CFG->alternateloginurl);
200
        unset($CFG->disablelogintoken);
201
        $sink = $this->redirectEvents();
202
        $result = authenticate_user_login('username1', 'password1', false, $reason, 'invalidtoken');
203
        $events = $sink->get_events();
204
        $sink->close();
205
        $event = array_pop($events);
206
 
207
        $this->assertFalse($result);
208
        $this->assertEquals(AUTH_LOGIN_FAILED, $reason);
209
        // Test Event.
210
        $this->assertInstanceOf('\core\event\user_login_failed', $event);
211
        $eventdata = $event->get_data();
212
        $this->assertSame($eventdata['other']['username'], 'username1');
213
        $this->assertSame($eventdata['other']['reason'], AUTH_LOGIN_FAILED);
214
        $this->assertEventContextNotUsed($event);
215
 
216
        // Login should work with invalid token if CFG login token settings override it.
217
        $CFG->alternateloginurl = 'http://localhost/';
218
        $sink = $this->redirectEvents();
219
        $result = authenticate_user_login('username1', 'password1', false, $reason, 'invalidtoken');
220
        $events = $sink->get_events();
221
        $sink->close();
222
        $this->assertEmpty($events);
223
        $this->assertInstanceOf('stdClass', $result);
224
        $this->assertEquals(AUTH_LOGIN_OK, $reason);
225
 
226
        unset($CFG->alternateloginurl);
227
        $CFG->disablelogintoken = true;
228
 
229
        $sink = $this->redirectEvents();
230
        $result = authenticate_user_login('username1', 'password1', false, $reason, 'invalidtoken');
231
        $events = $sink->get_events();
232
        $sink->close();
233
        $this->assertEmpty($events);
234
        $this->assertInstanceOf('stdClass', $result);
235
        $this->assertEquals(AUTH_LOGIN_OK, $reason);
236
 
237
        unset($CFG->disablelogintoken);
238
        // Normal login with valid token.
239
        $reason = null;
240
        $token = \core\session\manager::get_login_token();
241
        $sink = $this->redirectEvents();
242
        $result = authenticate_user_login('username1', 'password1', false, $reason, $token);
243
        $events = $sink->get_events();
244
        $sink->close();
245
        $this->assertEmpty($events);
246
        $this->assertInstanceOf('stdClass', $result);
247
        $this->assertEquals(AUTH_LOGIN_OK, $reason);
248
 
249
        $reason = null;
250
        // Capture failed login event.
251
        $sink = $this->redirectEvents();
252
        $result = authenticate_user_login('username2', 'password2', false, $reason);
253
        $events = $sink->get_events();
254
        $sink->close();
255
        $event = array_pop($events);
256
 
257
        $this->assertFalse($result);
258
        $this->assertEquals(AUTH_LOGIN_SUSPENDED, $reason);
259
        // Test Event.
260
        $this->assertInstanceOf('\core\event\user_login_failed', $event);
261
        $eventdata = $event->get_data();
262
        $this->assertSame($eventdata['other']['username'], 'username2');
263
        $this->assertSame($eventdata['other']['reason'], AUTH_LOGIN_SUSPENDED);
264
        $this->assertEventContextNotUsed($event);
265
 
266
        $reason = null;
267
        // Capture failed login event.
268
        $sink = $this->redirectEvents();
269
        $result = authenticate_user_login('username3', 'password3', false, $reason);
270
        $events = $sink->get_events();
271
        $sink->close();
272
        $event = array_pop($events);
273
 
274
        $this->assertFalse($result);
275
        $this->assertEquals(AUTH_LOGIN_SUSPENDED, $reason);
276
        // Test Event.
277
        $this->assertInstanceOf('\core\event\user_login_failed', $event);
278
        $eventdata = $event->get_data();
279
        $this->assertSame($eventdata['other']['username'], 'username3');
280
        $this->assertSame($eventdata['other']['reason'], AUTH_LOGIN_SUSPENDED);
281
        $this->assertEventContextNotUsed($event);
282
 
283
        $reason = null;
284
        // Capture failed login event.
285
        $sink = $this->redirectEvents();
286
        $result = authenticate_user_login('username4', 'password3', false, $reason);
287
        $events = $sink->get_events();
288
        $sink->close();
289
        $event = array_pop($events);
290
 
291
        $this->assertFalse($result);
292
        $this->assertEquals(AUTH_LOGIN_NOUSER, $reason);
293
        // Test Event.
294
        $this->assertInstanceOf('\core\event\user_login_failed', $event);
295
        $eventdata = $event->get_data();
296
        $this->assertSame($eventdata['other']['username'], 'username4');
297
        $this->assertSame($eventdata['other']['reason'], AUTH_LOGIN_NOUSER);
298
        $this->assertEventContextNotUsed($event);
299
 
300
        set_config('lockoutthreshold', 3);
301
 
302
        $reason = null;
303
        $result = authenticate_user_login('username1', 'nopass', false, $reason);
304
        $this->assertFalse($result);
305
        $this->assertEquals(AUTH_LOGIN_FAILED, $reason);
306
        $result = authenticate_user_login('username1', 'nopass', false, $reason);
307
        $this->assertFalse($result);
308
        $this->assertEquals(AUTH_LOGIN_FAILED, $reason);
309
        $sink = $this->redirectEmails();
310
        $result = authenticate_user_login('username1', 'nopass', false, $reason);
311
        $this->assertCount(1, $sink->get_messages());
312
        $sink->close();
313
        $this->assertFalse($result);
314
        $this->assertEquals(AUTH_LOGIN_FAILED, $reason);
315
 
316
        $result = authenticate_user_login('username1', 'password1', false, $reason);
317
        $this->assertFalse($result);
318
        $this->assertEquals(AUTH_LOGIN_LOCKOUT, $reason);
319
 
320
        $result = authenticate_user_login('username1', 'password1', true, $reason);
321
        $this->assertInstanceOf('stdClass', $result);
322
        $this->assertEquals(AUTH_LOGIN_OK, $reason);
323
 
324
        ini_set('error_log', $oldlog);
325
 
326
        // Test password policy check on login.
327
        $CFG->passwordpolicy = 0;
328
        $CFG->passwordpolicycheckonlogin = 1;
329
 
330
        // First test with password policy disabled.
331
        $user4 = $this->getDataGenerator()->create_user(array('username' => 'username4', 'password' => 'a'));
332
        $sink = $this->redirectEvents();
333
        $reason = null;
334
        $result = authenticate_user_login('username4', 'a', false, $reason);
335
        $events = $sink->get_events();
336
        $sink->close();
337
        $notifications = notification::fetch();
338
        $this->assertInstanceOf('stdClass', $result);
339
        $this->assertEquals(AUTH_LOGIN_OK, $reason);
340
        $this->assertEquals(get_user_preferences('auth_forcepasswordchange', false, $result), false);
341
        // Check no events.
342
        $this->assertEquals(count($events), 0);
343
        // Check no notifications.
344
        $this->assertEquals(count($notifications), 0);
345
 
346
        // Now test with the password policy enabled, flip reset flag.
347
        $sink = $this->redirectEvents();
348
        $reason = null;
349
        $CFG->passwordpolicy = 1;
350
        $result = authenticate_user_login('username4', 'a', false, $reason);
351
        $events = $sink->get_events();
352
        $sink->close();
353
        $this->assertInstanceOf('stdClass', $result);
354
        $this->assertEquals(AUTH_LOGIN_OK, $reason);
355
        $this->assertEquals(get_user_preferences('auth_forcepasswordchange', true, $result), true);
356
        // Check that an event was emitted for the policy failure.
357
        $this->assertEquals(count($events), 1);
358
        $this->assertEquals(reset($events)->eventname, '\core\event\user_password_policy_failed');
359
        // Check notification fired.
360
        $notifications = notification::fetch();
361
        $this->assertEquals(count($notifications), 1);
362
 
363
        // Now the same tests with a user that passes the password policy.
364
        $user5 = $this->getDataGenerator()->create_user(array('username' => 'username5', 'password' => 'ThisPassword1sSecure!'));
365
        $reason = null;
366
        $CFG->passwordpolicy = 0;
367
        $sink = $this->redirectEvents();
368
        $result = authenticate_user_login('username5', 'ThisPassword1sSecure!', false, $reason);
369
        $events = $sink->get_events();
370
        $sink->close();
371
        $notifications = notification::fetch();
372
        $this->assertInstanceOf('stdClass', $result);
373
        $this->assertEquals(AUTH_LOGIN_OK, $reason);
374
        $this->assertEquals(get_user_preferences('auth_forcepasswordchange', false, $result), false);
375
        // Check no events.
376
        $this->assertEquals(count($events), 0);
377
        // Check no notifications.
378
        $this->assertEquals(count($notifications), 0);
379
 
380
        $reason = null;
381
        $CFG->passwordpolicy = 1;
382
        $sink = $this->redirectEvents();
383
        $result = authenticate_user_login('username5', 'ThisPassword1sSecure!', false, $reason);
384
        $events = $sink->get_events();
385
        $sink->close();
386
        $notifications = notification::fetch();
387
        $this->assertInstanceOf('stdClass', $result);
388
        $this->assertEquals(AUTH_LOGIN_OK, $reason);
389
        $this->assertEquals(get_user_preferences('auth_forcepasswordchange', false, $result), false);
390
        // Check no events.
391
        $this->assertEquals(count($events), 0);
392
        // Check no notifications.
393
        $this->assertEquals(count($notifications), 0);
394
 
395
        // Capture failed login reCaptcha.
396
        $CFG->recaptchapublickey = 'randompublickey';
397
        $CFG->recaptchaprivatekey = 'randomprivatekey';
398
        $CFG->enableloginrecaptcha = true;
399
 
400
        // Login with blank captcha.
401
        $sink = $this->redirectEvents();
402
        $result = authenticate_user_login('username1', 'password1', false, $reason, false, '');
403
        $events = $sink->get_events();
404
        $sink->close();
405
        $event = array_pop($events);
406
 
407
        $this->assertFalse($result);
408
        $this->assertEquals(AUTH_LOGIN_FAILED_RECAPTCHA, $reason);
409
 
410
        // Test event.
411
        $this->assertInstanceOf('\core\event\user_login_failed', $event);
412
        $eventdata = $event->get_data();
413
        $this->assertSame($eventdata['other']['username'], 'username1');
414
        $this->assertSame($eventdata['other']['reason'], AUTH_LOGIN_FAILED_RECAPTCHA);
415
        $this->assertEventContextNotUsed($event);
416
 
417
        // Login with invalid captcha.
418
        $sink = $this->redirectEvents();
419
        $result = authenticate_user_login('username1', 'password1', false, $reason, false, 'invalidcaptcha');
420
        $events = $sink->get_events();
421
        $sink->close();
422
        $event = array_pop($events);
423
 
424
        $this->assertFalse($result);
425
        $this->assertEquals(AUTH_LOGIN_FAILED_RECAPTCHA, $reason);
426
 
427
        // Test event.
428
        $this->assertInstanceOf('\core\event\user_login_failed', $event);
429
        $eventdata = $event->get_data();
430
        $this->assertSame($eventdata['other']['username'], 'username1');
431
        $this->assertSame($eventdata['other']['reason'], AUTH_LOGIN_FAILED_RECAPTCHA);
432
        $this->assertEventContextNotUsed($event);
433
 
434
        // Unset settings.
435
        unset($CFG->recaptchapublickey);
436
        unset($CFG->recaptchaprivatekey);
437
        unset($CFG->enableloginrecaptcha);
438
    }
439
 
11 efrain 440
    public function test_user_loggedin_event_exceptions(): void {
1 efrain 441
        try {
442
            $event = \core\event\user_loggedin::create(array('objectid' => 1));
443
            $this->fail('\core\event\user_loggedin requires other[\'username\']');
444
        } catch(\Exception $e) {
445
            $this->assertInstanceOf('coding_exception', $e);
446
        }
447
    }
448
 
449
    /**
450
     * Test the {@link signup_validate_data()} duplicate email validation.
451
     */
11 efrain 452
    public function test_signup_validate_data_same_email(): void {
1 efrain 453
        global $CFG;
454
        require_once($CFG->libdir . '/authlib.php');
455
        require_once($CFG->libdir . '/phpmailer/moodle_phpmailer.php');
456
        require_once($CFG->dirroot . '/user/profile/lib.php');
457
 
458
        $this->resetAfterTest();
459
 
460
        $CFG->registerauth = 'email';
461
        $CFG->passwordpolicy = false;
462
 
463
        // In this test, we want to check accent-sensitive email search. However, accented email addresses do not pass
464
        // the default `validate_email()` and Moodle does not yet provide a CFG switch to allow such emails.  So we
465
        // inject our own validation method here and revert it back once we are done. This custom validator method is
466
        // identical to the default 'php' validator with the only difference: it has the FILTER_FLAG_EMAIL_UNICODE set
467
        // so that it allows to use non-ASCII characters in email addresses.
468
        $defaultvalidator = \moodle_phpmailer::$validator;
469
        \moodle_phpmailer::$validator = function($address) {
470
            return (bool) filter_var($address, FILTER_VALIDATE_EMAIL, FILTER_FLAG_EMAIL_UNICODE);
471
        };
472
 
473
        // Check that two users cannot share the same email address if the site is configured so.
474
        // Emails in Moodle are supposed to be case-insensitive (and accent-sensitive but accents are not yet supported).
475
        $CFG->allowaccountssameemail = false;
476
 
477
        $u1 = $this->getDataGenerator()->create_user([
478
            'username' => 'abcdef',
479
            'email' => 'abcdef@example.com',
480
        ]);
481
 
482
        $formdata = [
483
            'username' => 'newuser',
484
            'firstname' => 'First',
485
            'lastname' => 'Last',
486
            'password' => 'weak',
487
            'email' => 'ABCDEF@example.com',
488
        ];
489
 
490
        $errors = signup_validate_data($formdata, []);
491
        $this->assertStringContainsString('This email address is already registered.', $errors['email']);
492
 
493
        // Emails are accent-sensitive though so if we change a -> á in the u1's email, it should pass.
494
        // Please note that Moodle does not normally support such emails yet. We test the DB search sensitivity here.
495
        $formdata['email'] = 'ábcdef@example.com';
496
        $errors = signup_validate_data($formdata, []);
497
        $this->assertArrayNotHasKey('email', $errors);
498
 
499
        // Check that users can share the same email if the site is configured so.
500
        $CFG->allowaccountssameemail = true;
501
        $formdata['email'] = 'abcdef@example.com';
502
        $errors = signup_validate_data($formdata, []);
503
        $this->assertArrayNotHasKey('email', $errors);
504
 
505
        // Restore the original email address validator.
506
        \moodle_phpmailer::$validator = $defaultvalidator;
507
    }
508
 
509
    /**
510
     * Test the find_cli_user method
511
     */
512
    public function test_find_cli_user(): void {
513
        global $CFG, $USER;
514
        require_once("$CFG->libdir/authlib.php");
515
        require_once("$CFG->libdir/tests/fixtures/testable_auth_plugin_base.php");
516
 
517
        $this->resetAfterTest();
518
 
519
        $user = \testable_auth_plugin_base::find_cli_admin_user();
520
        $this->assertEmpty($user);
521
 
522
        $u1 = $this->getDataGenerator()->create_user([
523
            'username' => 'abcdef',
524
            'email' => 'abcdef@example.com',
525
        ]);
526
        $user = \testable_auth_plugin_base::find_cli_admin_user();
527
        $this->assertEmpty($user); // User is not an admin yet.
528
 
529
        \testable_auth_plugin_base::login_cli_admin_user();
530
        $this->assertEquals($USER->id, 0); // User is not logged in.
531
 
532
        $CFG->siteadmins .= "," . $u1->id;
533
 
534
        \testable_auth_plugin_base::login_cli_admin_user();
535
        $this->assertEquals($USER->id, $u1->id); // User is now logged in.
536
 
537
        $user = \testable_auth_plugin_base::find_cli_admin_user();
538
        $this->assertNotEmpty($user);
539
    }
540
 
541
    /**
542
     * Test the get_enabled_auth_plugin_classes method
543
     */
544
    public function test_get_enabled_auth_plugin_classes(): void {
545
        global $CFG;
546
        require_once("$CFG->libdir/authlib.php");
547
        $plugins = \auth_plugin_base::get_enabled_auth_plugin_classes();
548
        $this->assertEquals(get_class($plugins[0]), 'auth_plugin_manual');
549
        $this->assertEquals(count($plugins), 3);
550
    }
551
 
1441 ariadna 552
    /**
553
     * Test case for checking the email greetings in account lockout notification emails.
554
     *
555
     * @covers ::login_lock_account()
556
     */
557
    public function test_email_greetings(): void {
558
        $this->resetAfterTest();
559
 
560
        $user = $this->getDataGenerator()->create_user();
561
 
562
        $sink = $this->redirectEmails(); // Make sure we are redirecting emails.
563
        login_lock_account($user);
564
        $result = $sink->get_messages();
565
        $sink->close();
566
        // Test greetings.
567
        $this->assertStringContainsString('Hi ' . $user->firstname, quoted_printable_decode($result[0]->body));
568
    }
569
 
1 efrain 570
}