|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Firesphere\BootstrapMFA\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Firesphere\BootstrapMFA\Authenticators\BootstrapMFAAuthenticator; |
|
6
|
|
|
use Firesphere\BootstrapMFA\Handlers\BootstrapMFAChangePasswordHandler; |
|
7
|
|
|
use Firesphere\BootstrapMFA\Tests\Helpers\CodeHelper; |
|
8
|
|
|
use SilverStripe\Control\Controller; |
|
9
|
|
|
use SilverStripe\Control\HTTPResponse; |
|
10
|
|
|
use SilverStripe\Control\Session; |
|
11
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
12
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
13
|
|
|
use SilverStripe\Security\IdentityStore; |
|
14
|
|
|
use SilverStripe\Security\Member; |
|
15
|
|
|
use SilverStripe\Security\MemberAuthenticator\ChangePasswordForm; |
|
16
|
|
|
|
|
17
|
|
|
class BootstrapMFAChangePasswordHandlerTest extends SapphireTest |
|
18
|
|
|
{ |
|
19
|
|
|
protected static $fixture_file = '../fixtures/member.yml'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var Controller |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $controller; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var BootstrapMFAAuthenticator |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $authenticator; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var BootstrapMFAChangePasswordHandler |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $handler; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var ChangePasswordForm |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $form; |
|
40
|
|
|
|
|
41
|
|
|
public function testDoChangePassword() |
|
42
|
|
|
{ |
|
43
|
|
|
$user = $this->objFromFixture(Member::class, 'member1'); |
|
44
|
|
|
Injector::inst()->get(IdentityStore::class)->logIn($user); |
|
45
|
|
|
|
|
46
|
|
|
$data = [ |
|
47
|
|
|
'OldPassword' => 'password1', |
|
48
|
|
|
'NewPassword1' => 'password', |
|
49
|
|
|
'NewPassword2' => 'password', |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
$response = $this->handler->doChangePassword($data, $this->form); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertInstanceOf(HTTPResponse::class, $response); |
|
55
|
|
|
$codes = CodeHelper::getCodesFromSession(); |
|
56
|
|
|
$this->assertEquals(15, count($codes)); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
protected function setUp() |
|
60
|
|
|
{ |
|
61
|
|
|
parent::setUp(); |
|
62
|
|
|
$this->controller = Controller::curr(); |
|
63
|
|
|
$request = $this->controller->getRequest(); |
|
64
|
|
|
$request->setSession(new Session(['test' => 'test'])); |
|
65
|
|
|
$this->authenticator = Injector::inst()->create(BootstrapMFAAuthenticator::class); |
|
66
|
|
|
$this->form = Injector::inst()->createWithArgs( |
|
67
|
|
|
ChangePasswordForm::class, |
|
68
|
|
|
[$this->controller, 'changepassword'] |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
$this->handler = Injector::inst()->createWithArgs( |
|
72
|
|
|
BootstrapMFAChangePasswordHandler::class, |
|
73
|
|
|
['changepassword', $this->authenticator] |
|
74
|
|
|
); |
|
75
|
|
|
$this->handler->setRequest($request); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|