Issues (67)

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/unit/Serializers/ItemSerializerTest.php (4 issues)

Severity

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 Tests\Wikibase\DataModel\Serializers;
4
5
use Serializers\Serializer;
6
use Wikibase\DataModel\Entity\Item;
7
use Wikibase\DataModel\Entity\ItemId;
8
use Wikibase\DataModel\Entity\Property;
9
use Wikibase\DataModel\Serializers\ItemSerializer;
10
use Wikibase\DataModel\SiteLink;
11
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
12
use Wikibase\DataModel\Statement\StatementList;
13
use Wikibase\DataModel\Term\AliasGroupList;
14
use Wikibase\DataModel\Term\TermList;
15
16
/**
17
 * @covers Wikibase\DataModel\Serializers\ItemSerializer
18
 *
19
 * @license GPL-2.0-or-later
20
 * @author Thomas Pellissier Tanon
21
 * @author Jan Zerebecki < [email protected] >
22
 * @author Bene* < [email protected] >
23
 */
24
class ItemSerializerTest extends DispatchableSerializerTest {
25
26
	protected function buildSerializer( $useObjectsForMaps = false ) {
27
		$termListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock();
28
		$termListSerializerMock->expects( $this->any() )
29
			->method( 'serialize' )
30
			->will( $this->returnCallback( function( TermList $termList ) {
31
				if ( $termList->isEmpty() ) {
32
					return [];
33
				}
34
35
				return [
36
					'en' => [ 'lang' => 'en', 'value' => 'foo' ]
37
				];
38
			} ) );
39
40
		$aliasGroupListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock();
41
		$aliasGroupListSerializerMock->expects( $this->any() )
42
			->method( 'serialize' )
43
			->will( $this->returnCallback( function( AliasGroupList $aliasGroupList ) {
44
				if ( $aliasGroupList->isEmpty() ) {
45
					return [];
46
				}
47
48
				return [
49
					'en' => [ 'lang' => 'en', 'values' => [ 'foo', 'bar' ] ]
50
				];
51
			} ) );
52
53
		$statementListSerializerMock = $this->getMockBuilder( Serializer::class )->getMock();
54
		$statementListSerializerMock->expects( $this->any() )
55
			->method( 'serialize' )
56
			->will( $this->returnCallback( function( StatementList $statementList ) {
57
				if ( $statementList->isEmpty() ) {
58
					return [];
59
				}
60
61
				return [
62
					'P42' => [
63
						[
64
							'mainsnak' => [
65
								'snaktype' => 'novalue',
66
								'property' => 'P42'
67
							],
68
							'type' => 'statement',
69
							'rank' => 'normal'
70
						]
71
					]
72
				];
73
			} ) );
74
75
		$siteLinkSerializerMock = $this->getMockBuilder( Serializer::class )->getMock();
76
		$siteLinkSerializerMock->expects( $this->any() )
77
			->method( 'serialize' )
78
			->with( $this->equalTo( new SiteLink( 'enwiki', 'Nyan Cat' ) ) )
79
			->will( $this->returnValue( [
80
				'site' => 'enwiki',
81
				'title' => 'Nyan Cat',
82
				'badges' => []
83
			] ) );
84
85
		return new ItemSerializer(
86
			$termListSerializerMock,
0 ignored issues
show
$termListSerializerMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Serializers\Serializer>.

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...
87
			$aliasGroupListSerializerMock,
0 ignored issues
show
$aliasGroupListSerializerMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Serializers\Serializer>.

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...
88
			$statementListSerializerMock,
0 ignored issues
show
$statementListSerializerMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Serializers\Serializer>.

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...
89
			$siteLinkSerializerMock,
0 ignored issues
show
$siteLinkSerializerMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Serializers\Serializer>.

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...
90
			$useObjectsForMaps
91
		);
92
	}
93
94
	public function serializableProvider() {
95
		return [
96
			[ new Item() ],
97
		];
98
	}
99
100
	public function nonSerializableProvider() {
101
		return [
102
			[ 5 ],
103
			[ [] ],
104
			[ Property::newFromType( 'string' ) ],
105
		];
106
	}
107
108
	public function serializationProvider() {
109
		$provider = [
110
			[
111
				[
112
					'type' => 'item',
113
					'labels' => [],
114
					'descriptions' => [],
115
					'aliases' => [],
116
					'claims' => [],
117
					'sitelinks' => [],
118
				],
119
				new Item()
120
			],
121
		];
122
123
		$entity = new Item( new ItemId( 'Q42' ) );
124
		$provider[] = [
125
			[
126
				'type' => 'item',
127
				'id' => 'Q42',
128
				'labels' => [],
129
				'descriptions' => [],
130
				'aliases' => [],
131
				'claims' => [],
132
				'sitelinks' => [],
133
			],
134
			$entity
135
		];
136
137
		$entity = new Item();
138
		$entity->setLabel( 'en', 'foo' );
139
		$provider[] = [
140
			[
141
				'type' => 'item',
142
				'labels' => [
143
					'en' => [
144
						'lang' => 'en',
145
						'value' => 'foo'
146
					]
147
				],
148
				'descriptions' => [],
149
				'aliases' => [],
150
				'claims' => [],
151
				'sitelinks' => [],
152
			],
153
			$entity
154
		];
155
156
		$entity = new Item();
157
		$entity->setDescription( 'en', 'foo' );
158
		$provider[] = [
159
			[
160
				'type' => 'item',
161
				'labels' => [],
162
				'descriptions' => [
163
					'en' => [
164
						'lang' => 'en',
165
						'value' => 'foo'
166
					]
167
				],
168
				'aliases' => [],
169
				'claims' => [],
170
				'sitelinks' => [],
171
			],
172
			$entity
173
		];
174
175
		$entity = new Item();
176
		$entity->setAliases( 'en', [ 'foo', 'bar' ] );
177
		$provider[] = [
178
			[
179
				'type' => 'item',
180
				'labels' => [],
181
				'descriptions' => [],
182
				'aliases' => [
183
					'en' => [
184
						'lang' => 'en',
185
						'values' => [ 'foo', 'bar' ]
186
					]
187
				],
188
				'claims' => [],
189
				'sitelinks' => [],
190
			],
191
			$entity
192
		];
193
194
		$entity = new Item();
195
		$entity->getStatements()->addNewStatement( new PropertyNoValueSnak( 42 ), null, null, 'test' );
196
		$provider[] = [
197
			[
198
				'type' => 'item',
199
				'labels' => [],
200
				'descriptions' => [],
201
				'aliases' => [],
202
				'claims' => [
203
					'P42' => [
204
						[
205
							'mainsnak' => [
206
								'snaktype' => 'novalue',
207
								'property' => 'P42'
208
							],
209
							'type' => 'statement',
210
							'rank' => 'normal'
211
						]
212
					]
213
				],
214
				'sitelinks' => [],
215
			],
216
			$entity
217
		];
218
219
		$item = new Item();
220
		$item->getSiteLinkList()->addNewSiteLink( 'enwiki', 'Nyan Cat' );
221
		$provider[] = [
222
			[
223
				'type' => 'item',
224
				'labels' => [],
225
				'descriptions' => [],
226
				'aliases' => [],
227
				'claims' => [],
228
				'sitelinks' => [
229
					'enwiki' => [
230
						'site' => 'enwiki',
231
						'title' => 'Nyan Cat',
232
						'badges' => []
233
					]
234
				],
235
			],
236
			$item
237
		];
238
239
		return $provider;
240
	}
241
242
	public function testItemSerializerWithOptionObjectsForMaps() {
243
		$serializer = $this->buildSerializer( true );
244
245
		$item = new Item();
246
		$item->getSiteLinkList()->addNewSiteLink( 'enwiki', 'Nyan Cat' );
247
248
		$sitelinks = new \stdClass();
249
		$sitelinks->enwiki = [
250
			'site' => 'enwiki',
251
			'title' => 'Nyan Cat',
252
			'badges' => [],
253
		];
254
255
		$serial = [
256
			'type' => 'item',
257
			'labels' => [],
258
			'descriptions' => [],
259
			'aliases' => [],
260
			'claims' => [],
261
			'sitelinks' => $sitelinks,
262
		];
263
264
		$this->assertEquals( $serial, $serializer->serialize( $item ) );
265
	}
266
267
}
268