forked from phpbb-extensions/teamsecurity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfailed_logins_test.php
More file actions
59 lines (51 loc) · 1.82 KB
/
failed_logins_test.php
File metadata and controls
59 lines (51 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
*
* Team Security Measures extension for the phpBB Forum Software package.
*
* @copyright (c) 2015 phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbb\teamsecurity\tests\event;
class failed_logins_test extends listener_base
{
/**
* Data set for log_failed_login_attempts
*
* @return array Array of test data
*/
public static function log_failed_login_attempts_data()
{
return array(
array(true, true, array('user_row' => array('user_id' => 2))),
array(false, true, array('user_row' => array('user_id' => 0))),
array(true, false, array('user_row' => array('user_id' => 0))),
array(false, false, array('user_row' => array('user_id' => 0))),
);
}
/**
* Test failed login attempt information is being logged
*
* @dataProvider log_failed_login_attempts_data
*/
public function test_log_failed_login_attempts($enabled, $in_watch_group, $result)
{
$this->config = new \phpbb\config\config(array(
'sec_login_attempts' => $enabled,
));
$this->set_listener();
$this->listener->expects(self::atMost(1))
->method('in_watch_group')
->willReturn($in_watch_group);
// Check log->add is called once with expected data if enabled and in_watch_group are true,
// otherwise check that it is never called.
$this->log->expects(($enabled && $in_watch_group) ? self::once() : self::never())
->method('add')
->with('user', $result['user_row']['user_id'], $this->user->ip, 'LOG_TEAM_AUTH_FAIL', time(), array('reportee_id' => $result['user_row']['user_id']));
$dispatcher = new \phpbb\event\dispatcher();
$dispatcher->addListener('core.login_box_failed', array($this->listener, 'log_failed_login_attempts'));
$event_data = array('result');
$dispatcher->trigger_event('core.login_box_failed', compact($event_data));
}
}