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.

unit/Lookup/RedirectResolvingEntityLookupTest.php (6 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 Wikibase\DataModel\Services\Tests\Lookup;
4
5
use PHPUnit\Framework\TestCase;
6
use Wikibase\DataModel\Entity\EntityId;
7
use Wikibase\DataModel\Entity\Item;
8
use Wikibase\DataModel\Entity\ItemId;
9
use Wikibase\DataModel\Services\Lookup\EntityLookup;
10
use Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup;
11
use Wikibase\DataModel\Services\Lookup\UnresolvedEntityRedirectException;
12
13
/**
14
 * @covers \Wikibase\DataModel\Services\Lookup\RedirectResolvingEntityLookup
15
 *
16
 * @license GPL-2.0-or-later
17
 * @author Daniel Kinzler
18
 */
19
class RedirectResolvingEntityLookupTest extends TestCase {
20
21
	/**
22
	 * @param EntityId $id
23
	 *
24
	 * @return null|Item
25
	 * @throws UnresolvedEntityRedirectException
26
	 */
27
	public function getEntity( EntityId $id ) {
28
		switch ( $id->getSerialization() ) {
29
			case 'Q10':
30
				return new Item( $id );
0 ignored issues
show
$id is of type object<Wikibase\DataModel\Entity\EntityId>, but the function expects a null|object<Wikibase\DataModel\Entity\ItemId>.

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...
31
			case 'Q11':
32
				throw new UnresolvedEntityRedirectException( new ItemId( 'Q11' ), new ItemId( 'Q10' ) );
33
			case 'Q12':
34
				throw new UnresolvedEntityRedirectException( new ItemId( 'Q12' ), new ItemId( 'Q11' ) );
35
			case 'Q21':
36
				throw new UnresolvedEntityRedirectException( new ItemId( 'Q21' ), new ItemId( 'Q20' ) );
37
			default:
38
				return null;
39
		}
40
	}
41
42
	/**
43
	 * @return EntityLookup
44
	 */
45
	public function getLookupDouble() {
46
		$mock = $this->createMock( EntityLookup::class );
47
48
		$mock->expects( $this->any() )
49
			->method( 'getEntity' )
50
			->will( $this->returnCallback( [ $this, 'getEntity' ] ) );
51
52
		$mock->expects( $this->any() )
53
			->method( 'hasEntity' )
54
			->will( $this->returnCallback( function ( EntityId $id ) {
55
				return $this->getEntity( $id ) !== null;
56
			} ) );
57
58
		return $mock;
59
	}
60
61
	public function getEntityProvider() {
62
		return [
63
			'no redirect' => [ new ItemId( 'Q10' ), new ItemId( 'Q10' ) ],
64
			'one redirect' => [ new ItemId( 'Q11' ), new ItemId( 'Q10' ) ],
65
		];
66
	}
67
68
	/**
69
	 * @dataProvider getEntityProvider
70
	 */
71
	public function testGetEntity( EntityId $id, EntityId $expected ) {
72
		$lookup = new RedirectResolvingEntityLookup( $this->getLookupDouble() );
0 ignored issues
show
$this->getLookupDouble() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Wikibase\DataMode...es\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...
73
74
		$entity = $lookup->getEntity( $id );
75
76
		if ( $expected === null ) {
77
			$this->assertNull( $entity );
78
		} else {
79
			$this->assertTrue( $expected->equals( $entity->getId() ) );
80
		}
81
	}
82
83
	public function testGetEntity_missing() {
84
		$lookup = new RedirectResolvingEntityLookup( $this->getLookupDouble() );
0 ignored issues
show
$this->getLookupDouble() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Wikibase\DataMode...es\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...
85
86
		$id = new ItemId( 'Q7' ); // entity Q7 is not known
87
		$this->assertNull( $lookup->getEntity( $id ) );
88
	}
89
90
	public function testGetEntity_brokenRedirect() {
91
		$lookup = new RedirectResolvingEntityLookup( $this->getLookupDouble() );
0 ignored issues
show
$this->getLookupDouble() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Wikibase\DataMode...es\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...
92
93
		$id = new ItemId( 'Q20' ); // Q20 is a broken redirect
94
		$this->assertNull( $lookup->getEntity( $id ) );
95
	}
96
97
	public function testGetEntity_doubleRedirect() {
98
		$lookup = new RedirectResolvingEntityLookup( $this->getLookupDouble() );
0 ignored issues
show
$this->getLookupDouble() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Wikibase\DataMode...es\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...
99
100
		$id = new ItemId( 'Q12' ); // Q12 is a double redirect
101
102
		$this->expectException( UnresolvedEntityRedirectException::class );
103
		$lookup->getEntity( $id );
104
	}
105
106
	public function hasEntityProvider() {
107
		return [
108
			'unknown entity' => [ new ItemId( 'Q7' ), false ],
109
			'no redirect' => [ new ItemId( 'Q10' ), true ],
110
			'one redirect' => [ new ItemId( 'Q11' ), true ],
111
			'broken redirect' => [ new ItemId( 'Q21' ), false ],
112
		];
113
	}
114
115
	/**
116
	 * @dataProvider hasEntityProvider
117
	 */
118
	public function testHasEntity( EntityId $id, $exists ) {
119
		$lookup = new RedirectResolvingEntityLookup( $this->getLookupDouble() );
0 ignored issues
show
$this->getLookupDouble() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Wikibase\DataMode...es\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...
120
121
		$this->assertEquals( $exists, $lookup->hasEntity( $id ) );
122
	}
123
124
}
125