@@ -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 |
@@ -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 |
@@ -25,27 +25,27 @@ |
||
| 25 | 25 | |
| 26 | 26 | class PersonalPanel implements ISettings {
|
| 27 | 27 | |
| 28 | - /** @var SecurityConfig */ |
|
| 29 | - private $config; |
|
| 30 | - |
|
| 31 | - public function __construct(SecurityConfig $config) {
|
|
| 32 | - $this->config = $config; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function getPanel() {
|
|
| 36 | - $params = $this->config->getAllSecurityConfigs(); |
|
| 37 | - $tmpl = new Template('security', 'settings-personal');
|
|
| 38 | - foreach ($params as $key => $value) {
|
|
| 39 | - $tmpl->assign($key, $value); |
|
| 40 | - } |
|
| 41 | - return $tmpl; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function getSectionID() {
|
|
| 45 | - return 'general'; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - public function getPriority() {
|
|
| 49 | - return 0; |
|
| 50 | - } |
|
| 28 | + /** @var SecurityConfig */ |
|
| 29 | + private $config; |
|
| 30 | + |
|
| 31 | + public function __construct(SecurityConfig $config) {
|
|
| 32 | + $this->config = $config; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function getPanel() {
|
|
| 36 | + $params = $this->config->getAllSecurityConfigs(); |
|
| 37 | + $tmpl = new Template('security', 'settings-personal');
|
|
| 38 | + foreach ($params as $key => $value) {
|
|
| 39 | + $tmpl->assign($key, $value); |
|
| 40 | + } |
|
| 41 | + return $tmpl; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function getSectionID() {
|
|
| 45 | + return 'general'; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + public function getPriority() {
|
|
| 49 | + return 0; |
|
| 50 | + } |
|
| 51 | 51 | } |
| 52 | 52 | \ No newline at end of file |
@@ -26,27 +26,27 @@ |
||
| 26 | 26 | |
| 27 | 27 | class AdminPanel implements ISettings {
|
| 28 | 28 | |
| 29 | - /** @var SecurityConfig */ |
|
| 30 | - private $config; |
|
| 31 | - |
|
| 32 | - public function __construct(SecurityConfig $config) {
|
|
| 33 | - $this->config = $config; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function getPanel() {
|
|
| 37 | - $params = $this->config->getAllSecurityConfigs(); |
|
| 38 | - $tmpl = new Template('security', 'settings-admin');
|
|
| 39 | - foreach ($params as $key => $value) {
|
|
| 40 | - $tmpl->assign($key, $value); |
|
| 41 | - } |
|
| 42 | - return $tmpl; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function getSectionID() {
|
|
| 46 | - return 'security'; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function getPriority() {
|
|
| 50 | - return 100; |
|
| 51 | - } |
|
| 29 | + /** @var SecurityConfig */ |
|
| 30 | + private $config; |
|
| 31 | + |
|
| 32 | + public function __construct(SecurityConfig $config) {
|
|
| 33 | + $this->config = $config; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public function getPanel() {
|
|
| 37 | + $params = $this->config->getAllSecurityConfigs(); |
|
| 38 | + $tmpl = new Template('security', 'settings-admin');
|
|
| 39 | + foreach ($params as $key => $value) {
|
|
| 40 | + $tmpl->assign($key, $value); |
|
| 41 | + } |
|
| 42 | + return $tmpl; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function getSectionID() {
|
|
| 46 | + return 'security'; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function getPriority() {
|
|
| 50 | + return 100; |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -24,115 +24,115 @@ |
||
| 24 | 24 | |
| 25 | 25 | class PasswordValidator {
|
| 26 | 26 | |
| 27 | - /** @var SecurityConfig */ |
|
| 28 | - protected $config; |
|
| 27 | + /** @var SecurityConfig */ |
|
| 28 | + protected $config; |
|
| 29 | 29 | |
| 30 | - /** @var IL10N */ |
|
| 31 | - protected $l; |
|
| 30 | + /** @var IL10N */ |
|
| 31 | + protected $l; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * PasswordValidator constructor. |
|
| 35 | - * |
|
| 36 | - * @param SecurityConfig $config |
|
| 37 | - * @param IL10N $l |
|
| 38 | - */ |
|
| 39 | - public function __construct(SecurityConfig $config, IL10N $l) {
|
|
| 40 | - $this->config = $config; |
|
| 41 | - $this->l = $l; |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * PasswordValidator constructor. |
|
| 35 | + * |
|
| 36 | + * @param SecurityConfig $config |
|
| 37 | + * @param IL10N $l |
|
| 38 | + */ |
|
| 39 | + public function __construct(SecurityConfig $config, IL10N $l) {
|
|
| 40 | + $this->config = $config; |
|
| 41 | + $this->l = $l; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * validate the given password satisfies defined password policy |
|
| 46 | - * |
|
| 47 | - * @param string $password |
|
| 48 | - * @throws HintException |
|
| 49 | - */ |
|
| 50 | - public function validate($password) {
|
|
| 51 | - $this->checkPasswordLength($password); |
|
| 52 | - $this->checkNumericCharacters($password); |
|
| 53 | - $this->checkUpperLowerCase($password); |
|
| 54 | - $this->checkSpecialCharacters($password); |
|
| 55 | - } |
|
| 44 | + /** |
|
| 45 | + * validate the given password satisfies defined password policy |
|
| 46 | + * |
|
| 47 | + * @param string $password |
|
| 48 | + * @throws HintException |
|
| 49 | + */ |
|
| 50 | + public function validate($password) {
|
|
| 51 | + $this->checkPasswordLength($password); |
|
| 52 | + $this->checkNumericCharacters($password); |
|
| 53 | + $this->checkUpperLowerCase($password); |
|
| 54 | + $this->checkSpecialCharacters($password); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * validate the given password satisfies defined min length |
|
| 59 | - * |
|
| 60 | - * @param string $password |
|
| 61 | - * @throws HintException |
|
| 62 | - */ |
|
| 63 | - public function checkPasswordLength($password) {
|
|
| 64 | - $minPassLength = $this->config->getMinPasswordLength(); |
|
| 65 | - if(strlen($password) < $minPassLength) {
|
|
| 66 | - $message = 'Password needs to be at least ' . $minPassLength . ' characters long'; |
|
| 67 | - $hint = $this->l->t( |
|
| 68 | - 'Password needs to be at least %s characters long', [$minPassLength] |
|
| 69 | - ); |
|
| 70 | - throw new HintException($message, $hint); |
|
| 71 | - } |
|
| 72 | - } |
|
| 57 | + /** |
|
| 58 | + * validate the given password satisfies defined min length |
|
| 59 | + * |
|
| 60 | + * @param string $password |
|
| 61 | + * @throws HintException |
|
| 62 | + */ |
|
| 63 | + public function checkPasswordLength($password) {
|
|
| 64 | + $minPassLength = $this->config->getMinPasswordLength(); |
|
| 65 | + if(strlen($password) < $minPassLength) {
|
|
| 66 | + $message = 'Password needs to be at least ' . $minPassLength . ' characters long'; |
|
| 67 | + $hint = $this->l->t( |
|
| 68 | + 'Password needs to be at least %s characters long', [$minPassLength] |
|
| 69 | + ); |
|
| 70 | + throw new HintException($message, $hint); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * validate if password contains at least one upper and one lower case character |
|
| 76 | - * |
|
| 77 | - * @param string $password |
|
| 78 | - * @throws HintException |
|
| 79 | - */ |
|
| 80 | - public function checkUpperLowerCase($password) {
|
|
| 81 | - $enforceUpperLowerCase= $this->config->getIsUpperLowerCaseEnforced(); |
|
| 82 | - if($enforceUpperLowerCase === true && $this->hasUpperAndLowerCase($password) === false) {
|
|
| 83 | - $message = 'Password should contain at least one upper and one lower case character.'; |
|
| 84 | - $hint = $this->l->t( |
|
| 85 | - 'Password should contain at least one upper and one lower case character.' |
|
| 86 | - ); |
|
| 87 | - throw new HintException($message, $hint); |
|
| 88 | - } |
|
| 89 | - } |
|
| 74 | + /** |
|
| 75 | + * validate if password contains at least one upper and one lower case character |
|
| 76 | + * |
|
| 77 | + * @param string $password |
|
| 78 | + * @throws HintException |
|
| 79 | + */ |
|
| 80 | + public function checkUpperLowerCase($password) {
|
|
| 81 | + $enforceUpperLowerCase= $this->config->getIsUpperLowerCaseEnforced(); |
|
| 82 | + if($enforceUpperLowerCase === true && $this->hasUpperAndLowerCase($password) === false) {
|
|
| 83 | + $message = 'Password should contain at least one upper and one lower case character.'; |
|
| 84 | + $hint = $this->l->t( |
|
| 85 | + 'Password should contain at least one upper and one lower case character.' |
|
| 86 | + ); |
|
| 87 | + throw new HintException($message, $hint); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * validate the given password satisfies numeric character policy |
|
| 93 | - * |
|
| 94 | - * @param string $password |
|
| 95 | - * @throws HintException |
|
| 96 | - */ |
|
| 97 | - public function checkNumericCharacters($password) {
|
|
| 98 | - $enforceNumericCharacters = $this->config->getIsNumericCharactersEnforced(); |
|
| 99 | - if($enforceNumericCharacters === true && $this->hasNumericalCharacters($password) === false) {
|
|
| 100 | - $message = 'Password should contain at least one numerical character.'; |
|
| 101 | - $hint = $this->l->t( |
|
| 102 | - 'Password should contain at least one numerical character.' |
|
| 103 | - ); |
|
| 104 | - throw new HintException($message, $hint); |
|
| 105 | - } |
|
| 106 | - } |
|
| 91 | + /** |
|
| 92 | + * validate the given password satisfies numeric character policy |
|
| 93 | + * |
|
| 94 | + * @param string $password |
|
| 95 | + * @throws HintException |
|
| 96 | + */ |
|
| 97 | + public function checkNumericCharacters($password) {
|
|
| 98 | + $enforceNumericCharacters = $this->config->getIsNumericCharactersEnforced(); |
|
| 99 | + if($enforceNumericCharacters === true && $this->hasNumericalCharacters($password) === false) {
|
|
| 100 | + $message = 'Password should contain at least one numerical character.'; |
|
| 101 | + $hint = $this->l->t( |
|
| 102 | + 'Password should contain at least one numerical character.' |
|
| 103 | + ); |
|
| 104 | + throw new HintException($message, $hint); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * check if password contains at least one special character |
|
| 110 | - * |
|
| 111 | - * @param string $password |
|
| 112 | - * @throws HintException |
|
| 113 | - */ |
|
| 114 | - public function checkSpecialCharacters($password) {
|
|
| 115 | - $enforceSpecialCharacters = $this->config->getIsSpecialCharactersEnforced(); |
|
| 116 | - if($enforceSpecialCharacters === true && $this->hasSpecialCharacter($password) === false) {
|
|
| 117 | - $message = 'Password should contain at least one special character.'; |
|
| 118 | - $hint = $this->l->t( |
|
| 119 | - 'Password should contain at least one special character.' |
|
| 120 | - ); |
|
| 121 | - throw new HintException($message, $hint); |
|
| 122 | - } |
|
| 123 | - } |
|
| 108 | + /** |
|
| 109 | + * check if password contains at least one special character |
|
| 110 | + * |
|
| 111 | + * @param string $password |
|
| 112 | + * @throws HintException |
|
| 113 | + */ |
|
| 114 | + public function checkSpecialCharacters($password) {
|
|
| 115 | + $enforceSpecialCharacters = $this->config->getIsSpecialCharactersEnforced(); |
|
| 116 | + if($enforceSpecialCharacters === true && $this->hasSpecialCharacter($password) === false) {
|
|
| 117 | + $message = 'Password should contain at least one special character.'; |
|
| 118 | + $hint = $this->l->t( |
|
| 119 | + 'Password should contain at least one special character.' |
|
| 120 | + ); |
|
| 121 | + throw new HintException($message, $hint); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - public function hasNumericalCharacters($password) {
|
|
| 126 | - return preg_match('/\d/', $password) === 1 ? true : false;
|
|
| 127 | - } |
|
| 125 | + public function hasNumericalCharacters($password) {
|
|
| 126 | + return preg_match('/\d/', $password) === 1 ? true : false;
|
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - public function hasUpperAndLowerCase($password) {
|
|
| 130 | - $toLower = strtolower($password); |
|
| 131 | - $toUpper = strtoupper($password); |
|
| 132 | - return ($toLower !== $password && $toUpper !== $password) ? true : false; |
|
| 133 | - } |
|
| 129 | + public function hasUpperAndLowerCase($password) {
|
|
| 130 | + $toLower = strtolower($password); |
|
| 131 | + $toUpper = strtoupper($password); |
|
| 132 | + return ($toLower !== $password && $toUpper !== $password) ? true : false; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - public function hasSpecialCharacter($password) {
|
|
| 136 | - return (!ctype_alnum($password)); |
|
| 137 | - } |
|
| 135 | + public function hasSpecialCharacter($password) {
|
|
| 136 | + return (!ctype_alnum($password)); |
|
| 137 | + } |
|
| 138 | 138 | } |
| 139 | 139 | \ No newline at end of file |
@@ -26,23 +26,23 @@ |
||
| 26 | 26 | |
| 27 | 27 | class SettingsController extends Controller {
|
| 28 | 28 | |
| 29 | - /** @var SecurityConfig */ |
|
| 30 | - private $config; |
|
| 29 | + /** @var SecurityConfig */ |
|
| 30 | + private $config; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @param string $appName |
|
| 34 | - * @param IRequest $request |
|
| 35 | - * @param SecurityConfig $config |
|
| 36 | - */ |
|
| 37 | - public function __construct($appName, IRequest $request, SecurityConfig $config) {
|
|
| 38 | - parent::__construct($appName, $request); |
|
| 39 | - $this->config = $config; |
|
| 40 | - } |
|
| 32 | + /** |
|
| 33 | + * @param string $appName |
|
| 34 | + * @param IRequest $request |
|
| 35 | + * @param SecurityConfig $config |
|
| 36 | + */ |
|
| 37 | + public function __construct($appName, IRequest $request, SecurityConfig $config) {
|
|
| 38 | + parent::__construct($appName, $request); |
|
| 39 | + $this->config = $config; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return array |
|
| 44 | - */ |
|
| 45 | - public function state() {
|
|
| 46 | - return $this->config->getAllSecurityConfigs(); |
|
| 47 | - } |
|
| 42 | + /** |
|
| 43 | + * @return array |
|
| 44 | + */ |
|
| 45 | + public function state() {
|
|
| 46 | + return $this->config->getAllSecurityConfigs(); |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -1,6 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - |
|
| 4 | 3 | * |
| 5 | 4 | * @author Semih Serhat Karakaya |
| 6 | 5 | * @copyright Copyright (c) 2017, ownCloud GmbH |
@@ -1,6 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - |
|
| 4 | 3 | * |
| 5 | 4 | * @author Semih Serhat Karakaya |
| 6 | 5 | * @copyright Copyright (c) 2016, ITU IT HEAD OFFICE. |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | $c->query('DbService'),
|
| 48 | 48 | $c->query('SecurityConfig'),
|
| 49 | 49 | $c->query('OCP\IL10N'),
|
| 50 | - $c->query('OCP\AppFramework\Utility\ITimeFactory')
|
|
| 50 | + $c->query('OCP\AppFramework\Utility\ITimeFactory')
|
|
| 51 | 51 | ); |
| 52 | 52 | }); |
| 53 | 53 | |