silverstripe /
silverstripe-auditor
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SilverStripe\Auditor\Tests; |
||
| 4 | |||
| 5 | use PHPUnit_Framework_MockObject_MockObject; |
||
| 6 | use SilverStripe\Auditor\Tests\AuditHookTest\Logger; |
||
| 7 | use SilverStripe\Control\HTTPRequest; |
||
| 8 | use SilverStripe\Control\Session; |
||
| 9 | use SilverStripe\Core\Injector\Injector; |
||
| 10 | use SilverStripe\Dev\SapphireTest; |
||
| 11 | use SilverStripe\MFA\Authenticator\LoginHandler; |
||
|
0 ignored issues
–
show
|
|||
| 12 | use SilverStripe\MFA\Authenticator\MemberAuthenticator; |
||
|
0 ignored issues
–
show
The type
SilverStripe\MFA\Authenticator\MemberAuthenticator was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 13 | use SilverStripe\MFA\Method\MethodInterface; |
||
|
0 ignored issues
–
show
The type
SilverStripe\MFA\Method\MethodInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 14 | use SilverStripe\Security\Member; |
||
| 15 | |||
| 16 | class AuditHookMFATest extends SapphireTest |
||
| 17 | { |
||
| 18 | protected static $fixture_file = 'AuditHookMFATest.yml'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var Logger |
||
| 22 | */ |
||
| 23 | protected $writer; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var LoginHandler |
||
| 27 | */ |
||
| 28 | protected $handler; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var Member |
||
| 32 | */ |
||
| 33 | protected $member; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var MethodInterface|PHPUnit_Framework_MockObject_MockObject |
||
| 37 | */ |
||
| 38 | protected $method; |
||
| 39 | |||
| 40 | protected function setUp() |
||
| 41 | { |
||
| 42 | parent::setUp(); |
||
| 43 | |||
| 44 | if (!interface_exists(MethodInterface::class)) { |
||
| 45 | $this->markTestSkipped('This test requires the silverstripe/mfa module to be installed'); |
||
| 46 | return; |
||
| 47 | } |
||
| 48 | |||
| 49 | $this->writer = new Logger; |
||
| 50 | |||
| 51 | // Phase singleton out, so the message log is purged. |
||
| 52 | Injector::inst()->unregisterNamedObject('AuditLogger'); |
||
| 53 | Injector::inst()->registerService($this->writer, 'AuditLogger'); |
||
| 54 | |||
| 55 | $this->handler = new LoginHandler('foo', $this->createMock(MemberAuthenticator::class)); |
||
| 56 | $this->handler->setRequest(new HTTPRequest('GET', '/')); |
||
| 57 | $this->handler->getRequest()->setSession(new Session([])); |
||
| 58 | |||
| 59 | $this->member = $this->objFromFixture(Member::class, 'leslie_lawless'); |
||
| 60 | $this->method = $this->createMock(MethodInterface::class); |
||
| 61 | } |
||
| 62 | |||
| 63 | public function testOnRegisterMethod() |
||
| 64 | { |
||
| 65 | $this->handler->extend('onRegisterMethod', $this->member, $this->method); |
||
| 66 | |||
| 67 | $message = $this->writer->getLastMessage(); |
||
| 68 | $this->assertContains('[email protected]', $message); |
||
| 69 | $this->assertContains('registered MFA method', $message); |
||
| 70 | $this->assertContains('MethodInterface', $message, 'Method class name is in context'); |
||
| 71 | } |
||
| 72 | |||
| 73 | public function testOnRegisterMethodFailure() |
||
| 74 | { |
||
| 75 | $this->handler->extend('onRegisterMethodFailure', $this->member, $this->method); |
||
| 76 | |||
| 77 | $message = $this->writer->getLastMessage(); |
||
| 78 | $this->assertContains('[email protected]', $message); |
||
| 79 | $this->assertContains('failed registering new MFA method', $message); |
||
| 80 | $this->assertContains('MethodInterface', $message, 'Method class name is in context'); |
||
| 81 | } |
||
| 82 | |||
| 83 | public function testOnMethodVerificationFailure() |
||
| 84 | { |
||
| 85 | $this->member->config()->set('lock_out_after_incorrect_logins', 0); |
||
| 86 | $this->handler->extend('onMethodVerificationFailure', $this->member, $this->method); |
||
| 87 | |||
| 88 | $message = $this->writer->getLastMessage(); |
||
| 89 | $this->assertContains('[email protected]', $message); |
||
| 90 | $this->assertContains('failed to verify using MFA method', $message); |
||
| 91 | $this->assertContains('MethodInterface', $message, 'Method class name is in context'); |
||
| 92 | $this->assertNotContains('attempt_limit', $message); |
||
| 93 | } |
||
| 94 | |||
| 95 | public function testOnMethodVerificationFailureWithLockoutConfiguration() |
||
| 96 | { |
||
| 97 | $this->member->config()->set('lock_out_after_incorrect_logins', 5); |
||
| 98 | $this->member->registerFailedLogin(); |
||
| 99 | $this->member->registerFailedLogin(); |
||
| 100 | $this->member->registerFailedLogin(); |
||
| 101 | $this->handler->extend('onMethodVerificationFailure', $this->member, $this->method); |
||
| 102 | |||
| 103 | $message = $this->writer->getLastMessage(); |
||
| 104 | $this->assertContains('[email protected]', $message); |
||
| 105 | $this->assertContains('failed to verify using MFA method', $message); |
||
| 106 | $this->assertContains('MethodInterface', $message, 'Method class name is in context'); |
||
| 107 | // NB: json format is defined by AuditHookTest\Logger::log() |
||
| 108 | $this->assertContains('"attempts":3', $message); |
||
| 109 | $this->assertContains('"attempt_limit":5', $message); |
||
| 110 | } |
||
| 111 | |||
| 112 | public function testOnSkipRegistration() |
||
| 113 | { |
||
| 114 | $this->handler->extend('onSkipRegistration', $this->member, $this->method); |
||
| 115 | |||
| 116 | $message = $this->writer->getLastMessage(); |
||
| 117 | $this->assertContains('[email protected]', $message); |
||
| 118 | $this->assertContains('skipped MFA registration', $message); |
||
| 119 | } |
||
| 120 | |||
| 121 | public function testOnMethodVerificationSuccess() |
||
| 122 | { |
||
| 123 | $this->handler->extend('onMethodVerificationSuccess', $this->member, $this->method); |
||
| 124 | |||
| 125 | $message = $this->writer->getLastMessage(); |
||
| 126 | $this->assertContains('[email protected]', $message); |
||
| 127 | $this->assertContains('successfully verified using MFA method', $message); |
||
| 128 | $this->assertContains('MethodInterface', $message, 'Method class name is in context'); |
||
| 129 | } |
||
| 130 | } |
||
| 131 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths