Issues (65)

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/ByPropertyIdGrouperTest.php (2 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 Wikibase\DataModel\Services\Tests;
4
5
use ArrayObject;
6
use InvalidArgumentException;
7
use OutOfBoundsException;
8
use PHPUnit\Framework\TestCase;
9
use Wikibase\DataModel\Entity\PropertyId;
10
use Wikibase\DataModel\PropertyIdProvider;
11
use Wikibase\DataModel\Services\ByPropertyIdGrouper;
12
use Wikibase\DataModel\Snak\Snak;
13
14
/**
15
 * @covers \Wikibase\DataModel\Services\ByPropertyIdGrouper
16
 *
17
 * @license GPL-2.0-or-later
18
 * @author Bene* < [email protected] >
19
 * @author Thiemo Kreuz
20
 */
21
class ByPropertyIdGrouperTest extends TestCase {
22
23
	/**
24
	 * @dataProvider validConstructorArgumentProvider
25
	 */
26
	public function testConstructor( $argument ) {
27
		$instance = new ByPropertyIdGrouper( $argument );
28
		$this->assertCount( count( $argument ), $instance->getPropertyIds() );
0 ignored issues
show
$instance->getPropertyIds() is of type array<integer,object<Wik...del\Entity\PropertyId>>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
29
	}
30
31
	public function validConstructorArgumentProvider() {
32
		return [
33
			[ [] ],
34
			[ [ $this->getPropertyIdProviderMock( 'P1' ) ] ],
35
			[ new ArrayObject() ],
36
			[ new ArrayObject( [ $this->getPropertyIdProviderMock( 'P1' ) ] ) ],
37
		];
38
	}
39
40
	/**
41
	 * @dataProvider invalidConstructorArgumentProvider
42
	 */
43
	public function testConstructorThrowsException( $argument ) {
44
		$this->expectException( InvalidArgumentException::class );
45
		new ByPropertyIdGrouper( $argument );
46
	}
47
48
	public function invalidConstructorArgumentProvider() {
49
		return [
50
			[ null ],
51
			[ 'notAnObject' ],
52
			[ [ null ] ],
53
			[ [ 'notAnObject' ] ],
54
			[ new ArrayObject( [ null ] ) ],
55
			[ new ArrayObject( [ 'notAnObject' ] ) ],
56
		];
57
	}
58
59
	public function provideGetPropertyIds() {
60
		$cases = [];
61
62
		$cases['empty list'] = [
63
			[],
64
			[]
65
		];
66
67
		$cases['some property ids'] = [
68
			[
69
				$this->getPropertyIdProviderMock( 'P42' ),
70
				$this->getPropertyIdProviderMock( 'P23' )
71
			],
72
			[
73
				new PropertyId( 'P42' ),
74
				new PropertyId( 'P23' )
75
			]
76
		];
77
78
		$cases['duplicate property ids'] = [
79
			$this->getPropertyIdProviders(),
80
			[
81
				new PropertyId( 'P42' ),
82
				new PropertyId( 'P23' ),
83
				new PropertyId( 'P15' ),
84
				new PropertyId( 'P10' )
85
			]
86
		];
87
88
		return $cases;
89
	}
90
91
	/**
92
	 * @dataProvider provideGetPropertyIds
93
	 * @param PropertyIdProvider[] $propertyIdProviders
94
	 * @param PropertyId[] $expectedPropertyIds
95
	 */
96
	public function testGetPropertyIds( array $propertyIdProviders, array $expectedPropertyIds ) {
97
		$byPropertyIdGrouper = new ByPropertyIdGrouper( $propertyIdProviders );
98
		$propertyIds = $byPropertyIdGrouper->getPropertyIds();
99
		$this->assertEquals( $expectedPropertyIds, $propertyIds );
100
	}
101
102
	public function provideGetByPropertyId() {
103
		$cases = [];
104
105
		$cases[] = [
106
			$this->getPropertyIdProviders(),
107
			'P42',
108
			[ 'abc', 'jkl' ]
109
		];
110
111
		$cases[] = [
112
			$this->getPropertyIdProviders(),
113
			'P23',
114
			[ 'def' ]
115
		];
116
117
		return $cases;
118
	}
119
120
	/**
121
	 * @dataProvider provideGetByPropertyId
122
	 */
123
	public function testGetByPropertyId( array $propertyIdProviders, $propertyId, array $expectedValues ) {
124
		$byPropertyIdGrouper = new ByPropertyIdGrouper( $propertyIdProviders );
125
		$values = $byPropertyIdGrouper->getByPropertyId( new PropertyId( $propertyId ) );
126
		array_walk( $values, function( Snak &$value ) {
127
			$value = $value->getType();
128
		} );
129
		$this->assertEquals( $expectedValues, $values );
130
	}
131
132
	public function testGetByPropertyIdThrowsException() {
133
		$byPropertyIdGrouper = new ByPropertyIdGrouper( $this->getPropertyIdProviders() );
0 ignored issues
show
$this->getPropertyIdProviders() is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Wik...r>>|object<Traversable>.

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...
134
		$this->expectException( OutOfBoundsException::class );
135
		$byPropertyIdGrouper->getByPropertyId( new PropertyId( 'P11' ) );
136
	}
137
138
	public function provideHasPropertyId() {
139
		$cases = [];
140
141
		$cases[] = [ $this->getPropertyIdProviders(), 'P42', true ];
142
		$cases[] = [ $this->getPropertyIdProviders(), 'P23', true ];
143
		$cases[] = [ $this->getPropertyIdProviders(), 'P15', true ];
144
		$cases[] = [ $this->getPropertyIdProviders(), 'P10', true ];
145
		$cases[] = [ $this->getPropertyIdProviders(), 'P11', false ];
146
147
		return $cases;
148
	}
149
150
	/**
151
	 * @dataProvider provideHasPropertyId
152
	 */
153
	public function testHasPropertyId( array $propertyIdProviders, $propertyId, $expectedValue ) {
154
		$byPropertyIdGrouper = new ByPropertyIdGrouper( $propertyIdProviders );
155
		$this->assertEquals( $expectedValue, $byPropertyIdGrouper->hasPropertyId( new PropertyId( $propertyId ) ) );
156
	}
157
158
	/**
159
	 * @return PropertyIdProvider[]
160
	 */
161
	private function getPropertyIdProviders() {
162
		return [
163
			$this->getPropertyIdProviderMock( 'P42', 'abc' ),
164
			$this->getPropertyIdProviderMock( 'P23', 'def' ),
165
			$this->getPropertyIdProviderMock( 'P15', 'ghi' ),
166
			$this->getPropertyIdProviderMock( 'P42', 'jkl' ),
167
			$this->getPropertyIdProviderMock( 'P10', 'mno' )
168
		];
169
	}
170
171
	/**
172
	 * Creates a PropertyIdProvider mock which can return a value.
173
	 *
174
	 * @param string $propertyId
175
	 * @param string|null $type
176
	 *
177
	 * @return PropertyIdProvider
178
	 */
179
	private function getPropertyIdProviderMock( $propertyId, $type = null ) {
180
		$propertyIdProvider = $this->createMock( Snak::class );
181
182
		$propertyIdProvider->expects( $this->once() )
183
			->method( 'getPropertyId' )
184
			->will( $this->returnValue( new PropertyId( $propertyId ) ) );
185
186
		$propertyIdProvider->expects( $this->any() )
187
			->method( 'getType' )
188
			->will( $this->returnValue( $type ) );
189
190
		return $propertyIdProvider;
191
	}
192
193
}
194