1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\MFA\Tests\Report; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\Config\Config; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
use SilverStripe\Forms\DropdownField; |
8
|
|
|
use SilverStripe\MFA\BackupCode\Method as BackupMethod; |
9
|
|
|
use SilverStripe\MFA\Report\EnabledMembers; |
10
|
|
|
use SilverStripe\MFA\Service\MethodRegistry; |
11
|
|
|
use SilverStripe\MFA\Tests\Stub\BasicMath\Method as BasicMathMethod; |
12
|
|
|
use SilverStripe\MFA\Tests\Stub\Null\Method as NullMethod; |
13
|
|
|
|
14
|
|
|
class EnabledMembersTest extends SapphireTest |
15
|
|
|
{ |
16
|
|
|
protected static $fixture_file = 'EnabledMembersTest.yml'; |
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
parent::setUp(); |
21
|
|
|
Config::modify() |
22
|
|
|
->set(MethodRegistry::class, 'default_backup_method', BackupMethod::class) |
23
|
|
|
->set(MethodRegistry::class, 'methods', [BasicMathMethod::class, NullMethod::class, BackupMethod::class]); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testRegisteredMethodFilterFieldDoesNotContainBackupMethod() |
27
|
|
|
{ |
28
|
|
|
$report = new EnabledMembers(); |
29
|
|
|
$fields = $report->parameterFields(); |
30
|
|
|
/** @var DropdownField $registeredMethodFilterField */ |
31
|
|
|
$registeredMethodFilterField = $fields->dataFieldByName('Methods'); |
32
|
|
|
$source = $registeredMethodFilterField->getSource(); |
33
|
|
|
$this->assertArrayNotHasKey(BackupMethod::class, $source); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @dataProvider sourceRecordsParamsProvider |
38
|
|
|
* @param array $params |
39
|
|
|
* @param int $expectedRows |
40
|
|
|
*/ |
41
|
|
|
public function testSourceRecords($params, $expectedRows) |
42
|
|
|
{ |
43
|
|
|
$report = new EnabledMembers(); |
44
|
|
|
$records = $report->sourceRecords($params); |
45
|
|
|
$this->assertCount($expectedRows, $records); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function sourceRecordsParamsProvider() |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
|
|
'no filters' => [[], 5], |
52
|
|
|
'skipped registration' => [['Skipped' => 'yes'], 2], |
53
|
|
|
'partial match on member name fields' => [['Member' => 'i'], 4], |
54
|
|
|
'includes member email field' => [['Member' => '.com'], 4], |
55
|
|
|
'specific registered method' => [['Methods' => BasicMathMethod::class], 2], |
56
|
|
|
'method, member name, and skipped filters' => [ |
57
|
|
|
['Methods' => BasicMathMethod::class, 'Member' => 'EDITOR', 'Skipped' => 'yes'], |
58
|
|
|
1, |
59
|
|
|
], |
60
|
|
|
'skipped filter removes record that would otherwise match' => [ |
61
|
|
|
['Methods' => BasicMathMethod::class, 'Member' => 'EDITOR', 'Skipped' => 'no'], |
62
|
|
|
0, |
63
|
|
|
], |
64
|
|
|
'miss match on method, MFA in name, skipped' => [ |
65
|
|
|
['Methods' => BasicMathMethod::class, 'Member' => 'MFA', 'Skipped' => 'yes'], |
66
|
|
|
0, |
67
|
|
|
], |
68
|
|
|
'miss match on method, editor in name, skipped' => [ |
69
|
|
|
['Methods' => NullMethod::class, 'Member' => 'EDITOR', 'Skipped' => 'yes'], |
70
|
|
|
0, |
71
|
|
|
], |
72
|
|
|
'hit match on method, MFA in name, not skipped' => [ |
73
|
|
|
['Methods' => NullMethod::class, 'Member' => 'MFA', 'Skipped' => 'no'], |
74
|
|
|
1, |
75
|
|
|
], |
76
|
|
|
'empty filters returns all records' => [ |
77
|
|
|
['Methods' => '', 'Member' => '', 'Skipped' => ''], |
78
|
|
|
5, |
79
|
|
|
], |
80
|
|
|
'"none" filter on method names' => [ |
81
|
|
|
['Methods' => 'none'], |
82
|
|
|
2, |
83
|
|
|
], |
84
|
|
|
'"any" filter on method names' => [ |
85
|
|
|
['Methods' => 'any'], |
86
|
|
|
3, |
87
|
|
|
], |
88
|
|
|
]; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|