Issues (14)

Security Analysis    not enabled

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/src/ValidatorTest.php (4 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
namespace HelePartnerSyncApi;
4
5
use DateTime;
6
use PHPUnit_Framework_TestCase;
7
use stdClass;
8
9
class ValidatorTest extends PHPUnit_Framework_TestCase
10
{
11
12
	public function testValidExamples()
13
	{
14
		$now = new DateTime();
15
		Validator::checkNull(null);
16
		Validator::checkString('true');
17
		Validator::checkString('0');
18
		Validator::checkString('1.9');
19
		Validator::checkString('array');
20
		Validator::checkInt(121);
21
		Validator::checkInt(-78);
22
		Validator::checkInt(0);
23
		Validator::checkDateTime($now);
24
		Validator::checkDateTimeString($now->format(DATE_W3C));
25
		$this->assertTrue(true);
26
	}
27
28
	/**
29
	 * @return mixed[][]
30
	 */
31 View Code Duplication
	public function provideInvalidNulls()
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...
32
	{
33
		return array(
34
			array(true),
35
			array(false),
36
			array(0),
37
			array(0.0),
38
			array(array()),
39
		);
40
	}
41
42
	/**
43
	 * @param mixed $value
44
	 *
45
	 * @dataProvider provideInvalidNulls
46
	 * @expectedException \HelePartnerSyncApi\ValidatorException
47
	 * @expectedExceptionMessage Null expected
48
	 */
49
	public function testCheckInvalidNulls($value)
50
	{
51
		Validator::checkNull($value);
52
	}
53
54
	/**
55
	 * @return mixed[][]
56
	 */
57 View Code Duplication
	public function provideInvalidStrings()
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...
58
	{
59
		return array(
60
			array(true),
61
			array(0.5),
62
			array(1212),
63
			array(null),
64
			array(array()),
65
		);
66
	}
67
68
	/**
69
	 * @param mixed $value
70
	 *
71
	 * @dataProvider provideInvalidStrings
72
	 * @expectedException \HelePartnerSyncApi\ValidatorException
73
	 * @expectedExceptionMessage String expected
74
	 */
75
	public function testCheckInvalidStrings($value)
76
	{
77
		Validator::checkString($value);
78
	}
79
80
	/**
81
	 * @return mixed[][]
82
	 */
83
	public function provideInvalidInts()
84
	{
85
		return array(
86
			array('1212'),
87
			array(true),
88
			array(0.5),
89
			array(null),
90
			array(array()),
91
			array(new stdClass()),
92
		);
93
	}
94
95
	/**
96
	 * @param mixed $value
97
	 *
98
	 * @dataProvider provideInvalidInts
99
	 * @expectedException \HelePartnerSyncApi\ValidatorException
100
	 * @expectedExceptionMessage Int expected
101
	 */
102
	public function testCheckInvalidIntegers($value)
103
	{
104
		Validator::checkInt($value);
105
	}
106
107
	public function testCheckValidStructures()
108
	{
109
		Validator::checkStructure(array(-1, 0, 1), array(Validator::TYPE_INT));
110
111
		Validator::checkStructure(array(
112
			'key' => 123,
113
			'data' => array(
114
				'text' => 'abc',
115
			),
116
		), array(
117
			'key' => Validator::TYPE_INT,
118
			'data' => array(
119
				'text' => Validator::TYPE_STRING,
120
			),
121
		));
122
123
		Validator::checkStructure(array(
124
			array(
125
				'from' => 12,
126
				'to' => 16,
127
			),
128
			array(
129
				'from' => 17,
130
				'to' => 22,
131
			),
132
		), array(
133
			array(
134
				'from' => Validator::TYPE_INT,
135
				'to' => Validator::TYPE_INT,
136
			),
137
		));
138
139
		$this->assertTrue(true);
140
	}
141
142
	/**
143
	 * @expectedException \HelePartnerSyncApi\ValidatorException
144
	 * @expectedExceptionMessage Invalid type in key 'foo': Int expected, array given.
145
	 */
146
	public function testCheckInvalidStructuresBasic()
147
	{
148
		Validator::checkStructure(array(
149
			'moo' => 0,
150
			'foo' => array(),
151
		), array(
152
			'moo' => Validator::TYPE_INT,
153
			'foo' => Validator::TYPE_INT,
154
		));
155
	}
156
157
	/**
158
	 * @expectedException \HelePartnerSyncApi\ValidatorException
159
	 * @expectedExceptionMessage Expected list structure in root
160
	 */
161
	public function testCheckInvalidStructureNotAList()
162
	{
163
		Validator::checkStructure(array(1, 2, 'key' => 'not-a-list'), array(Validator::TYPE_INT));
164
	}
165
166
	/**
167
	 * @expectedException \HelePartnerSyncApi\ValidatorException
168
	 * @expectedExceptionMessage Invalid type in key '2': Int expected, string (3) given.
169
	 */
170
	public function testCheckInvalidStructureListElement()
171
	{
172
		Validator::checkStructure(array(1, 2, '3'), array(Validator::TYPE_INT));
173
	}
174
175
	/**
176
	 * @expectedException \HelePartnerSyncApi\ValidatorException
177
	 * @expectedExceptionMessage Invalid type in key '2': Array expected, string (what?) given.
178
	 */
179 View Code Duplication
	public function testCheckInvalidStructureNonArrayElement()
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...
180
	{
181
		Validator::checkStructure(array(
182
			array(
183
				'moo' => 1,
184
			),
185
			array(
186
				'moo' => 2,
187
			),
188
			'what?'
189
		), array(
190
			array(
191
				'moo' => Validator::TYPE_INT,
192
			)
193
		));
194
	}
195
196
	/**
197
	 * @expectedException \HelePartnerSyncApi\ValidatorException
198
	 * @expectedExceptionMessage Invalid type in path 'foo.bar': Int expected, string (moo) given.
199
	 */
200 View Code Duplication
	public function testCheckInvalidStructuresDeep()
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...
201
	{
202
		Validator::checkStructure(array(
203
			'boo' => null,
204
			'foo' => array(
205
				'bar' => 'moo',
206
			),
207
		), array(
208
			'boo' => Validator::TYPE_NULL,
209
			'foo' => array(
210
				'bar' => Validator::TYPE_INT,
211
			),
212
		));
213
	}
214
215
	/**
216
	 * @expectedException \HelePartnerSyncApi\ValidatorException
217
	 * @expectedExceptionMessage Missing keys (bar, foo) in root
218
	 */
219
	public function testCheckInvalidStructuresMissingKeys()
220
	{
221
		Validator::checkStructure(array(), array(
222
			'bar' => Validator::TYPE_INT,
223
			'foo' => Validator::TYPE_INT,
224
		));
225
	}
226
227
	/**
228
	 * @expectedException \HelePartnerSyncApi\ValidatorException
229
	 * @expectedExceptionMessage Unknown keys (foo, bar) in root
230
	 */
231
	public function testCheckInvalidStructuresUnknownKeys()
232
	{
233
		Validator::checkStructure(array(
234
			'foo' => 'foo',
235
			'bar' => 'bar',
236
		), array(
237
			'moo' => Validator::TYPE_INT,
238
		));
239
	}
240
241
}
242