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.

lib/tests/phpunit/TermIndexEntryTest.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 Wikibase\Lib\Tests;
4
5
use Wikibase\DataModel\Entity\Item;
6
use Wikibase\DataModel\Entity\ItemId;
7
use Wikibase\DataModel\Entity\PropertyId;
8
use Wikibase\DataModel\Term\Term;
9
use Wikibase\Lib\TermIndexEntry;
10
use Wikimedia\Assert\ParameterAssertionException;
11
12
/**
13
 * @covers \Wikibase\Lib\TermIndexEntry
14
 *
15
 * @group Wikibase
16
 *
17
 * @license GPL-2.0-or-later
18
 * @author Daniel Kinzler <[email protected]>
19
 */
20
class TermIndexEntryTest extends \PHPUnit\Framework\TestCase {
21
22
	public function testConstructor() {
23
		$term = new TermIndexEntry( [
24
			'entityId' => new ItemId( 'Q23' ),
25
			'termType' => TermIndexEntry::TYPE_LABEL,
26
			'termLanguage' => 'en',
27
			'termText' => 'foo',
28
		] );
29
30
		$this->assertEquals( new ItemId( 'Q23' ), $term->getEntityId() );
31
		$this->assertSame( Item::ENTITY_TYPE, $term->getEntityType() );
32
		$this->assertSame( TermIndexEntry::TYPE_LABEL, $term->getTermType() );
33
		$this->assertSame( 'en', $term->getLanguage() );
34
		$this->assertSame( 'foo', $term->getText() );
35
	}
36
37
	public function testGivenInvalidField_constructorThrowsException() {
38
		$this->expectException( ParameterAssertionException::class );
39
		new TermIndexEntry( [
40
			'entityId' => new ItemId( 'Q23' ),
41
			'termType' => TermIndexEntry::TYPE_LABEL,
42
			'termLanguage' => 'en',
43
			'termText' => 'foo',
44
			'fooField' => 'bar',
45
		] );
46
	}
47
48
	public function provideIncompleteFields() {
49
		return [
50
			[
51
				[
52
					'termType' => TermIndexEntry::TYPE_LABEL,
53
					'termLanguage' => 'en',
54
					'termText' => 'foo',
55
				]
56
			],
57
			[
58
				[
59
					'entityId' => new ItemId( 'Q23' ),
60
					'termType' => TermIndexEntry::TYPE_LABEL,
61
				]
62
			],
63
			[
64
				[
65
					'entityId' => new ItemId( 'Q23' ),
66
				]
67
			],
68
			[
69
				[]
70
			],
71
		];
72
	}
73
74
	/**
75
	 * @dataProvider provideIncompleteFields
76
	 */
77
	public function testGivenIncompleteFields_constructorThrowsException( $fields ) {
78
		$this->expectException( ParameterAssertionException::class );
79
		new TermIndexEntry( $fields );
80
	}
81
82
	public function provideInvalidValues() {
83
		$goodFields = [
84
			'entityId' => new ItemId( 'Q23' ),
85
			'termType' => TermIndexEntry::TYPE_LABEL,
86
			'termLanguage' => 'en',
87
			'termText' => 'foo',
88
		];
89
90
		return [
91
			'non-string term type' => [ array_merge( $goodFields, [ 'termType' => 100 ] ) ],
92
			'invalid term type' => [ array_merge( $goodFields, [ 'termType' => 'foo' ] ) ],
93
			'non-string term language' => [ array_merge( $goodFields, [ 'termLanguage' => 100 ] ) ],
94
			'non-string term text' => [ array_merge( $goodFields, [ 'termText' => 100 ] ) ],
95
			'non-EntityId as entity id' => [ array_merge( $goodFields, [ 'entityId' => 'foo' ] ) ],
96
		];
97
	}
98
99
	/**
100
	 * @dataProvider provideInvalidValues
101
	 */
102
	public function testGivenInvalidValues_constructorThrowsException( $fields ) {
103
		$this->expectException( ParameterAssertionException::class );
104
		new TermIndexEntry( $fields );
105
	}
106
107
	public function testClone() {
108
		$term = new TermIndexEntry( [
109
			'entityId' => new ItemId( 'Q23' ),
110
			'termType' => TermIndexEntry::TYPE_LABEL,
111
			'termLanguage' => 'en',
112
			'termText' => 'foo',
113
		] );
114
115
		$clone = clone $term;
116
		$this->assertEquals( $term, $clone, 'clone must be equal to original' );
117
	}
118
119
	/**
120
	 * @param array $extraFields
121
	 *
122
	 * @return TermIndexEntry
123
	 */
124
	private function newInstance( array $extraFields = [] ) {
125
		return new TermIndexEntry( $extraFields + [
126
				'entityId' => new ItemId( 'Q23' ),
127
				'termType' => TermIndexEntry::TYPE_LABEL,
128
				'termLanguage' => 'en',
129
				'termText' => 'foo',
130
			] );
131
	}
132
133
	public function provideCompare() {
134
		$term = $this->newInstance();
135
136
		return [
137
			'the same object' => [
138
				$term,
139
				$term,
140
				true,
141
			],
142
			'clone' => [
143
				$term,
144
				clone $term,
145
				true
146
			],
147
			'other text' => [
148
				$term,
149
				$this->newInstance( [ 'termText' => 'bar' ] ),
150
				false
151
			],
152
			'other entity id' => [
153
				$term,
154
				$this->newInstance( [ 'entityId' => new PropertyId( 'P11' ) ] ),
155
				false
156
			],
157
			'other language' => [
158
				$term,
159
				$this->newInstance( [ 'termLanguage' => 'fr' ] ),
160
				false
161
			],
162
			'other term type' => [
163
				$term,
164
				$this->newInstance( [ 'termType' => TermIndexEntry::TYPE_DESCRIPTION ] ),
165
				false
166
			],
167
		];
168
	}
169
170
	/**
171
	 * @dataProvider provideCompare
172
	 * @depends testClone
173
	 */
174
	public function testCompare( TermIndexEntry $a, TermIndexEntry $b, $equal ) {
175
		$ab = TermIndexEntry::compare( $a, $b );
0 ignored issues
show
$a is of type object<Wikibase\Lib\TermIndexEntry>, but the function expects a object<self>.

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...
$b is of type object<Wikibase\Lib\TermIndexEntry>, but the function expects a object<self>.

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...
176
		$ba = TermIndexEntry::compare( $b, $a );
0 ignored issues
show
$b is of type object<Wikibase\Lib\TermIndexEntry>, but the function expects a object<self>.

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...
$a is of type object<Wikibase\Lib\TermIndexEntry>, but the function expects a object<self>.

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...
177
178
		if ( $equal ) {
179
			$this->assertSame( 0, $ab, 'Comparison of equal terms is expected to return 0' );
180
			$this->assertSame( 0, $ba, 'Comparison of equal terms is expected to return 0' );
181
		} else {
182
			// NOTE: We don't know or care whether this is larger or smaller
183
			$this->assertNotSame( 0, $ab, 'Comparison of unequal terms is expected to not return 0' );
184
			$this->assertSame( -$ab, $ba, 'Comparing A to B should return the inverse of comparing B to A' );
185
		}
186
	}
187
188
	public function testGetTerm() {
189
		$termIndexEntry = new TermIndexEntry( [
190
			'entityId' => new ItemId( 'Q23' ),
191
			'termType' => TermIndexEntry::TYPE_LABEL,
192
			'termLanguage' => 'en',
193
			'termText' => 'foo',
194
		] );
195
		$this->assertEquals( new Term( 'en', 'foo' ), $termIndexEntry->getTerm() );
196
	}
197
198
}
199