Issues (40)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/SecurityConfigTest.php (14 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Semih Serhat Karakaya <[email protected]>
4
 *
5
 * @license GNU AGPL version 3 or any later version
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as
9
 * published by the Free Software Foundation, either version 3 of the
10
 * License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
namespace OCA\Security\Tests;
22
23
use OCA\Security\SecurityConfig;
24
use OCP\IConfig;
25
use Test\TestCase;
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
    }
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
    }
47
48
    public function testGetAllSecurityConfigs() {
49
        $instance = $this->getMockInstance(
50
            [
51
                'getBruteForceProtectionFailTolerance',
52
                'getBruteForceProtectionTimeThreshold',
53
                'getBruteForceProtectionBanPeriod',
54
                'getMinPasswordLength',
55
                'getIsUpperLowerCaseEnforced',
56
                'getIsNumericCharactersEnforced',
57
                'getIsSpecialCharactersEnforced'
58
            ]
59
        );
60
        $instance->expects($this->once())->method('getBruteForceProtectionFailTolerance');
0 ignored issues
show
The method expects() does not seem to exist on object<OCA\Security\SecurityConfig>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
        $instance->expects($this->once())->method('getBruteForceProtectionTimeThreshold');
0 ignored issues
show
The method expects() does not seem to exist on object<OCA\Security\SecurityConfig>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
        $instance->expects($this->once())->method('getBruteForceProtectionBanPeriod');
0 ignored issues
show
The method expects() does not seem to exist on object<OCA\Security\SecurityConfig>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
        $instance->expects($this->once())->method('getMinPasswordLength');
0 ignored issues
show
The method expects() does not seem to exist on object<OCA\Security\SecurityConfig>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
        $instance->expects($this->once())->method('getIsUpperLowerCaseEnforced');
0 ignored issues
show
The method expects() does not seem to exist on object<OCA\Security\SecurityConfig>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
        $instance->expects($this->once())->method('getIsNumericCharactersEnforced');
0 ignored issues
show
The method expects() does not seem to exist on object<OCA\Security\SecurityConfig>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
        $instance->expects($this->once())->method('getIsNumericCharactersEnforced');
0 ignored issues
show
The method expects() does not seem to exist on object<OCA\Security\SecurityConfig>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
        $instance->getAllSecurityConfigs();
68
    }
69
    /**
70
     * @dataProvider numericConfTestData
71
     * @param string $appConfigValue
72
     * @param int $expected
73
     */
74 View Code Duplication
    public function testGetBruteForceProtectionFailTolerance($appConfigValue, $expected) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
        $this->config->expects($this->once())->method('getAppValue')
76
            ->with('security', 'brute_force_protection_fail_tolerance', '3')
77
            ->willReturn($appConfigValue);
78
        $this->assertSame($expected,
79
            $this->securityConfig->getBruteForceProtectionFailTolerance()
80
        );
81
    }
82
    /**
83
     * @dataProvider numericConfTestData
84
     * @param string $appConfigValue
85
     * @param int $expected
86
     */
87 View Code Duplication
    public function testGetBruteForceProtectionTimeThreshold($appConfigValue, $expected) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
        $this->config->expects($this->once())->method('getAppValue')
89
            ->with('security', 'brute_force_protection_time_threshold', '600')
90
            ->willReturn($appConfigValue);
91
        $this->assertSame($expected,
92
            $this->securityConfig->getBruteForceProtectionTimeThreshold()
93
        );
94
    }
95
    /**
96
     * @dataProvider numericConfTestData
97
     * @param string $appConfigValue
98
     * @param int $expected
99
     */
100 View Code Duplication
    public function testGetBruteForceProtectionBanPeriod($appConfigValue, $expected) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
        $this->config->expects($this->once())->method('getAppValue')
102
            ->with('security', 'brute_force_protection_ban_period', '300')
103
            ->willReturn($appConfigValue);
104
        $this->assertSame($expected,
105
            $this->securityConfig->getBruteForceProtectionBanPeriod()
106
        );
107
    }
108
    /**
109
     * @dataProvider minPassTestData
110
     * @param string $appConfigValue
111
     * @param int $expected
112
     */
113 View Code Duplication
    public function testGetMinPasswordLength($appConfigValue, $expected) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
        $this->config->expects($this->once())->method('getAppValue')
115
            ->with('security', 'min_password_length', '8')
116
            ->willReturn($appConfigValue);
117
        $this->assertSame($expected,
118
            $this->securityConfig->getMinPasswordLength()
119
        );
120
    }
121
    /**
122
     * @dataProvider configTestData
123
     * @param string $appConfigValue
124
     * @param bool $expected
125
     */
126 View Code Duplication
    public function testGetIsUpperLowerCaseEnforced($appConfigValue, $expected) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
        $this->config->expects($this->once())->method('getAppValue')
128
            ->with('security', 'enforce_upper_lower_case', '0')
129
            ->willReturn($appConfigValue);
130
        $this->assertSame($expected,
131
            $this->securityConfig->getIsUpperLowerCaseEnforced()
132
        );
133
    }
134
    /**
135
     * @dataProvider configTestData
136
     * @param string $appConfigValue
137
     * @param bool $expected
138
     */
139 View Code Duplication
    public function testGetIsNumericCharactersEnforced($appConfigValue, $expected) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
140
        $this->config->expects($this->once())->method('getAppValue')
141
            ->with('security', 'enforce_numeric_characters', '0')
142
            ->willReturn($appConfigValue);
143
        $this->assertSame($expected,
144
            $this->securityConfig->getIsNumericCharactersEnforced()
145
        );
146
    }
147
    /**
148
     * @dataProvider configTestData
149
     * @param string $appConfigValue
150
     * @param bool $expected
151
     */
152 View Code Duplication
    public function testGetIsSpecialCharactersEnforced($appConfigValue, $expected) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
153
        $this->config->expects($this->once())->method('getAppValue')
154
            ->with('security', 'enforce_special_characters', '0')
155
            ->willReturn($appConfigValue);
156
        $this->assertSame($expected,
157
            $this->securityConfig->getIsSpecialCharactersEnforced()
158
        );
159
    }
160
    /**
161
     * @dataProvider numericConfTestData
162
     * @param string $expected
163
     * @param int $setValue
164
     */
165
    public function testSetBruteForceProtectionFailTolerance($expected, $setValue) {
166
        $this->config->expects($this->once())->method('setAppValue')
167
            ->with('security', 'brute_force_protection_fail_tolerance', $expected);
168
        $this->securityConfig->setBruteForceProtectionFailTolerance($setValue);
169
    }
170
    /**
171
     * @dataProvider numericConfTestData
172
     * @param string $expected
173
     * @param int $setValue
174
     */
175
    public function testSetBruteForceProtectionTimeThreshold($expected, $setValue) {
176
        $this->config->expects($this->once())->method('setAppValue')
177
            ->with('security', 'brute_force_protection_time_threshold', $expected);
178
        $this->securityConfig->setBruteForceProtectionTimeThreshold($setValue);
179
    }
180
    /**
181
     * @dataProvider numericConfTestData
182
     * @param string $expected
183
     * @param int $setValue
184
     */
185
    public function testSetBruteForceProtectionBanPeriod($expected, $setValue) {
186
        $this->config->expects($this->once())->method('setAppValue')
187
            ->with('security', 'brute_force_protection_ban_period', $expected);
188
        $this->securityConfig->setBruteForceProtectionBanPeriod($setValue);
189
    }
190
    /**
191
     * @dataProvider minPassTestData
192
     * @param string $expected
193
     * @param int $setValue
194
     */
195
    public function testSetMinPasswordLength($expected, $setValue) {
196
        $this->config->expects($this->once())->method('setAppValue')
197
            ->with('security', 'min_password_length', $expected);
198
        $this->securityConfig->setMinPasswordLength($setValue);
199
    }
200
    /**
201
     * @dataProvider configTestData
202
     * @param string $expected
203
     * @param bool $setValue
204
     */
205
    public function testSetIsUpperLowerCaseEnforced($expected, $setValue) {
206
        $this->config->expects($this->once())->method('setAppValue')
207
            ->with('security', 'enforce_upper_lower_case', $expected);
208
        $this->securityConfig->setIsUpperLowerCaseEnforced($setValue);
209
    }
210
    /**
211
     * @dataProvider configTestData
212
     * @param string $expected
213
     * @param bool $setValue
214
     */
215
    public function testSetIsNumericCharactersEnforced($expected, $setValue) {
216
        $this->config->expects($this->once())->method('setAppValue')
217
            ->with('security', 'enforce_numeric_characters', $expected);
218
        $this->securityConfig->setIsNumericCharactersEnforced($setValue);
219
    }
220
    /**
221
     * @dataProvider configTestData
222
     * @param string $expected
223
     * @param bool $setValue
224
     */
225
    public function testSetIsSpecialCharactersEnforced($expected, $setValue) {
226
        $this->config->expects($this->once())->method('setAppValue')
227
            ->with('security', 'enforce_special_characters', $expected);
228
        $this->securityConfig->setIsSpecialCharactersEnforced($setValue);
229
    }
230
    public function configTestData() {
231
        return [
232
            ['1', true],
233
            ['0', false],
234
        ];
235
    }
236
    public function minPassTestData() {
237
        return [
238
            ['8', 8],
239
            ['16', 16],
240
            ['255', 255]
241
        ];
242
    }
243
    public function numericConfTestData() {
244
        return [
245
            ['42', 42],
246
            ['300', 300],
247
            ['1000', 1000]
248
        ];
249
    }
250
251
}