Issues (51)

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/php/controller/settingscontrollerTest.php (26 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
 * Calendar App
4
 *
5
 * @author Georg Ehrke
6
 * @copyright 2016 Georg Ehrke <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
namespace OCA\Calendar\Controller;
23
24
use PHPUnit\Framework\TestCase;
25
26
class SettingsControllerTest extends TestCase {
27
28
	private $appName;
29
	private $request;
30
	private $userSession;
31
	private $config;
32
33
	private $dummyUser;
34
35
	private $controller;
36
37
	public function setUp() {
38
		$this->appName = 'calendar';
39
		$this->request = $this->getMockBuilder('\OCP\IRequest')
40
			->disableOriginalConstructor()
41
			->getMock();
42
		$this->userSession = $this->getMockBuilder('OCP\IUserSession')
43
			->disableOriginalConstructor()
44
			->getMock();
45
		$this->config = $this->getMockBuilder('OCP\IConfig')
46
			->disableOriginalConstructor()
47
			->getMock();
48
49
		$this->dummyUser = $this->getMockBuilder('OCP\IUser')
50
			->disableOriginalConstructor()
51
			->getMock();
52
53
		$this->userSession->expects($this->once())
54
			->method('getUser')
55
			->will($this->returnValue($this->dummyUser));
56
57
		$this->dummyUser->expects($this->once())
58
			->method('getUID')
59
			->will($this->returnValue('user123'));
60
61
		$this->controller = new SettingsController($this->appName,
62
			$this->request, $this->userSession, $this->config);
63
	}
64
65
	/**
66
	 * @dataProvider setViewWithAllowedViewDataProvider
67
	 */
68
	public function testSetViewWithAllowedView($view) {
69
		$this->config->expects($this->once())
70
			->method('setUserValue')
71
			->with('user123', $this->appName, 'currentView', $view);
72
73
		$actual = $this->controller->setConfig('view', $view);
74
75
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
76
		$this->assertEquals([], $actual->getData());
77
		$this->assertEquals(200, $actual->getStatus());
78
	}
79
80
	public function setViewWithAllowedViewDataProvider() {
81
		return [
82
			['agendaDay'],
83
			['agendaWeek'],
84
			['month'],
85
		];
86
	}
87
88 View Code Duplication
	public function testSetViewWithForbiddenView() {
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...
89
		$actual = $this->controller->setConfig('view','someForbiddenView');
90
91
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
92
		$this->assertEquals([], $actual->getData());
93
		$this->assertEquals(422, $actual->getStatus());
94
	}
95
96 View Code Duplication
	public function testSetViewWithConfigException() {
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...
97
		$this->config->expects($this->once())
98
			->method('setUserValue')
99
			->with('user123', $this->appName, 'currentView', 'month')
100
			->will($this->throwException(new \Exception));
0 ignored issues
show
new \Exception() is of type object<Exception>, but the function expects a object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
101
102
		$actual = $this->controller->setConfig('view', 'month');
103
104
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
105
		$this->assertEquals([], $actual->getData());
106
		$this->assertEquals(500, $actual->getStatus());
107
	}
108
109 View Code Duplication
	public function testGetView() {
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...
110
		$this->config->expects($this->once())
111
			->method('getUserValue')
112
			->with('user123', $this->appName, 'currentView', 'month')
113
			->will($this->returnValue('agendaWeek'));
114
115
		$actual = $this->controller->getConfig('view');
116
117
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
118
		$this->assertEquals(['value' => 'agendaWeek'], $actual->getData());
119
		$this->assertEquals(200, $actual->getStatus());
120
	}
121
122 View Code Duplication
	public function testGetViewWithConfigException() {
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...
123
		$this->config->expects($this->once())
124
			->method('getUserValue')
125
			->with('user123', $this->appName, 'currentView', 'month')
126
			->will($this->throwException(new \Exception));
0 ignored issues
show
new \Exception() is of type object<Exception>, but the function expects a object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
127
128
		$actual = $this->controller->getConfig('view');
129
130
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
131
		$this->assertEquals([], $actual->getData());
132
		$this->assertEquals(500, $actual->getStatus());
133
	}
134
135
	/**
136
	 * @dataProvider setPopoverWithAllowedValueDataProvider
137
	 */
138
	public function testSetPopoverWithAllowedValue($value) {
139
		$this->config->expects($this->once())
140
			->method('setUserValue')
141
			->with('user123', $this->appName, 'skipPopover', $value);
142
143
		$actual = $this->controller->setConfig('skipPopover', $value);
144
145
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
146
		$this->assertEquals([], $actual->getData());
147
		$this->assertEquals(200, $actual->getStatus());
148
	}
149
150
	public function setPopoverWithAllowedValueDataProvider() {
151
		return [
152
			['yes'],
153
			['no']
154
		];
155
	}
156
157 View Code Duplication
	public function testSetPopoverWithForbiddenValue() {
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...
158
		$actual = $this->controller->setConfig('skipPopover','someForbiddenValue');
159
160
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
161
		$this->assertEquals([], $actual->getData());
162
		$this->assertEquals(422, $actual->getStatus());
163
	}
164
165 View Code Duplication
	public function testSetPopoverWithConfigException() {
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...
166
		$this->config->expects($this->once())
167
			->method('setUserValue')
168
			->with('user123', $this->appName, 'skipPopover', 'no')
169
			->will($this->throwException(new \Exception));
0 ignored issues
show
new \Exception() is of type object<Exception>, but the function expects a object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
170
171
		$actual = $this->controller->setConfig('skipPopover', 'no');
172
173
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
174
		$this->assertEquals([], $actual->getData());
175
		$this->assertEquals(500, $actual->getStatus());
176
	}
177
178 View Code Duplication
	public function testGetPopover() {
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...
179
		$this->config->expects($this->once())
180
			->method('getUserValue')
181
			->with('user123', $this->appName, 'skipPopover', 'no')
182
			->will($this->returnValue('agendaWeek'));
183
184
		$actual = $this->controller->getConfig('skipPopover');
185
186
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
187
		$this->assertEquals(['value' => 'agendaWeek'], $actual->getData());
188
		$this->assertEquals(200, $actual->getStatus());
189
	}
190
191 View Code Duplication
	public function testGetPopoverWithConfigException() {
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...
192
		$this->config->expects($this->once())
193
			->method('getUserValue')
194
			->with('user123', $this->appName, 'skipPopover', 'no')
195
			->will($this->throwException(new \Exception));
0 ignored issues
show
new \Exception() is of type object<Exception>, but the function expects a object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
196
197
		$actual = $this->controller->getConfig('skipPopover');
198
199
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
200
		$this->assertEquals([], $actual->getData());
201
		$this->assertEquals(500, $actual->getStatus());
202
	}
203
204 View Code Duplication
	public function testSetFirstRun() {
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...
205
		$this->config->expects($this->once())
206
			->method('setUserValue')
207
			->with('user123', $this->appName, 'firstRun', 'no');
208
209
		$actual = $this->controller->setConfig('firstRun', 'some_random_ignored_value');
210
211
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
212
		$this->assertEquals([], $actual->getData());
213
		$this->assertEquals(200, $actual->getStatus());
214
	}
215
216 View Code Duplication
	public function testSetFirstRunWithException() {
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...
217
		$this->config->expects($this->once())
218
			->method('setUserValue')
219
			->with('user123', $this->appName, 'firstRun', 'no')
220
			->will($this->throwException(new \Exception));
0 ignored issues
show
new \Exception() is of type object<Exception>, but the function expects a object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
221
222
		$actual = $this->controller->setConfig('firstRun', 'some_random_ignored_value');
223
224
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
225
		$this->assertEquals([], $actual->getData());
226
		$this->assertEquals(500, $actual->getStatus());
227
	}
228
229 View Code Duplication
	public function testGetFirstRun() {
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...
230
		$this->config->expects($this->once())
231
			->method('getUserValue')
232
			->with('user123', $this->appName, 'firstRun', 'yes')
233
			->will($this->returnValue('no'));
234
235
		$actual = $this->controller->getConfig('firstRun');
236
237
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
238
		$this->assertEquals(['value' => 'no'], $actual->getData());
239
		$this->assertEquals(200, $actual->getStatus());
240
	}
241
242 View Code Duplication
	public function testGetFirstRunWithException() {
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...
243
		$this->config->expects($this->once())
244
			->method('getUserValue')
245
			->with('user123', $this->appName, 'firstRun', 'yes')
246
			->will($this->throwException(new \Exception));
0 ignored issues
show
new \Exception() is of type object<Exception>, but the function expects a object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
247
248
		$actual = $this->controller->getConfig('firstRun');
249
250
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
251
		$this->assertEquals([], $actual->getData());
252
		$this->assertEquals(500, $actual->getStatus());
253
	}
254
255 View Code Duplication
	public function testSetTimezone() {
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...
256
		$this->config->expects($this->once())
257
			->method('setUserValue')
258
			->with('user123', $this->appName, 'timezone', 'Europe/Berlin');
259
260
		$actual = $this->controller->setConfig('timezone', 'Europe/Berlin');
261
262
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
263
		$this->assertEquals([], $actual->getData());
264
		$this->assertEquals(200, $actual->getStatus());
265
	}
266
267 View Code Duplication
	public function testSetTimezoneWithException() {
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...
268
		$this->config->expects($this->once())
269
			->method('setUserValue')
270
			->with('user123', $this->appName, 'timezone', 'Europe/Berlin')
271
			->will($this->throwException(new \Exception));
0 ignored issues
show
new \Exception() is of type object<Exception>, but the function expects a object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
272
273
		$actual = $this->controller->setConfig('timezone', 'Europe/Berlin');
274
275
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
276
		$this->assertEquals([], $actual->getData());
277
		$this->assertEquals(500, $actual->getStatus());
278
	}
279
280 View Code Duplication
	public function testGetTimezone() {
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...
281
		$this->config->expects($this->once())
282
			->method('getUserValue')
283
			->with('user123', $this->appName, 'timezone', 'automatic')
284
			->will($this->returnValue('Europe/Berlin'));
285
286
		$actual = $this->controller->getConfig('timezone');
287
288
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
289
		$this->assertEquals(['value' => 'Europe/Berlin'], $actual->getData());
290
		$this->assertEquals(200, $actual->getStatus());
291
	}
292
293 View Code Duplication
	public function testGetTimezoneWithException() {
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...
294
		$this->config->expects($this->once())
295
			->method('getUserValue')
296
			->with('user123', $this->appName, 'timezone', 'automatic')
297
			->will($this->throwException(new \Exception));
0 ignored issues
show
new \Exception() is of type object<Exception>, but the function expects a object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
298
299
		$actual = $this->controller->getConfig('timezone');
300
301
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
302
		$this->assertEquals([], $actual->getData());
303
		$this->assertEquals(500, $actual->getStatus());
304
	}
305
306 View Code Duplication
	public function testGetNotExistingConfig() {
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...
307
		$actual = $this->controller->getConfig('foo');
308
		
309
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
310
		$this->assertEquals([], $actual->getData());
311
		$this->assertEquals(400, $actual->getStatus());
312
	}
313
314 View Code Duplication
	public function testSetNotExistingConfig() {
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...
315
		$actual = $this->controller->setConfig('foo', 'bar');
316
317
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
318
		$this->assertEquals([], $actual->getData());
319
		$this->assertEquals(400, $actual->getStatus());
320
	}
321
}
322