1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\SecurityReport\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\Config\Config; |
6
|
|
|
use SilverStripe\ORM\ArrayList; |
7
|
|
|
use SilverStripe\Security\Group; |
8
|
|
|
use SilverStripe\Security\Member; |
9
|
|
|
use SilverStripe\Security\Security; |
10
|
|
|
use SilverStripe\SecurityReport\MemberReportExtension; |
11
|
|
|
use SilverStripe\Reports\Report; |
12
|
|
|
use SilverStripe\Dev\SapphireTest; |
13
|
|
|
use SilverStripe\SecurityReport\UserSecurityReport; |
14
|
|
|
use SilverStripe\Subsites\Extensions\GroupSubsites; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* User Security Report Tests. |
18
|
|
|
* |
19
|
|
|
* @author Michael Parkhill <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class UserSecurityReportTest extends SapphireTest |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
protected static $fixture_file = 'UserSecurityReportTest.yml'; |
25
|
|
|
|
26
|
|
|
protected $records; |
27
|
|
|
protected $report; |
28
|
|
|
|
29
|
|
|
protected static $required_extensions = [ |
30
|
|
|
Member::class => [ |
31
|
|
|
MemberReportExtension::class, |
32
|
|
|
], |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
protected static $illegal_extensions = [ |
36
|
|
|
Group::class => [ |
37
|
|
|
GroupSubsites::class, |
38
|
|
|
], |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Utility method for all tests to use. |
43
|
|
|
* |
44
|
|
|
* @return ArrayList |
45
|
|
|
* @todo pre-fill the report with fixture-defined users |
46
|
|
|
*/ |
47
|
|
|
protected function setUp() |
48
|
|
|
{ |
49
|
|
|
parent::setUp(); |
50
|
|
|
$reports = Report::get_reports(); |
51
|
|
|
$report = $reports[UserSecurityReport::class]; |
52
|
|
|
$this->report = $report; |
53
|
|
|
$this->records = $report->sourceRecords()->toArray(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testSourceRecords() |
57
|
|
|
{ |
58
|
|
|
$this->assertNotEmpty($this->records); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testGetMemberGroups() |
62
|
|
|
{ |
63
|
|
|
//getMemberGroups(&$member) returns string |
64
|
|
|
$member = $this->objFromFixture(Member::class, 'member-has-0-groups'); |
65
|
|
|
$groups = $member->GroupsDescription; |
66
|
|
|
$this->assertEquals('Not in a Security Group', $groups); |
67
|
|
|
|
68
|
|
|
$member = $this->objFromFixture(Member::class, 'member-has-1-groups'); |
69
|
|
|
$groups = $member->GroupsDescription; |
70
|
|
|
$this->assertEquals('Group Test 01', $groups); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testGetMemberPermissions() |
74
|
|
|
{ |
75
|
|
|
$member = $this->objFromFixture(Member::class, 'member-has-0-permissions'); |
76
|
|
|
$perms = $member->PermissionsDescription; |
77
|
|
|
$this->assertEquals('No Permissions', $perms); |
78
|
|
|
|
79
|
|
|
$member = $this->objFromFixture(Member::class, 'member-has-1-permissions'); |
80
|
|
|
$perms = $member->PermissionsDescription; |
81
|
|
|
$this->assertEquals('Full administrative rights', $perms); |
82
|
|
|
|
83
|
|
|
$member = $this->objFromFixture(Member::class, 'member-has-n-permissions'); |
84
|
|
|
$perms = $member->PermissionsDescription; |
85
|
|
|
$this->assertEquals('Full administrative rights, Edit any page', $perms); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testLoginLoggingColumnShowsOnlyWhenApplicable() |
89
|
|
|
{ |
90
|
|
|
$original = Config::inst()->get(Security::class, 'login_recording'); |
91
|
|
|
|
92
|
|
|
Config::modify()->set(Security::class, 'login_recording', true); |
93
|
|
|
$this->assertContains('LastLoggedIn', array_keys($this->report->columns())); |
94
|
|
|
|
95
|
|
|
Config::modify()->set(Security::class, 'login_recording', false); |
96
|
|
|
$this->assertNotContains('LastLoggedIn', array_keys($this->report->columns())); |
97
|
|
|
|
98
|
|
|
Config::modify()->set(Security::class, 'login_recording', $original); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|