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/Lookup/DispatchingEntityLookupTest.php (3 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\Lookup;
4
5
use Exception;
6
use PHPUnit\Framework\TestCase;
7
use Wikibase\DataModel\Entity\ItemId;
8
use Wikibase\DataModel\Entity\PropertyId;
9
use Wikibase\DataModel\Services\Fixtures\FakeEntityDocument;
10
use Wikibase\DataModel\Services\Lookup\DispatchingEntityLookup;
11
use Wikibase\DataModel\Services\Lookup\EntityLookup;
12
use Wikibase\DataModel\Services\Lookup\EntityLookupException;
13
use Wikibase\DataModel\Services\Lookup\InMemoryEntityLookup;
14
use Wikimedia\Assert\ParameterAssertionException;
15
16
/**
17
 * @covers \Wikibase\DataModel\Services\Lookup\DispatchingEntityLookup
18
 *
19
 * @license GPL-2.0-or-later
20
 */
21
class DispatchingEntityLookupTest extends TestCase {
22
23
	/**
24
	 * @dataProvider provideInvalidForeignLookups
25
	 */
26
	public function testGivenInvalidForeignLookups_exceptionIsThrown( array $lookups ) {
27
		$this->expectException( ParameterAssertionException::class );
28
		new DispatchingEntityLookup( $lookups );
29
	}
30
31
	public function provideInvalidForeignLookups() {
32
		return [
33
			'no lookups given' => [ [] ],
34
			'not an implementation of EntityLookup given as a lookup' => [
35
				[ '' => new ItemId( 'Q123' ) ],
36
			],
37
			'non-string keys' => [
38
				[ '' => new InMemoryEntityLookup(), 100 => new InMemoryEntityLookup(), ],
39
			],
40
			'repo name containing colon' => [
41
				[ '' => new InMemoryEntityLookup(),	'fo:oo' => new InMemoryEntityLookup(), ],
42
			],
43
		];
44
	}
45
46
	public function testGivenExistingEntityId_getEntityReturnsTheEntity() {
47
		$localLookup = new InMemoryEntityLookup();
48
		$localLookup->addEntity( new FakeEntityDocument( new ItemId( 'Q1' ) ) );
49
		$fooLookup = new InMemoryEntityLookup();
50
		$fooLookup->addEntity( new FakeEntityDocument( new PropertyId( 'foo:P11' ) ) );
51
52
		$dispatchingLookup = new DispatchingEntityLookup( [ '' => $localLookup, 'foo' => $fooLookup ] );
53
54
		$expected = new FakeEntityDocument( new ItemId( 'Q1' ) );
55
		$actual = $dispatchingLookup->getEntity( new ItemId( 'Q1' ) );
56
		$this->assertTrue( $actual->equals( $expected ) );
57
		$this->assertTrue( $actual->getId()->equals( new ItemId( 'Q1' ) ) );
58
59
		$expected = new FakeEntityDocument( new PropertyId( 'foo:P11' ) );
60
		$actual = $dispatchingLookup->getEntity( new PropertyId( 'foo:P11' ) );
61
		$this->assertTrue( $actual->equals( $expected ) );
62
		$this->assertTrue( $actual->getId()->equals( new PropertyId( 'foo:P11' ) ) );
63
	}
64
65
	public function testGivenNotExistingEntityIdFromKnownRepository_getEntityReturnsNull() {
66
		$localLookup = new InMemoryEntityLookup();
67
		$fooLookup = new InMemoryEntityLookup();
68
		$dispatchingLookup = new DispatchingEntityLookup( [ '' => $localLookup, 'foo' => $fooLookup ] );
69
		$this->assertNull( $dispatchingLookup->getEntity( new ItemId( 'Q1' ) ) );
70
		$this->assertNull( $dispatchingLookup->getEntity( new ItemId( 'foo:Q19' ) ) );
71
	}
72
73
	public function testGivenEntityIdFromUnknownRepository_getEntityReturnsNull() {
74
		$dispatchingLookup = new DispatchingEntityLookup( [ '' => new InMemoryEntityLookup(), ] );
75
76
		$this->assertNull( $dispatchingLookup->getEntity( new ItemId( 'foo:Q1' ) ) );
77
	}
78
79
	/**
80
	 * @param Exception $exception
81
	 *
82
	 * @return EntityLookup
83
	 */
84
	private function getExceptionThrowingLookup( Exception $exception ) {
85
		$lookup = $this->createMock( EntityLookup::class );
86
		$lookup->expects( $this->any() )
87
			->method( $this->anything() )
88
			->will( $this->throwException( $exception ) );
89
		return $lookup;
90
	}
91
92
	public function testLookupExceptionsAreNotCaughtInGetEntity() {
93
		$lookup = $this->getExceptionThrowingLookup( new EntityLookupException( new ItemId( 'Q321' ) ) );
94
95
		$dispatchingLookup = new DispatchingEntityLookup( [ '' => $lookup ] );
0 ignored issues
show
array('' => $lookup) is of type array<string,object<PHPU...kObject\\MockObject>"}>, but the function expects a array<integer,object<Wik...s\Lookup\EntityLookup>>.

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...
96
97
		$this->expectException( EntityLookupException::class );
98
		$dispatchingLookup->getEntity( new ItemId( 'Q321' ) );
99
	}
100
101
	public function testGivenExistingEntityId_hasEntityReturnsTrue() {
102
		$localLookup = new InMemoryEntityLookup();
103
		$localLookup->addEntity( new FakeEntityDocument( new ItemId( 'Q1' ) ) );
104
		$fooLookup = new InMemoryEntityLookup();
105
		$fooLookup->addEntity( new FakeEntityDocument( new PropertyId( 'foo:P11' ) ) );
106
107
		$dispatchingLookup = new DispatchingEntityLookup( [ '' => $localLookup, 'foo' => $fooLookup ] );
108
109
		$this->assertTrue( $dispatchingLookup->hasEntity( new ItemId( 'Q1' ) ) );
110
		$this->assertTrue( $dispatchingLookup->hasEntity( new PropertyId( 'foo:P11' ) ) );
111
	}
112
113
	public function testGivenNotExistingEntityIdFromKnownRepository_hasEntityReturnsFalse() {
114
		$localLookup = new InMemoryEntityLookup();
115
		$fooLookup = new InMemoryEntityLookup();
116
117
		$dispatchingLookup = new DispatchingEntityLookup( [ '' => $localLookup, 'foo' => $fooLookup ] );
118
119
		$this->assertFalse( $dispatchingLookup->hasEntity( new ItemId( 'Q1' ) ) );
120
		$this->assertFalse( $dispatchingLookup->hasEntity( new ItemId( 'foo:Q19' ) ) );
121
	}
122
123
	public function testGivenEntityIdFromUnknownRepository_hasEntityReturnsFalse() {
124
		$dispatchingLookup = new DispatchingEntityLookup( [ '' => $this->createMock( EntityLookup::class ), ] );
0 ignored issues
show
array('' => $this->creat...p\EntityLookup::class)) is of type array<string,object<PHPU...kObject\\MockObject>"}>, but the function expects a array<integer,object<Wik...s\Lookup\EntityLookup>>.

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...
125
126
		$this->assertFalse( $dispatchingLookup->hasEntity( new ItemId( 'foo:Q1' ) ) );
127
	}
128
129
	public function testLookupExceptionsAreNotCaughtInHasEntity() {
130
		$lookup = $this->getExceptionThrowingLookup( new EntityLookupException( new ItemId( 'Q321' ) ) );
131
132
		$dispatchingLookup = new DispatchingEntityLookup( [ '' => $lookup ] );
0 ignored issues
show
array('' => $lookup) is of type array<string,object<PHPU...kObject\\MockObject>"}>, but the function expects a array<integer,object<Wik...s\Lookup\EntityLookup>>.

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...
133
134
		$this->expectException( EntityLookupException::class );
135
		$dispatchingLookup->hasEntity( new ItemId( 'Q321' ) );
136
	}
137
138
}
139