|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\SecurityExtensions\Tests\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
6
|
|
|
use SilverStripe\Dev\FunctionalTest; |
|
7
|
|
|
use SilverStripe\Security\Member; |
|
8
|
|
|
use SilverStripe\Security\MemberAuthenticator\LoginHandler; |
|
9
|
|
|
use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator; |
|
10
|
|
|
use SilverStripe\Security\Security; |
|
11
|
|
|
use SilverStripe\SecurityExtensions\Control\SudoModeController; |
|
12
|
|
|
use SilverStripe\SecurityExtensions\Extension\SudoModeOnLoginExtension; |
|
13
|
|
|
|
|
14
|
|
|
class SudoModeOnLoginExtensionTest extends FunctionalTest |
|
15
|
|
|
{ |
|
16
|
|
|
protected static $required_extensions = [ |
|
17
|
|
|
LoginHandler::class => [ |
|
18
|
|
|
SudoModeOnLoginExtension::class, |
|
19
|
|
|
], |
|
20
|
|
|
]; |
|
21
|
|
|
|
|
22
|
|
|
protected function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
parent::setUp(); |
|
25
|
|
|
|
|
26
|
|
|
// Disable MFA on account |
|
27
|
|
|
Injector::inst()->load([ |
|
28
|
|
|
Security::class => [ |
|
29
|
|
|
'properties' => [ |
|
30
|
|
|
'Authenticators' => [ |
|
31
|
|
|
'default' => '%$' . MemberAuthenticator::class, |
|
32
|
|
|
], |
|
33
|
|
|
], |
|
34
|
|
|
], |
|
35
|
|
|
]); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testSudoModeActivatesOnLogin() |
|
39
|
|
|
{ |
|
40
|
|
|
// Explicitly update a fixtured member's password |
|
41
|
|
|
$memberID = $this->logInWithPermission(); |
|
42
|
|
|
/** @var Member $member */ |
|
43
|
|
|
$member = Member::get()->byID($memberID); |
|
44
|
|
|
$member->changePassword('0p3nS3samE!'); |
|
45
|
|
|
$this->logOut(); |
|
46
|
|
|
|
|
47
|
|
|
// Perform a login using the new password |
|
48
|
|
|
$this->autoFollowRedirection = true; |
|
49
|
|
|
$this->get(Security::login_url()); |
|
50
|
|
|
$response = $this->submitForm('MemberLoginForm_LoginForm', 'action_doLogin', [ |
|
51
|
|
|
'Email' => $member->Email, |
|
52
|
|
|
'Password' => '0p3nS3samE!', |
|
53
|
|
|
]); |
|
54
|
|
|
$this->assertSame(200, $response->getStatusCode()); |
|
55
|
|
|
|
|
56
|
|
|
// Check to ensure that sudo mode is enabled for the current user |
|
57
|
|
|
$checkResponse = $this->get(SudoModeController::singleton()->Link('check')); |
|
58
|
|
|
$this->assertSame(200, $checkResponse->getStatusCode()); |
|
59
|
|
|
$body = json_decode((string) $checkResponse->getBody(), true); |
|
60
|
|
|
$this->assertTrue($body['active']); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|