@@ -81,7 +81,6 @@ |
||
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * @param string $uid |
| 84 | - * @param Throttle $throttle |
|
| 85 | 84 | */ |
| 86 | 85 | public function failedLoginCallback($uid) { |
| 87 | 86 | $this->throttle->addFailedLoginAttempt($uid, $this->request->getRemoteAddress()); |
@@ -1,6 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - |
|
| 4 | 3 | * |
| 5 | 4 | * @author Semih Serhat Karakaya |
| 6 | 5 | * @copyright Copyright (c) 2016, ITU IT HEAD OFFICE. |
@@ -45,15 +44,15 @@ discard block |
||
| 45 | 44 | |
| 46 | 45 | /** @var PasswordValidator */ |
| 47 | 46 | private $passValidator; |
| 48 | - /** @var EventDispatcherInterface */ |
|
| 49 | - private $dispatcher; |
|
| 47 | + /** @var EventDispatcherInterface */ |
|
| 48 | + private $dispatcher; |
|
| 50 | 49 | |
| 51 | 50 | /** |
| 52 | 51 | * @param IUserManager $userManager |
| 53 | 52 | * @param Throttle $throttle |
| 54 | 53 | * @param IRequest $request |
| 55 | - * @param PasswordValidator $passValidator |
|
| 56 | - * @param EventDispatcherInterface $dispatcher |
|
| 54 | + * @param PasswordValidator $passValidator |
|
| 55 | + * @param EventDispatcherInterface $dispatcher |
|
| 57 | 56 | */ |
| 58 | 57 | public function __construct($userManager, $throttle, $request, $passValidator, $dispatcher){ |
| 59 | 58 | $this->userManager = $userManager; |
@@ -73,9 +72,9 @@ discard block |
||
| 73 | 72 | $this->postLoginCallback($user); |
| 74 | 73 | }); |
| 75 | 74 | |
| 76 | - $this->dispatcher->addListener('OCP\User::validatePassword', function(GenericEvent $event) { |
|
| 77 | - $this->passValidator->validate($event->getArgument('password')); |
|
| 78 | - }); |
|
| 75 | + $this->dispatcher->addListener('OCP\User::validatePassword', function(GenericEvent $event) { |
|
| 76 | + $this->passValidator->validate($event->getArgument('password')); |
|
| 77 | + }); |
|
| 79 | 78 | |
| 80 | 79 | } |
| 81 | 80 | |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | * @param PasswordValidator $passValidator |
| 56 | 56 | * @param EventDispatcherInterface $dispatcher |
| 57 | 57 | */ |
| 58 | - public function __construct($userManager, $throttle, $request, $passValidator, $dispatcher){ |
|
| 58 | + public function __construct($userManager, $throttle, $request, $passValidator, $dispatcher) { |
|
| 59 | 59 | $this->userManager = $userManager; |
| 60 | 60 | $this->throttle = $throttle; |
| 61 | 61 | $this->request = $request; |
@@ -20,9 +20,9 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | namespace OCA\Security\Tests\Controller; |
| 22 | 22 | |
| 23 | -use OCA\Security\Controller\SettingsController; |
|
| 24 | -use OCA\Security\SecurityConfig; |
|
| 25 | -use OCP\IRequest; |
|
| 23 | +use OCA\Security\Controller\SettingsController; |
|
| 24 | +use OCA\Security\SecurityConfig; |
|
| 25 | +use OCP\IRequest; |
|
| 26 | 26 | use Test\TestCase; |
| 27 | 27 | |
| 28 | 28 | class SettingsControllerTest extends TestCase {
|
@@ -26,32 +26,32 @@ |
||
| 26 | 26 | use Test\TestCase; |
| 27 | 27 | |
| 28 | 28 | class SettingsControllerTest extends TestCase {
|
| 29 | - /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */ |
|
| 30 | - private $request; |
|
| 31 | - /** @var SecurityConfig|\PHPUnit_Framework_MockObject_MockObject */ |
|
| 32 | - private $config; |
|
| 33 | - /** @var SettingsController */ |
|
| 34 | - private $controller; |
|
| 35 | - protected function setUp() {
|
|
| 36 | - parent::setUp(); |
|
| 37 | - $this->request = $this->getMockBuilder(IRequest::class)->getMock(); |
|
| 38 | - $this->config = $this->getMockBuilder(SecurityConfig::class) |
|
| 39 | - ->disableOriginalConstructor() |
|
| 40 | - ->getMock(); |
|
| 41 | - $this->controller = new SettingsController('security', $this->request, $this->config);
|
|
| 42 | - } |
|
| 43 | - public function testState() {
|
|
| 44 | - $expected = [ |
|
| 45 | - 'bruteForceProtectionState' => true, |
|
| 46 | - 'minPassLength' => 8, |
|
| 47 | - 'enforceUpperLowerState' => true, |
|
| 48 | - 'enforceNumericalCharactersState' => true, |
|
| 49 | - 'enforceSpecialCharactersState' => true |
|
| 50 | - ]; |
|
| 51 | - $this->config->expects($this->exactly(1)) |
|
| 52 | - ->method('getAllSecurityConfigs')
|
|
| 53 | - ->willReturn($expected); |
|
| 29 | + /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */ |
|
| 30 | + private $request; |
|
| 31 | + /** @var SecurityConfig|\PHPUnit_Framework_MockObject_MockObject */ |
|
| 32 | + private $config; |
|
| 33 | + /** @var SettingsController */ |
|
| 34 | + private $controller; |
|
| 35 | + protected function setUp() {
|
|
| 36 | + parent::setUp(); |
|
| 37 | + $this->request = $this->getMockBuilder(IRequest::class)->getMock(); |
|
| 38 | + $this->config = $this->getMockBuilder(SecurityConfig::class) |
|
| 39 | + ->disableOriginalConstructor() |
|
| 40 | + ->getMock(); |
|
| 41 | + $this->controller = new SettingsController('security', $this->request, $this->config);
|
|
| 42 | + } |
|
| 43 | + public function testState() {
|
|
| 44 | + $expected = [ |
|
| 45 | + 'bruteForceProtectionState' => true, |
|
| 46 | + 'minPassLength' => 8, |
|
| 47 | + 'enforceUpperLowerState' => true, |
|
| 48 | + 'enforceNumericalCharactersState' => true, |
|
| 49 | + 'enforceSpecialCharactersState' => true |
|
| 50 | + ]; |
|
| 51 | + $this->config->expects($this->exactly(1)) |
|
| 52 | + ->method('getAllSecurityConfigs')
|
|
| 53 | + ->willReturn($expected); |
|
| 54 | 54 | |
| 55 | - $this->assertEquals($expected, $this->controller->state()); |
|
| 56 | - } |
|
| 55 | + $this->assertEquals($expected, $this->controller->state()); |
|
| 56 | + } |
|
| 57 | 57 | } |
| 58 | 58 | \ No newline at end of file |
@@ -22,9 +22,9 @@ |
||
| 22 | 22 | |
| 23 | 23 | namespace OCA\Security\Tests\Db; |
| 24 | 24 | |
| 25 | -use OCA\Security\Db\DbService; |
|
| 26 | -use OC\AppFramework\Utility\TimeFactory; |
|
| 27 | -use OCP\IDBConnection; |
|
| 25 | +use OCA\Security\Db\DbService; |
|
| 26 | +use OC\AppFramework\Utility\TimeFactory; |
|
| 27 | +use OCP\IDBConnection; |
|
| 28 | 28 | use Test\TestCase; |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | - * @param array $mockedMethods |
|
| 46 | + * @param string[] $mockedMethods |
|
| 47 | 47 | * @return PasswordValidator | \PHPUnit_Framework_MockObject_MockObject |
| 48 | 48 | */ |
| 49 | 49 | private function getMockInstance($mockedMethods = []) {
|
@@ -19,10 +19,10 @@ |
||
| 19 | 19 | * |
| 20 | 20 | */ |
| 21 | 21 | namespace OCA\Password_Policy\Tests; |
| 22 | -use OC\HintException; |
|
| 23 | -use OCA\Security\SecurityConfig; |
|
| 24 | -use OCA\Security\PasswordValidator; |
|
| 25 | -use OCP\IL10N; |
|
| 22 | +use OC\HintException; |
|
| 23 | +use OCA\Security\SecurityConfig; |
|
| 24 | +use OCA\Security\PasswordValidator; |
|
| 25 | +use OCP\IL10N; |
|
| 26 | 26 | use Test\TestCase; |
| 27 | 27 | class PasswordValidatorTest extends TestCase {
|
| 28 | 28 | |
@@ -26,155 +26,155 @@ |
||
| 26 | 26 | use Test\TestCase; |
| 27 | 27 | class PasswordValidatorTest extends TestCase {
|
| 28 | 28 | |
| 29 | - /** @var SecurityConfig|\PHPUnit_Framework_MockObject_MockObject */ |
|
| 30 | - private $config; |
|
| 29 | + /** @var SecurityConfig|\PHPUnit_Framework_MockObject_MockObject */ |
|
| 30 | + private $config; |
|
| 31 | 31 | |
| 32 | - /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ |
|
| 33 | - private $l10n; |
|
| 32 | + /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ |
|
| 33 | + private $l10n; |
|
| 34 | 34 | |
| 35 | - /** @var PasswordValidator */ |
|
| 36 | - private $passValidator; |
|
| 35 | + /** @var PasswordValidator */ |
|
| 36 | + private $passValidator; |
|
| 37 | 37 | |
| 38 | - public function setUp() {
|
|
| 39 | - parent::setUp(); |
|
| 40 | - $this->l10n = $this->createMock(IL10N::class); |
|
| 41 | - $this->config = $this->createMock(SecurityConfig::class); |
|
| 42 | - $this->passValidator = new PasswordValidator($this->config, $this->l10n); |
|
| 43 | - } |
|
| 38 | + public function setUp() {
|
|
| 39 | + parent::setUp(); |
|
| 40 | + $this->l10n = $this->createMock(IL10N::class); |
|
| 41 | + $this->config = $this->createMock(SecurityConfig::class); |
|
| 42 | + $this->passValidator = new PasswordValidator($this->config, $this->l10n); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param array $mockedMethods |
|
| 47 | - * @return PasswordValidator | \PHPUnit_Framework_MockObject_MockObject |
|
| 48 | - */ |
|
| 49 | - private function getMockInstance($mockedMethods = []) {
|
|
| 50 | - $passwordValidator = $this->getMockBuilder('OCA\Security\PasswordValidator')
|
|
| 51 | - ->setConstructorArgs([$this->config, $this->l10n]) |
|
| 52 | - ->setMethods($mockedMethods)->getMock(); |
|
| 53 | - return $passwordValidator; |
|
| 54 | - } |
|
| 45 | + /** |
|
| 46 | + * @param array $mockedMethods |
|
| 47 | + * @return PasswordValidator | \PHPUnit_Framework_MockObject_MockObject |
|
| 48 | + */ |
|
| 49 | + private function getMockInstance($mockedMethods = []) {
|
|
| 50 | + $passwordValidator = $this->getMockBuilder('OCA\Security\PasswordValidator')
|
|
| 51 | + ->setConstructorArgs([$this->config, $this->l10n]) |
|
| 52 | + ->setMethods($mockedMethods)->getMock(); |
|
| 53 | + return $passwordValidator; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function testCheckPasswordLength() {
|
|
| 57 | - $this->config->expects($this->exactly(1))->method('getMinPasswordLength')->willReturn(4);
|
|
| 58 | - $this->passValidator->checkPasswordLength('password');
|
|
| 59 | - } |
|
| 60 | - /** |
|
| 61 | - * @expectedException \OC\HintException |
|
| 62 | - */ |
|
| 63 | - public function testCheckPasswordLengthFail() {
|
|
| 64 | - $this->config->expects($this->exactly(1))->method('getMinPasswordLength')->willReturn(4);
|
|
| 65 | - $this->passValidator->checkPasswordLength('123');
|
|
| 66 | - } |
|
| 67 | - /** |
|
| 68 | - * @dataProvider dataTestCheckUpperLowerCase |
|
| 69 | - * |
|
| 70 | - * @param string $password |
|
| 71 | - * @param bool $enforceUpperLowerCase |
|
| 72 | - */ |
|
| 73 | - public function testCheckUpperLowerCase($password, $enforceUpperLowerCase) {
|
|
| 74 | - $this->config->expects($this->once())->method('getIsUpperLowerCaseEnforced')
|
|
| 75 | - ->willReturn($enforceUpperLowerCase); |
|
| 76 | - $this->passValidator->checkUpperLowerCase($password); |
|
| 77 | - } |
|
| 78 | - public function dataTestCheckUpperLowerCase() {
|
|
| 79 | - return [ |
|
| 80 | - ['testPass', true], |
|
| 81 | - ['Testpass', true], |
|
| 82 | - ['testpass', false], |
|
| 83 | - ['TESTPASS', false], |
|
| 84 | - ]; |
|
| 85 | - } |
|
| 86 | - /** |
|
| 87 | - * @dataProvider dataTestCheckUpperLowerCaseFail |
|
| 88 | - * @param string $password |
|
| 89 | - * @expectedException \OC\HintException |
|
| 90 | - */ |
|
| 91 | - public function testCheckUpperLowerCaseFail($password) {
|
|
| 92 | - $this->config->expects($this->once())->method('getIsUpperLowerCaseEnforced')->willReturn(true);
|
|
| 93 | - $this->passValidator->checkUpperLowerCase($password); |
|
| 94 | - } |
|
| 95 | - public function dataTestCheckUpperLowerCaseFail() {
|
|
| 96 | - return [ |
|
| 97 | - ['TESTPASS'], ['testpass'] |
|
| 98 | - ]; |
|
| 99 | - } |
|
| 100 | - /** |
|
| 101 | - * @dataProvider dataTestCheckNumericCharacters |
|
| 102 | - * |
|
| 103 | - * @param string $password |
|
| 104 | - * @param bool $enforceNumericCharacters |
|
| 105 | - */ |
|
| 106 | - public function testCheckNumericCharacters($password, $enforceNumericCharacters) {
|
|
| 107 | - $this->config->expects($this->once())->method('getIsNumericCharactersEnforced')->willReturn($enforceNumericCharacters);
|
|
| 108 | - $this->passValidator->checkNumericCharacters($password); |
|
| 109 | - } |
|
| 110 | - public function dataTestCheckNumericCharacters() {
|
|
| 111 | - return [ |
|
| 112 | - ['testPass1', true], |
|
| 113 | - ['testpass', false] |
|
| 114 | - ]; |
|
| 115 | - } |
|
| 116 | - /** |
|
| 117 | - * @dataProvider dataTestCheckNumericCharactersFail |
|
| 118 | - * @param string $password |
|
| 119 | - * @expectedException \OC\HintException |
|
| 120 | - */ |
|
| 121 | - public function testCheckNumericCharactersFail($password) {
|
|
| 122 | - $this->config->expects($this->once())->method('getIsNumericCharactersEnforced')->willReturn(true);
|
|
| 123 | - $this->passValidator->checkNumericCharacters($password); |
|
| 124 | - } |
|
| 125 | - public function dataTestCheckNumericCharactersFail() {
|
|
| 126 | - return [ |
|
| 127 | - ['testpass'], |
|
| 128 | - ['TestPass%'], |
|
| 129 | - ['TEST*PASS'] |
|
| 130 | - ]; |
|
| 131 | - } |
|
| 132 | - /** |
|
| 133 | - * @dataProvider dataTestCheckSpecialCharacters |
|
| 134 | - * |
|
| 135 | - * @param string $password |
|
| 136 | - * @param bool $enforceSpecialCharacters |
|
| 137 | - */ |
|
| 138 | - public function testCheckSpecialCharacters($password, $enforceSpecialCharacters) {
|
|
| 139 | - $this->config->expects($this->once())->method('getIsSpecialCharactersEnforced')->willReturn($enforceSpecialCharacters);
|
|
| 140 | - $this->passValidator->checkSpecialCharacters($password); |
|
| 141 | - } |
|
| 142 | - public function dataTestCheckSpecialCharacters() {
|
|
| 143 | - return [ |
|
| 144 | - ['testPass%', true], |
|
| 145 | - ['testpass', false] |
|
| 146 | - ]; |
|
| 147 | - } |
|
| 148 | - /** |
|
| 149 | - * @dataProvider dataTestCheckSpecialCharactersFail |
|
| 150 | - * @param string $password |
|
| 151 | - * @expectedException \OC\HintException |
|
| 152 | - */ |
|
| 153 | - public function testCheckSpecialCharactersFail($password) {
|
|
| 154 | - $this->config->expects($this->once())->method('getIsSpecialCharactersEnforced')->willReturn(true);
|
|
| 155 | - $this->passValidator->checkSpecialCharacters($password); |
|
| 156 | - } |
|
| 157 | - public function dataTestCheckSpecialCharactersFail() {
|
|
| 158 | - return [ |
|
| 159 | - ['testpass'], |
|
| 160 | - ['TestPass1'], |
|
| 161 | - ['TEST2PASS'] |
|
| 162 | - ]; |
|
| 163 | - } |
|
| 164 | - public function testValidate() {
|
|
| 165 | - $password = 'password'; |
|
| 166 | - $instance = $this->getMockInstance( |
|
| 167 | - [ |
|
| 168 | - 'checkPasswordLength', |
|
| 169 | - 'checkUpperLowerCase', |
|
| 170 | - 'checkNumericCharacters', |
|
| 171 | - 'checkSpecialCharacters', |
|
| 172 | - ] |
|
| 173 | - ); |
|
| 174 | - $instance->expects($this->once())->method('checkPasswordLength')->with($password);
|
|
| 175 | - $instance->expects($this->once())->method('checkUpperLowerCase')->with($password);
|
|
| 176 | - $instance->expects($this->once())->method('checkNumericCharacters')->with($password);
|
|
| 177 | - $instance->expects($this->once())->method('checkSpecialCharacters')->with($password);
|
|
| 178 | - $instance->validate($password); |
|
| 179 | - } |
|
| 56 | + public function testCheckPasswordLength() {
|
|
| 57 | + $this->config->expects($this->exactly(1))->method('getMinPasswordLength')->willReturn(4);
|
|
| 58 | + $this->passValidator->checkPasswordLength('password');
|
|
| 59 | + } |
|
| 60 | + /** |
|
| 61 | + * @expectedException \OC\HintException |
|
| 62 | + */ |
|
| 63 | + public function testCheckPasswordLengthFail() {
|
|
| 64 | + $this->config->expects($this->exactly(1))->method('getMinPasswordLength')->willReturn(4);
|
|
| 65 | + $this->passValidator->checkPasswordLength('123');
|
|
| 66 | + } |
|
| 67 | + /** |
|
| 68 | + * @dataProvider dataTestCheckUpperLowerCase |
|
| 69 | + * |
|
| 70 | + * @param string $password |
|
| 71 | + * @param bool $enforceUpperLowerCase |
|
| 72 | + */ |
|
| 73 | + public function testCheckUpperLowerCase($password, $enforceUpperLowerCase) {
|
|
| 74 | + $this->config->expects($this->once())->method('getIsUpperLowerCaseEnforced')
|
|
| 75 | + ->willReturn($enforceUpperLowerCase); |
|
| 76 | + $this->passValidator->checkUpperLowerCase($password); |
|
| 77 | + } |
|
| 78 | + public function dataTestCheckUpperLowerCase() {
|
|
| 79 | + return [ |
|
| 80 | + ['testPass', true], |
|
| 81 | + ['Testpass', true], |
|
| 82 | + ['testpass', false], |
|
| 83 | + ['TESTPASS', false], |
|
| 84 | + ]; |
|
| 85 | + } |
|
| 86 | + /** |
|
| 87 | + * @dataProvider dataTestCheckUpperLowerCaseFail |
|
| 88 | + * @param string $password |
|
| 89 | + * @expectedException \OC\HintException |
|
| 90 | + */ |
|
| 91 | + public function testCheckUpperLowerCaseFail($password) {
|
|
| 92 | + $this->config->expects($this->once())->method('getIsUpperLowerCaseEnforced')->willReturn(true);
|
|
| 93 | + $this->passValidator->checkUpperLowerCase($password); |
|
| 94 | + } |
|
| 95 | + public function dataTestCheckUpperLowerCaseFail() {
|
|
| 96 | + return [ |
|
| 97 | + ['TESTPASS'], ['testpass'] |
|
| 98 | + ]; |
|
| 99 | + } |
|
| 100 | + /** |
|
| 101 | + * @dataProvider dataTestCheckNumericCharacters |
|
| 102 | + * |
|
| 103 | + * @param string $password |
|
| 104 | + * @param bool $enforceNumericCharacters |
|
| 105 | + */ |
|
| 106 | + public function testCheckNumericCharacters($password, $enforceNumericCharacters) {
|
|
| 107 | + $this->config->expects($this->once())->method('getIsNumericCharactersEnforced')->willReturn($enforceNumericCharacters);
|
|
| 108 | + $this->passValidator->checkNumericCharacters($password); |
|
| 109 | + } |
|
| 110 | + public function dataTestCheckNumericCharacters() {
|
|
| 111 | + return [ |
|
| 112 | + ['testPass1', true], |
|
| 113 | + ['testpass', false] |
|
| 114 | + ]; |
|
| 115 | + } |
|
| 116 | + /** |
|
| 117 | + * @dataProvider dataTestCheckNumericCharactersFail |
|
| 118 | + * @param string $password |
|
| 119 | + * @expectedException \OC\HintException |
|
| 120 | + */ |
|
| 121 | + public function testCheckNumericCharactersFail($password) {
|
|
| 122 | + $this->config->expects($this->once())->method('getIsNumericCharactersEnforced')->willReturn(true);
|
|
| 123 | + $this->passValidator->checkNumericCharacters($password); |
|
| 124 | + } |
|
| 125 | + public function dataTestCheckNumericCharactersFail() {
|
|
| 126 | + return [ |
|
| 127 | + ['testpass'], |
|
| 128 | + ['TestPass%'], |
|
| 129 | + ['TEST*PASS'] |
|
| 130 | + ]; |
|
| 131 | + } |
|
| 132 | + /** |
|
| 133 | + * @dataProvider dataTestCheckSpecialCharacters |
|
| 134 | + * |
|
| 135 | + * @param string $password |
|
| 136 | + * @param bool $enforceSpecialCharacters |
|
| 137 | + */ |
|
| 138 | + public function testCheckSpecialCharacters($password, $enforceSpecialCharacters) {
|
|
| 139 | + $this->config->expects($this->once())->method('getIsSpecialCharactersEnforced')->willReturn($enforceSpecialCharacters);
|
|
| 140 | + $this->passValidator->checkSpecialCharacters($password); |
|
| 141 | + } |
|
| 142 | + public function dataTestCheckSpecialCharacters() {
|
|
| 143 | + return [ |
|
| 144 | + ['testPass%', true], |
|
| 145 | + ['testpass', false] |
|
| 146 | + ]; |
|
| 147 | + } |
|
| 148 | + /** |
|
| 149 | + * @dataProvider dataTestCheckSpecialCharactersFail |
|
| 150 | + * @param string $password |
|
| 151 | + * @expectedException \OC\HintException |
|
| 152 | + */ |
|
| 153 | + public function testCheckSpecialCharactersFail($password) {
|
|
| 154 | + $this->config->expects($this->once())->method('getIsSpecialCharactersEnforced')->willReturn(true);
|
|
| 155 | + $this->passValidator->checkSpecialCharacters($password); |
|
| 156 | + } |
|
| 157 | + public function dataTestCheckSpecialCharactersFail() {
|
|
| 158 | + return [ |
|
| 159 | + ['testpass'], |
|
| 160 | + ['TestPass1'], |
|
| 161 | + ['TEST2PASS'] |
|
| 162 | + ]; |
|
| 163 | + } |
|
| 164 | + public function testValidate() {
|
|
| 165 | + $password = 'password'; |
|
| 166 | + $instance = $this->getMockInstance( |
|
| 167 | + [ |
|
| 168 | + 'checkPasswordLength', |
|
| 169 | + 'checkUpperLowerCase', |
|
| 170 | + 'checkNumericCharacters', |
|
| 171 | + 'checkSpecialCharacters', |
|
| 172 | + ] |
|
| 173 | + ); |
|
| 174 | + $instance->expects($this->once())->method('checkPasswordLength')->with($password);
|
|
| 175 | + $instance->expects($this->once())->method('checkUpperLowerCase')->with($password);
|
|
| 176 | + $instance->expects($this->once())->method('checkNumericCharacters')->with($password);
|
|
| 177 | + $instance->expects($this->once())->method('checkSpecialCharacters')->with($password);
|
|
| 178 | + $instance->validate($password); |
|
| 179 | + } |
|
| 180 | 180 | } |
| 181 | 181 | \ No newline at end of file |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * @param array $mockedMethods |
|
| 38 | + * @param string[] $mockedMethods |
|
| 39 | 39 | * @return SecurityConfig | \PHPUnit_Framework_MockObject_MockObject |
| 40 | 40 | */ |
| 41 | 41 | private function getMockInstance($mockedMethods = []) {
|
@@ -20,8 +20,8 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | namespace OCA\Security\Tests; |
| 22 | 22 | |
| 23 | -use OCA\Security\SecurityConfig; |
|
| 24 | -use OCP\IConfig; |
|
| 23 | +use OCA\Security\SecurityConfig; |
|
| 24 | +use OCP\IConfig; |
|
| 25 | 25 | use Test\TestCase; |
| 26 | 26 | class SecurityConfigTest extends TestCase {
|
| 27 | 27 | /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ |
@@ -24,170 +24,170 @@ |
||
| 24 | 24 | use OCP\IConfig; |
| 25 | 25 | use Test\TestCase; |
| 26 | 26 | class SecurityConfigTest extends TestCase {
|
| 27 | - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ |
|
| 28 | - private $config; |
|
| 29 | - /** @var SecurityConfig */ |
|
| 30 | - private $securityConfig; |
|
| 31 | - public function setUp() {
|
|
| 32 | - parent::setUp(); |
|
| 33 | - $this->config = $this->createMock(IConfig::class); |
|
| 34 | - $this->securityConfig = new SecurityConfig($this->config); |
|
| 35 | - } |
|
| 27 | + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ |
|
| 28 | + private $config; |
|
| 29 | + /** @var SecurityConfig */ |
|
| 30 | + private $securityConfig; |
|
| 31 | + public function setUp() {
|
|
| 32 | + parent::setUp(); |
|
| 33 | + $this->config = $this->createMock(IConfig::class); |
|
| 34 | + $this->securityConfig = new SecurityConfig($this->config); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param array $mockedMethods |
|
| 39 | - * @return SecurityConfig | \PHPUnit_Framework_MockObject_MockObject |
|
| 40 | - */ |
|
| 41 | - private function getMockInstance($mockedMethods = []) {
|
|
| 42 | - $passwordValidator = $this->getMockBuilder('OCA\Security\SecurityConfig')
|
|
| 43 | - ->setConstructorArgs([$this->config]) |
|
| 44 | - ->setMethods($mockedMethods)->getMock(); |
|
| 45 | - return $passwordValidator; |
|
| 46 | - } |
|
| 37 | + /** |
|
| 38 | + * @param array $mockedMethods |
|
| 39 | + * @return SecurityConfig | \PHPUnit_Framework_MockObject_MockObject |
|
| 40 | + */ |
|
| 41 | + private function getMockInstance($mockedMethods = []) {
|
|
| 42 | + $passwordValidator = $this->getMockBuilder('OCA\Security\SecurityConfig')
|
|
| 43 | + ->setConstructorArgs([$this->config]) |
|
| 44 | + ->setMethods($mockedMethods)->getMock(); |
|
| 45 | + return $passwordValidator; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function testGetAllSecurityConfigs() {
|
|
| 49 | - $instance = $this->getMockInstance( |
|
| 50 | - [ |
|
| 51 | - 'getIsBruteForceProtectionEnabled', |
|
| 52 | - 'getMinPasswordLength', |
|
| 53 | - 'getIsUpperLowerCaseEnforced', |
|
| 54 | - 'getIsNumericCharactersEnforced', |
|
| 55 | - 'getIsSpecialCharactersEnforced' |
|
| 56 | - ] |
|
| 57 | - ); |
|
| 58 | - $instance->expects($this->once())->method('getIsBruteForceProtectionEnabled');
|
|
| 59 | - $instance->expects($this->once())->method('getMinPasswordLength');
|
|
| 60 | - $instance->expects($this->once())->method('getIsUpperLowerCaseEnforced');
|
|
| 61 | - $instance->expects($this->once())->method('getIsNumericCharactersEnforced');
|
|
| 62 | - $instance->expects($this->once())->method('getIsNumericCharactersEnforced');
|
|
| 63 | - $instance->getAllSecurityConfigs(); |
|
| 64 | - } |
|
| 65 | - /** |
|
| 66 | - * @dataProvider configTestData |
|
| 67 | - * @param string $appConfigValue |
|
| 68 | - * @param bool $expected |
|
| 69 | - */ |
|
| 70 | - public function testGetIsBruteForceProtectionEnabled($appConfigValue, $expected) {
|
|
| 71 | - $this->config->expects($this->once())->method('getAppValue')
|
|
| 72 | - ->with('security', 'enable_brute_force_protection', '0')
|
|
| 73 | - ->willReturn($appConfigValue); |
|
| 74 | - $this->assertSame($expected, |
|
| 75 | - $this->securityConfig->getIsBruteForceProtectionEnabled() |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - /** |
|
| 79 | - * @dataProvider minPassTestData |
|
| 80 | - * @param string $appConfigValue |
|
| 81 | - * @param bool $expected |
|
| 82 | - */ |
|
| 83 | - public function testGetMinPasswordLength($appConfigValue, $expected) {
|
|
| 84 | - $this->config->expects($this->once())->method('getAppValue')
|
|
| 85 | - ->with('security', 'min_password_length', '8')
|
|
| 86 | - ->willReturn($appConfigValue); |
|
| 87 | - $this->assertSame($expected, |
|
| 88 | - $this->securityConfig->getMinPasswordLength() |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - /** |
|
| 92 | - * @dataProvider configTestData |
|
| 93 | - * @param string $appConfigValue |
|
| 94 | - * @param bool $expected |
|
| 95 | - */ |
|
| 96 | - public function testGetIsUpperLowerCaseEnforced($appConfigValue, $expected) {
|
|
| 97 | - $this->config->expects($this->once())->method('getAppValue')
|
|
| 98 | - ->with('security', 'enforce_upper_lower_case', '0')
|
|
| 99 | - ->willReturn($appConfigValue); |
|
| 100 | - $this->assertSame($expected, |
|
| 101 | - $this->securityConfig->getIsUpperLowerCaseEnforced() |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - /** |
|
| 105 | - * @dataProvider configTestData |
|
| 106 | - * @param string $appConfigValue |
|
| 107 | - * @param bool $expected |
|
| 108 | - */ |
|
| 109 | - public function testGetIsNumericCharactersEnforced($appConfigValue, $expected) {
|
|
| 110 | - $this->config->expects($this->once())->method('getAppValue')
|
|
| 111 | - ->with('security', 'enforce_numeric_characters', '0')
|
|
| 112 | - ->willReturn($appConfigValue); |
|
| 113 | - $this->assertSame($expected, |
|
| 114 | - $this->securityConfig->getIsNumericCharactersEnforced() |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - /** |
|
| 118 | - * @dataProvider configTestData |
|
| 119 | - * @param string $appConfigValue |
|
| 120 | - * @param bool $expected |
|
| 121 | - */ |
|
| 122 | - public function testGetIsSpecialCharactersEnforced($appConfigValue, $expected) {
|
|
| 123 | - $this->config->expects($this->once())->method('getAppValue')
|
|
| 124 | - ->with('security', 'enforce_special_characters', '0')
|
|
| 125 | - ->willReturn($appConfigValue); |
|
| 126 | - $this->assertSame($expected, |
|
| 127 | - $this->securityConfig->getIsSpecialCharactersEnforced() |
|
| 128 | - ); |
|
| 129 | - } |
|
| 130 | - /** |
|
| 131 | - * @dataProvider configTestData |
|
| 132 | - * @param string $expected |
|
| 133 | - * @param bool $setValue |
|
| 134 | - */ |
|
| 135 | - public function testSetIsBruteForceProtectionEnabled($expected, $setValue) {
|
|
| 136 | - $this->config->expects($this->once())->method('setAppValue')
|
|
| 137 | - ->with('security', 'enable_brute_force_protection', $expected);
|
|
| 138 | - $this->securityConfig->setIsBruteForceProtectionEnabled($setValue); |
|
| 139 | - } |
|
| 140 | - /** |
|
| 141 | - * @dataProvider minPassTestData |
|
| 142 | - * @param string $expected |
|
| 143 | - * @param bool $setValue |
|
| 144 | - */ |
|
| 145 | - public function testSetMinPasswordLength($expected, $setValue) {
|
|
| 146 | - $this->config->expects($this->once())->method('setAppValue')
|
|
| 147 | - ->with('security', 'min_password_length', $expected);
|
|
| 148 | - $this->securityConfig->setMinPasswordLength($setValue); |
|
| 149 | - } |
|
| 150 | - /** |
|
| 151 | - * @dataProvider configTestData |
|
| 152 | - * @param string $expected |
|
| 153 | - * @param bool $setValue |
|
| 154 | - */ |
|
| 155 | - public function testSetIsUpperLowerCaseEnforced($expected, $setValue) {
|
|
| 156 | - $this->config->expects($this->once())->method('setAppValue')
|
|
| 157 | - ->with('security', 'enforce_upper_lower_case', $expected);
|
|
| 158 | - $this->securityConfig->setIsUpperLowerCaseEnforced($setValue); |
|
| 159 | - } |
|
| 160 | - /** |
|
| 161 | - * @dataProvider configTestData |
|
| 162 | - * @param string $expected |
|
| 163 | - * @param bool $setValue |
|
| 164 | - */ |
|
| 165 | - public function testSetIsNumericCharactersEnforced($expected, $setValue) {
|
|
| 166 | - $this->config->expects($this->once())->method('setAppValue')
|
|
| 167 | - ->with('security', 'enforce_numeric_characters', $expected);
|
|
| 168 | - $this->securityConfig->setIsNumericCharactersEnforced($setValue); |
|
| 169 | - } |
|
| 170 | - /** |
|
| 171 | - * @dataProvider configTestData |
|
| 172 | - * @param string $expected |
|
| 173 | - * @param bool $setValue |
|
| 174 | - */ |
|
| 175 | - public function testSetIsSpecialCharactersEnforced($expected, $setValue) {
|
|
| 176 | - $this->config->expects($this->once())->method('setAppValue')
|
|
| 177 | - ->with('security', 'enforce_special_characters', $expected);
|
|
| 178 | - $this->securityConfig->setIsSpecialCharactersEnforced($setValue); |
|
| 179 | - } |
|
| 180 | - public function configTestData() {
|
|
| 181 | - return [ |
|
| 182 | - ['1', true], |
|
| 183 | - ['0', false], |
|
| 184 | - ]; |
|
| 185 | - } |
|
| 186 | - public function minPassTestData() {
|
|
| 187 | - return [ |
|
| 188 | - ['8', 8], |
|
| 189 | - ['16', 16], |
|
| 190 | - ['255', 255] |
|
| 191 | - ]; |
|
| 192 | - } |
|
| 48 | + public function testGetAllSecurityConfigs() {
|
|
| 49 | + $instance = $this->getMockInstance( |
|
| 50 | + [ |
|
| 51 | + 'getIsBruteForceProtectionEnabled', |
|
| 52 | + 'getMinPasswordLength', |
|
| 53 | + 'getIsUpperLowerCaseEnforced', |
|
| 54 | + 'getIsNumericCharactersEnforced', |
|
| 55 | + 'getIsSpecialCharactersEnforced' |
|
| 56 | + ] |
|
| 57 | + ); |
|
| 58 | + $instance->expects($this->once())->method('getIsBruteForceProtectionEnabled');
|
|
| 59 | + $instance->expects($this->once())->method('getMinPasswordLength');
|
|
| 60 | + $instance->expects($this->once())->method('getIsUpperLowerCaseEnforced');
|
|
| 61 | + $instance->expects($this->once())->method('getIsNumericCharactersEnforced');
|
|
| 62 | + $instance->expects($this->once())->method('getIsNumericCharactersEnforced');
|
|
| 63 | + $instance->getAllSecurityConfigs(); |
|
| 64 | + } |
|
| 65 | + /** |
|
| 66 | + * @dataProvider configTestData |
|
| 67 | + * @param string $appConfigValue |
|
| 68 | + * @param bool $expected |
|
| 69 | + */ |
|
| 70 | + public function testGetIsBruteForceProtectionEnabled($appConfigValue, $expected) {
|
|
| 71 | + $this->config->expects($this->once())->method('getAppValue')
|
|
| 72 | + ->with('security', 'enable_brute_force_protection', '0')
|
|
| 73 | + ->willReturn($appConfigValue); |
|
| 74 | + $this->assertSame($expected, |
|
| 75 | + $this->securityConfig->getIsBruteForceProtectionEnabled() |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + /** |
|
| 79 | + * @dataProvider minPassTestData |
|
| 80 | + * @param string $appConfigValue |
|
| 81 | + * @param bool $expected |
|
| 82 | + */ |
|
| 83 | + public function testGetMinPasswordLength($appConfigValue, $expected) {
|
|
| 84 | + $this->config->expects($this->once())->method('getAppValue')
|
|
| 85 | + ->with('security', 'min_password_length', '8')
|
|
| 86 | + ->willReturn($appConfigValue); |
|
| 87 | + $this->assertSame($expected, |
|
| 88 | + $this->securityConfig->getMinPasswordLength() |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + /** |
|
| 92 | + * @dataProvider configTestData |
|
| 93 | + * @param string $appConfigValue |
|
| 94 | + * @param bool $expected |
|
| 95 | + */ |
|
| 96 | + public function testGetIsUpperLowerCaseEnforced($appConfigValue, $expected) {
|
|
| 97 | + $this->config->expects($this->once())->method('getAppValue')
|
|
| 98 | + ->with('security', 'enforce_upper_lower_case', '0')
|
|
| 99 | + ->willReturn($appConfigValue); |
|
| 100 | + $this->assertSame($expected, |
|
| 101 | + $this->securityConfig->getIsUpperLowerCaseEnforced() |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + /** |
|
| 105 | + * @dataProvider configTestData |
|
| 106 | + * @param string $appConfigValue |
|
| 107 | + * @param bool $expected |
|
| 108 | + */ |
|
| 109 | + public function testGetIsNumericCharactersEnforced($appConfigValue, $expected) {
|
|
| 110 | + $this->config->expects($this->once())->method('getAppValue')
|
|
| 111 | + ->with('security', 'enforce_numeric_characters', '0')
|
|
| 112 | + ->willReturn($appConfigValue); |
|
| 113 | + $this->assertSame($expected, |
|
| 114 | + $this->securityConfig->getIsNumericCharactersEnforced() |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + /** |
|
| 118 | + * @dataProvider configTestData |
|
| 119 | + * @param string $appConfigValue |
|
| 120 | + * @param bool $expected |
|
| 121 | + */ |
|
| 122 | + public function testGetIsSpecialCharactersEnforced($appConfigValue, $expected) {
|
|
| 123 | + $this->config->expects($this->once())->method('getAppValue')
|
|
| 124 | + ->with('security', 'enforce_special_characters', '0')
|
|
| 125 | + ->willReturn($appConfigValue); |
|
| 126 | + $this->assertSame($expected, |
|
| 127 | + $this->securityConfig->getIsSpecialCharactersEnforced() |
|
| 128 | + ); |
|
| 129 | + } |
|
| 130 | + /** |
|
| 131 | + * @dataProvider configTestData |
|
| 132 | + * @param string $expected |
|
| 133 | + * @param bool $setValue |
|
| 134 | + */ |
|
| 135 | + public function testSetIsBruteForceProtectionEnabled($expected, $setValue) {
|
|
| 136 | + $this->config->expects($this->once())->method('setAppValue')
|
|
| 137 | + ->with('security', 'enable_brute_force_protection', $expected);
|
|
| 138 | + $this->securityConfig->setIsBruteForceProtectionEnabled($setValue); |
|
| 139 | + } |
|
| 140 | + /** |
|
| 141 | + * @dataProvider minPassTestData |
|
| 142 | + * @param string $expected |
|
| 143 | + * @param bool $setValue |
|
| 144 | + */ |
|
| 145 | + public function testSetMinPasswordLength($expected, $setValue) {
|
|
| 146 | + $this->config->expects($this->once())->method('setAppValue')
|
|
| 147 | + ->with('security', 'min_password_length', $expected);
|
|
| 148 | + $this->securityConfig->setMinPasswordLength($setValue); |
|
| 149 | + } |
|
| 150 | + /** |
|
| 151 | + * @dataProvider configTestData |
|
| 152 | + * @param string $expected |
|
| 153 | + * @param bool $setValue |
|
| 154 | + */ |
|
| 155 | + public function testSetIsUpperLowerCaseEnforced($expected, $setValue) {
|
|
| 156 | + $this->config->expects($this->once())->method('setAppValue')
|
|
| 157 | + ->with('security', 'enforce_upper_lower_case', $expected);
|
|
| 158 | + $this->securityConfig->setIsUpperLowerCaseEnforced($setValue); |
|
| 159 | + } |
|
| 160 | + /** |
|
| 161 | + * @dataProvider configTestData |
|
| 162 | + * @param string $expected |
|
| 163 | + * @param bool $setValue |
|
| 164 | + */ |
|
| 165 | + public function testSetIsNumericCharactersEnforced($expected, $setValue) {
|
|
| 166 | + $this->config->expects($this->once())->method('setAppValue')
|
|
| 167 | + ->with('security', 'enforce_numeric_characters', $expected);
|
|
| 168 | + $this->securityConfig->setIsNumericCharactersEnforced($setValue); |
|
| 169 | + } |
|
| 170 | + /** |
|
| 171 | + * @dataProvider configTestData |
|
| 172 | + * @param string $expected |
|
| 173 | + * @param bool $setValue |
|
| 174 | + */ |
|
| 175 | + public function testSetIsSpecialCharactersEnforced($expected, $setValue) {
|
|
| 176 | + $this->config->expects($this->once())->method('setAppValue')
|
|
| 177 | + ->with('security', 'enforce_special_characters', $expected);
|
|
| 178 | + $this->securityConfig->setIsSpecialCharactersEnforced($setValue); |
|
| 179 | + } |
|
| 180 | + public function configTestData() {
|
|
| 181 | + return [ |
|
| 182 | + ['1', true], |
|
| 183 | + ['0', false], |
|
| 184 | + ]; |
|
| 185 | + } |
|
| 186 | + public function minPassTestData() {
|
|
| 187 | + return [ |
|
| 188 | + ['8', 8], |
|
| 189 | + ['16', 16], |
|
| 190 | + ['255', 255] |
|
| 191 | + ]; |
|
| 192 | + } |
|
| 193 | 193 | } |
| 194 | 194 | \ No newline at end of file |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | <div id="brute-force-protection"> |
| 27 | 27 | <div> |
| 28 | 28 | <input type="checkbox" class="checkbox" id="security-brute-force-protection-enabled" |
| 29 | - <?php if ($_['isBruteForceProtectionEnabled']) p("checked");?> >
|
|
| 29 | + <?php if ($_['isBruteForceProtectionEnabled']) p("checked"); ?> >
|
|
| 30 | 30 | <label for="security-brute-force-protection-enabled"><?php p($l->t('Activate Brute Force Protection')) ?></label>
|
| 31 | 31 | </div> |
| 32 | 32 | </div> |
@@ -36,22 +36,22 @@ discard block |
||
| 36 | 36 | <div> |
| 37 | 37 | <label for="security-min-password-length"><?php p($l->t('Determine minimum password length')) ?></label>
|
| 38 | 38 | <input type="number" id="security-min-password-length" min="6" value="<?php p($_['minPasswordLength']) ?>"> |
| 39 | - <button id="save-pass-length" class="save"><?php p($l->t('Save Length'));?></button>
|
|
| 39 | + <button id="save-pass-length" class="save"><?php p($l->t('Save Length')); ?></button>
|
|
| 40 | 40 | <span id="security-min-password-length-message" class="msg"></span> |
| 41 | 41 | </div> |
| 42 | 42 | <div> |
| 43 | 43 | <input type="checkbox" class="checkbox" id="security-enforce-upper-lower-case" |
| 44 | - <?php if ($_['isUpperLowerCaseEnforced']) p("checked");?> >
|
|
| 44 | + <?php if ($_['isUpperLowerCaseEnforced']) p("checked"); ?> >
|
|
| 45 | 45 | <label for="security-enforce-upper-lower-case"><?php p($l->t('Enforce at least one upper and one lower case character on passwords')) ?></label>
|
| 46 | 46 | </div> |
| 47 | 47 | <div> |
| 48 | 48 | <input type="checkbox" class="checkbox" id="security-enforce-numerical-characters" |
| 49 | - <?php if ($_['isNumericalCharsEnforced']) p("checked");?> >
|
|
| 49 | + <?php if ($_['isNumericalCharsEnforced']) p("checked"); ?> >
|
|
| 50 | 50 | <label for="security-enforce-numerical-characters"><?php p($l->t('Enforce at least one numerical characters on passwords')) ?></label>
|
| 51 | 51 | </div> |
| 52 | 52 | <div> |
| 53 | 53 | <input type="checkbox" class="checkbox" id="security-enforce-special-characters" |
| 54 | - <?php if ($_['isSpecialCharsEnforced']) p("checked");?> >
|
|
| 54 | + <?php if ($_['isSpecialCharsEnforced']) p("checked"); ?> >
|
|
| 55 | 55 | <label for="security-enforce-special-characters"><?php p($l->t('Enforce at least one special characters on passwords')) ?></label>
|
| 56 | 56 | </div> |
| 57 | 57 | </div> |
| 58 | 58 | \ No newline at end of file |
@@ -26,7 +26,10 @@ discard block |
||
| 26 | 26 | <div id="brute-force-protection"> |
| 27 | 27 | <div> |
| 28 | 28 | <input type="checkbox" class="checkbox" id="security-brute-force-protection-enabled" |
| 29 | - <?php if ($_['isBruteForceProtectionEnabled']) p("checked");?> >
|
|
| 29 | + <?php if ($_['isBruteForceProtectionEnabled']) { |
|
| 30 | + p("checked"); |
|
| 31 | +} |
|
| 32 | +?> > |
|
| 30 | 33 | <label for="security-brute-force-protection-enabled"><?php p($l->t('Activate Brute Force Protection')) ?></label>
|
| 31 | 34 | </div> |
| 32 | 35 | </div> |
@@ -41,17 +44,26 @@ discard block |
||
| 41 | 44 | </div> |
| 42 | 45 | <div> |
| 43 | 46 | <input type="checkbox" class="checkbox" id="security-enforce-upper-lower-case" |
| 44 | - <?php if ($_['isUpperLowerCaseEnforced']) p("checked");?> >
|
|
| 47 | + <?php if ($_['isUpperLowerCaseEnforced']) { |
|
| 48 | + p("checked"); |
|
| 49 | +} |
|
| 50 | +?> > |
|
| 45 | 51 | <label for="security-enforce-upper-lower-case"><?php p($l->t('Enforce at least one upper and one lower case character on passwords')) ?></label>
|
| 46 | 52 | </div> |
| 47 | 53 | <div> |
| 48 | 54 | <input type="checkbox" class="checkbox" id="security-enforce-numerical-characters" |
| 49 | - <?php if ($_['isNumericalCharsEnforced']) p("checked");?> >
|
|
| 55 | + <?php if ($_['isNumericalCharsEnforced']) { |
|
| 56 | + p("checked"); |
|
| 57 | +} |
|
| 58 | +?> > |
|
| 50 | 59 | <label for="security-enforce-numerical-characters"><?php p($l->t('Enforce at least one numerical characters on passwords')) ?></label>
|
| 51 | 60 | </div> |
| 52 | 61 | <div> |
| 53 | 62 | <input type="checkbox" class="checkbox" id="security-enforce-special-characters" |
| 54 | - <?php if ($_['isSpecialCharsEnforced']) p("checked");?> >
|
|
| 63 | + <?php if ($_['isSpecialCharsEnforced']) { |
|
| 64 | + p("checked"); |
|
| 65 | +} |
|
| 66 | +?> > |
|
| 55 | 67 | <label for="security-enforce-special-characters"><?php p($l->t('Enforce at least one special characters on passwords')) ?></label>
|
| 56 | 68 | </div> |
| 57 | 69 | </div> |
| 58 | 70 | \ No newline at end of file |
@@ -25,15 +25,15 @@ |
||
| 25 | 25 | ?> |
| 26 | 26 | <div id="password-policies" class="hidden"> |
| 27 | 27 | <?php print_unescaped( |
| 28 | - "<p>". $l->t('Passwords must:'). "</p>");?>
|
|
| 28 | + "<p>". $l->t('Passwords must:'). "</p>");?>
|
|
| 29 | 29 | <ul class="pass-info"> |
| 30 | 30 | <?php print_unescaped( |
| 31 | - "<li class='pass-info-element'>". $l->t('be at least 8 characters long ', $_['minPasswordLength']). "</li>");?>
|
|
| 31 | + "<li class='pass-info-element'>". $l->t('be at least 8 characters long ', $_['minPasswordLength']). "</li>");?>
|
|
| 32 | 32 | <?php if ($_['isUpperLowerCaseEnforced']) print_unescaped( |
| 33 | - "<li class='pass-info-element'>". $l->t('contain at least one uppercase letter and at least one lowercase letter '). "</li>");?>
|
|
| 33 | + "<li class='pass-info-element'>". $l->t('contain at least one uppercase letter and at least one lowercase letter '). "</li>");?>
|
|
| 34 | 34 | <?php if ($_['isNumericalCharsEnforced']) print_unescaped( |
| 35 | - "<li class='pass-info-element'>". $l->t('contain at least one numerical character'). "</li>");?>
|
|
| 35 | + "<li class='pass-info-element'>". $l->t('contain at least one numerical character'). "</li>");?>
|
|
| 36 | 36 | <?php if ($_['isSpecialCharsEnforced']) print_unescaped( |
| 37 | - "<li class='pass-info-element'>". $l->t('contain at least one special character'). "</li>");?>
|
|
| 37 | + "<li class='pass-info-element'>". $l->t('contain at least one special character'). "</li>");?>
|
|
| 38 | 38 | </ul> |
| 39 | 39 | </div> |
@@ -25,15 +25,15 @@ |
||
| 25 | 25 | ?> |
| 26 | 26 | <div id="password-policies" class="hidden"> |
| 27 | 27 | <?php print_unescaped( |
| 28 | - "<p>". $l->t('Passwords must:'). "</p>");?>
|
|
| 28 | + "<p>".$l->t('Passwords must:')."</p>"); ?>
|
|
| 29 | 29 | <ul class="pass-info"> |
| 30 | 30 | <?php print_unescaped( |
| 31 | - "<li class='pass-info-element'>". $l->t('be at least 8 characters long ', $_['minPasswordLength']). "</li>");?>
|
|
| 31 | + "<li class='pass-info-element'>".$l->t('be at least 8 characters long ', $_['minPasswordLength'])."</li>"); ?>
|
|
| 32 | 32 | <?php if ($_['isUpperLowerCaseEnforced']) print_unescaped( |
| 33 | - "<li class='pass-info-element'>". $l->t('contain at least one uppercase letter and at least one lowercase letter '). "</li>");?>
|
|
| 33 | + "<li class='pass-info-element'>".$l->t('contain at least one uppercase letter and at least one lowercase letter ')."</li>"); ?>
|
|
| 34 | 34 | <?php if ($_['isNumericalCharsEnforced']) print_unescaped( |
| 35 | - "<li class='pass-info-element'>". $l->t('contain at least one numerical character'). "</li>");?>
|
|
| 35 | + "<li class='pass-info-element'>".$l->t('contain at least one numerical character')."</li>"); ?>
|
|
| 36 | 36 | <?php if ($_['isSpecialCharsEnforced']) print_unescaped( |
| 37 | - "<li class='pass-info-element'>". $l->t('contain at least one special character'). "</li>");?>
|
|
| 37 | + "<li class='pass-info-element'>".$l->t('contain at least one special character')."</li>"); ?>
|
|
| 38 | 38 | </ul> |
| 39 | 39 | </div> |
@@ -29,11 +29,20 @@ |
||
| 29 | 29 | <ul class="pass-info"> |
| 30 | 30 | <?php print_unescaped( |
| 31 | 31 | "<li class='pass-info-element'>". $l->t('be at least 8 characters long ', $_['minPasswordLength']). "</li>");?>
|
| 32 | - <?php if ($_['isUpperLowerCaseEnforced']) print_unescaped( |
|
| 33 | - "<li class='pass-info-element'>". $l->t('contain at least one uppercase letter and at least one lowercase letter '). "</li>");?>
|
|
| 34 | - <?php if ($_['isNumericalCharsEnforced']) print_unescaped( |
|
| 35 | - "<li class='pass-info-element'>". $l->t('contain at least one numerical character'). "</li>");?>
|
|
| 36 | - <?php if ($_['isSpecialCharsEnforced']) print_unescaped( |
|
| 37 | - "<li class='pass-info-element'>". $l->t('contain at least one special character'). "</li>");?>
|
|
| 32 | + <?php if ($_['isUpperLowerCaseEnforced']) { |
|
| 33 | + print_unescaped( |
|
| 34 | + "<li class='pass-info-element'>". $l->t('contain at least one uppercase letter and at least one lowercase letter '). "</li>"); |
|
| 35 | +} |
|
| 36 | +?> |
|
| 37 | + <?php if ($_['isNumericalCharsEnforced']) { |
|
| 38 | + print_unescaped( |
|
| 39 | + "<li class='pass-info-element'>". $l->t('contain at least one numerical character'). "</li>"); |
|
| 40 | +} |
|
| 41 | +?> |
|
| 42 | + <?php if ($_['isSpecialCharsEnforced']) { |
|
| 43 | + print_unescaped( |
|
| 44 | + "<li class='pass-info-element'>". $l->t('contain at least one special character'). "</li>"); |
|
| 45 | +} |
|
| 46 | +?> |
|
| 38 | 47 | </ul> |
| 39 | 48 | </div> |
@@ -23,9 +23,9 @@ |
||
| 23 | 23 | } |
| 24 | 24 | require_once __DIR__.'/../../../lib/base.php'; |
| 25 | 25 | |
| 26 | -OC::$composerAutoloader->addPsr4('Test\\', OC::$SERVERROOT . '/tests/lib', true);
|
|
| 26 | +OC::$composerAutoloader->addPsr4('Test\\', OC::$SERVERROOT.'/tests/lib', true);
|
|
| 27 | 27 | |
| 28 | -if(!class_exists('PHPUnit_Framework_TestCase')) {
|
|
| 28 | +if (!class_exists('PHPUnit_Framework_TestCase')) {
|
|
| 29 | 29 | require_once('PHPUnit/Autoload.php');
|
| 30 | 30 | } |
| 31 | 31 | |
@@ -47,14 +47,14 @@ discard block |
||
| 47 | 47 | * @var \PHPUnit_Framework_MockObject_MockObject | IRequest |
| 48 | 48 | */ |
| 49 | 49 | private $requestMock; |
| 50 | - /** |
|
| 51 | - * @var \PHPUnit_Framework_MockObject_MockObject | PasswordValidator |
|
| 52 | - */ |
|
| 53 | - private $passwordValidatorMock; |
|
| 54 | - /** |
|
| 55 | - * @var \PHPUnit_Framework_MockObject_MockObject | EventDispatcher |
|
| 56 | - */ |
|
| 57 | - private $dispatcherMock; |
|
| 50 | + /** |
|
| 51 | + * @var \PHPUnit_Framework_MockObject_MockObject | PasswordValidator |
|
| 52 | + */ |
|
| 53 | + private $passwordValidatorMock; |
|
| 54 | + /** |
|
| 55 | + * @var \PHPUnit_Framework_MockObject_MockObject | EventDispatcher |
|
| 56 | + */ |
|
| 57 | + private $dispatcherMock; |
|
| 58 | 58 | |
| 59 | 59 | public function setUp() {
|
| 60 | 60 | parent::setUp(); |
@@ -70,28 +70,28 @@ discard block |
||
| 70 | 70 | ->disableOriginalConstructor() |
| 71 | 71 | ->getMock(); |
| 72 | 72 | $this->passwordValidatorMock = $this->getMockBuilder('OCA\Security\PasswordValidator')
|
| 73 | - ->disableOriginalConstructor() |
|
| 74 | - ->getMock(); |
|
| 75 | - $this->dispatcherMock = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
|
|
| 76 | - ->disableOriginalConstructor() |
|
| 77 | - ->getMock(); |
|
| 73 | + ->disableOriginalConstructor() |
|
| 74 | + ->getMock(); |
|
| 75 | + $this->dispatcherMock = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
|
|
| 76 | + ->disableOriginalConstructor() |
|
| 77 | + ->getMock(); |
|
| 78 | 78 | |
| 79 | 79 | |
| 80 | 80 | $this->hooks = new Hooks( |
| 81 | - $this->userManagerMock, |
|
| 82 | - $this->throttleMock, |
|
| 83 | - $this->requestMock, |
|
| 84 | - $this->passwordValidatorMock, |
|
| 85 | - $this->dispatcherMock); |
|
| 81 | + $this->userManagerMock, |
|
| 82 | + $this->throttleMock, |
|
| 83 | + $this->requestMock, |
|
| 84 | + $this->passwordValidatorMock, |
|
| 85 | + $this->dispatcherMock); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | public function testRegister() {
|
| 89 | - $this->userManagerMock->expects($this->exactly(2)) |
|
| 90 | - ->method('listen');
|
|
| 91 | - $this->dispatcherMock->expects($this->once()) |
|
| 92 | - ->method('addListener');
|
|
| 93 | - $this->hooks->register(); |
|
| 94 | - } |
|
| 89 | + $this->userManagerMock->expects($this->exactly(2)) |
|
| 90 | + ->method('listen');
|
|
| 91 | + $this->dispatcherMock->expects($this->once()) |
|
| 92 | + ->method('addListener');
|
|
| 93 | + $this->hooks->register(); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | public function testFailedLoginCallback() {
|
| 97 | 97 | $this->throttleMock->expects($this->once()) |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | $this->throttleMock->expects($this->once()) |
| 108 | 108 | ->method('clearSuspiciousAttemptsForIp');
|
| 109 | 109 | |
| 110 | - /** @var \OCP\IUser $user*/ |
|
| 110 | + /** @var \OCP\IUser $user*/ |
|
| 111 | 111 | $user = $this->getMockBuilder('OCP\IUser')
|
| 112 | 112 | ->disableOriginalConstructor() |
| 113 | 113 | ->getMock(); |