Issues (1401)

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/phpunit/EntitySourceDefinitionsTest.php (1 issue)

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\DataAccess\Tests;
4
5
use InvalidArgumentException;
6
use PHPUnit\Framework\TestCase;
7
use Wikibase\DataAccess\EntitySource;
8
use Wikibase\DataAccess\EntitySourceDefinitions;
9
use Wikibase\Lib\EntityTypeDefinitions;
10
11
/**
12
 * @covers \Wikibase\DataAccess\EntitySourceDefinitions
13
 *
14
 * @group Wikibase
15
 *
16
 * @license GPL-2.0-or-later
17
 */
18
class EntitySourceDefinitionsTest extends TestCase {
19
20
	public function testGivenInvalidArguments_constructorThrowsException() {
21
		$this->expectException( InvalidArgumentException::class );
22
		new EntitySourceDefinitions( [ 'foobar' ], new EntityTypeDefinitions( [] ) );
0 ignored issues
show
array('foobar') is of type array<integer,string,{"0":"string"}>, but the function expects a array<integer,object<Wik...taAccess\EntitySource>>.

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...
23
	}
24
25
	public function testGivenEntityTypeProvidedByMultipleSources_constructorThrowsException() {
26
		$itemSourceOne = $this->newItemSource();
27
		$itemSourceTwo = new EntitySource( 'dupe test', 'foodb', [ 'item' => [ 'namespaceId' => 100, 'slot' => 'main' ] ], '', '', '', '' );
28
29
		$this->expectException( InvalidArgumentException::class );
30
		new EntitySourceDefinitions( [ $itemSourceOne, $itemSourceTwo ], new EntityTypeDefinitions( [] ) );
31
	}
32
33
	public function testTwoSourcesWithSameName_constructorThrowsException() {
34
		$sourceOne = new EntitySource( 'same name', 'aaa', [ 'entityOne' => [ 'namespaceId' => 100, 'slot' => 'main' ] ], '', '', '', '' );
35
		$sourceTwo = new EntitySource( 'same name', 'bbb', [ 'entityTwo' => [ 'namespaceId' => 101, 'slot' => 'main2' ] ], '', '', '', '' );
36
37
		$this->expectException( InvalidArgumentException::class );
38
		new EntitySourceDefinitions( [ $sourceOne, $sourceTwo ], new EntityTypeDefinitions( [] ) );
39
	}
40
41
	public function testGivenKnownType_getSourceForEntityTypeReturnsTheConfiguredSource() {
42
		$itemSource = $this->newItemSource();
43
		$propertySource = $this->newPropertySource();
44
45
		$sourceDefinitions = new EntitySourceDefinitions( [ $itemSource, $propertySource ], new EntityTypeDefinitions( [] ) );
46
47
		$this->assertEquals( $itemSource, $sourceDefinitions->getSourceForEntityType( 'item' ) );
48
	}
49
50
	public function testGivenSubEntityOfKnownType_getSourceForEntityTypeReturnsTheRelevantSource() {
51
		$itemSource = $this->newItemSource();
52
		$propertySource = $this->newPropertySource();
53
54
		$sourceDefinitions = new EntitySourceDefinitions(
55
			[ $itemSource, $propertySource ],
56
			new EntityTypeDefinitions( [ 'item' => [ EntityTypeDefinitions::SUB_ENTITY_TYPES => [ 'subitem' ] ] ] )
57
		);
58
59
		$this->assertEquals( $itemSource, $sourceDefinitions->getSourceForEntityType( 'subitem' ) );
60
	}
61
62
	public function testGivenUnknownType_getSourceForEntityTypeReturnsNull() {
63
		$itemSource = $this->newItemSource();
64
65
		$sourceDefinitions = new EntitySourceDefinitions( [ $itemSource ], new EntityTypeDefinitions( [] ) );
66
67
		$this->assertNull( $sourceDefinitions->getSourceForEntityType( 'property' ) );
68
	}
69
70
	public function testGetEntityTypeToSourceMapping() {
71
		$itemSource = $this->newItemSource();
72
		$propertySource = $this->newPropertySource();
73
		$otherSource = $this->newOtherSource();
74
75
		$sources = [ $itemSource, $propertySource, $otherSource ];
76
		$entityTypeDefinitions = [
77
			'other' => [
78
				EntityTypeDefinitions::SUB_ENTITY_TYPES => [ 'otherSub' ],
79
			],
80
			'otherSub' => [],
81
		];
82
83
		$sourceDefinitions = new EntitySourceDefinitions( $sources, new EntityTypeDefinitions( $entityTypeDefinitions ) );
84
85
		$this->assertEquals(
86
			[ 'item' => $itemSource, 'property' => $propertySource, 'other' => $otherSource, 'otherSub' => $otherSource ],
87
			$sourceDefinitions->getEntityTypeToSourceMapping()
88
		);
89
	}
90
91
	public function testGetConceptBaseUris() {
92
		$itemSource = $this->newItemSource();
93
		$propertySource = $this->newPropertySource();
94
95
		$sourceDefinitions = new EntitySourceDefinitions( [ $itemSource, $propertySource ], new EntityTypeDefinitions( [] ) );
96
97
		$this->assertEquals( [ 'items' => 'itemsource:', 'properties' => 'propertysource:' ], $sourceDefinitions->getConceptBaseUris() );
98
	}
99
100
	public function testGetRdfNodeNamespacePrefixes() {
101
		$itemSource = $this->newItemSource();
102
		$propertySource = $this->newPropertySource();
103
104
		$sourceDefinitions = new EntitySourceDefinitions( [ $itemSource, $propertySource ], new EntityTypeDefinitions( [] ) );
105
106
		$this->assertEquals( [ 'items' => 'it', 'properties' => 'pro' ], $sourceDefinitions->getRdfNodeNamespacePrefixes() );
107
	}
108
109
	public function testGetRdfPredicateNamespacePrefixes() {
110
		$itemSource = $this->newItemSource();
111
		$propertySource = $this->newPropertySource();
112
113
		$sourceDefinitions = new EntitySourceDefinitions( [ $itemSource, $propertySource ], new EntityTypeDefinitions( [] ) );
114
115
		$this->assertEquals( [ 'items' => '', 'properties' => 'pro' ], $sourceDefinitions->getRdfPredicateNamespacePrefixes() );
116
	}
117
118
	private function newItemSource() {
119
		return new EntitySource(
120
			'items',
121
			false,
122
			[ 'item' => [ 'namespaceId' => 100, 'slot' => 'main' ] ],
123
			'itemsource:',
124
			'it',
125
			'',
126
			''
127
		);
128
	}
129
130
	private function newPropertySource() {
131
		return new EntitySource(
132
			'properties',
133
			false,
134
			[ 'property' => [ 'namespaceId' => 200, 'slot' => 'main' ] ],
135
			'propertysource:',
136
			'pro',
137
			'pro',
138
			''
139
		);
140
	}
141
142
	private function newOtherSource() {
143
		return new EntitySource(
144
			'others',
145
			false,
146
			[ 'other' => [ 'namespaceId' => 666, 'slot' => 'other' ] ],
147
			'othersource:',
148
			'ot',
149
			'',
150
			''
151
		);
152
	}
153
154
}
155