Issues (2)

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/BatchingEntityFetcherTest.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\EntityStore\Tests;
4
5
use BatchingIterator\Fetchers\InMemoryBatchingFetcher;
6
use Wikibase\DataModel\Entity\EntityId;
7
use Wikibase\DataModel\Entity\Item;
8
use Wikibase\DataModel\Entity\ItemId;
9
use Wikibase\EntityStore\BatchingEntityFetcher;
10
use Wikibase\EntityStore\Tests\Fixtures\InMemoryEntityLookup;
11
12
/**
13
 * @covers Wikibase\EntityStore\BatchingEntityFetcher
14
 *
15
 * @licence GNU GPL v2+
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class BatchingEntityFetcherTest extends \PHPUnit_Framework_TestCase {
19
20
	/**
21
	 * @var BatchingEntityFetcher
22
	 */
23
	private $fetcher;
24
25
	public function setUp() {
26
		$idFetcher = $this->newIdFetcher();
27
28
		$entityLookup = $this->newEntityLookup();
29
30
		$this->fetcher = new BatchingEntityFetcher(
31
			$idFetcher,
32
			$entityLookup
33
		);
34
	}
35
36
	private function newIdFetcher() {
37
		return new InMemoryBatchingFetcher( array(
38
			new ItemId( 'Q1' ),
39
			new ItemId( 'Q2' ),
40
			new ItemId( 'Q3' ),
41
			new ItemId( 'Q4' ),
42
			new ItemId( 'Q5' ),
43
			new ItemId( 'Q6' ),
44
			new ItemId( 'Q7' ),
45
			new ItemId( 'Q8' ),
46
		) );
47
	}
48
49
	private function newEntityLookup() {
50
		return new InMemoryEntityLookup(
51
			array(
52
				$this->newItemWithId( 'Q1' ),
53
				$this->newItemWithId( 'Q2' ),
54
				// Q3 is missing
55
				$this->newItemWithId( 'Q4' ),
56
				$this->newItemWithId( 'Q5' ),
57
				// Q6 results in an error
58
				$this->newItemWithId( 'Q7' ),
59
				// Q8 is missing
60
			),
61
			array(
62
				new ItemId( 'Q6' ),
63
			)
64
		);
65
	}
66
67
	private function newItemWithId( $id ) {
68
		$item = Item::newEmpty();
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Item::newEmpty() has been deprecated with message: since 2.5, use new Item() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
69
		$item->setId( new ItemId( $id ) );
70
		return $item;
71
	}
72
73
	public function testFetchingOfTwoExistingEntities() {
74
		$this->assertAreItemsWithIds(
75
			array(
76
				new ItemId( 'Q1' ),
77
				new ItemId( 'Q2' ),
78
			),
79
			$this->fetcher->fetchNext( 2 )
80
		);
81
	}
82
83
	public function testNonExistingEntitiesGetSkipped() {
84
		$this->assertAreItemsWithIds(
85
			array(
86
				new ItemId( 'Q1' ),
87
				new ItemId( 'Q2' ),
88
				new ItemId( 'Q4' ),
89
				new ItemId( 'Q5' ),
90
			),
91
			$this->fetcher->fetchNext( 5 )
92
		);
93
	}
94
95
	public function testContinuationWorksEvenWhenEntityDoesNotExist() {
96
		$this->fetcher->fetchNext( 3 );
97
98
		$this->assertAreItemsWithIds(
99
			array(
100
				new ItemId( 'Q4' ),
101
				new ItemId( 'Q5' ),
102
			),
103
			$this->fetcher->fetchNext( 2 )
104
		);
105
	}
106
107
	public function testFetchErrorCausesEntityToBeSkipped() {
108
		$this->fetcher->fetchNext( 4 );
109
110
		$this->assertAreItemsWithIds(
111
			array(
112
				new ItemId( 'Q5' ),
113
				new ItemId( 'Q7' ),
114
			),
115
			$this->fetcher->fetchNext( 3 )
116
		);
117
	}
118
119
	public function testMissingEntitiesAndFetchErrorsCauseOnSkippedFunctionToBeCalled() {
120
		$onEntitySkippedCalls = array();
121
122
		$fetcher = new BatchingEntityFetcher(
123
			$this->newIdFetcher(),
124
			$this->newEntityLookup(),
125
			function( EntityId $id, $reasonMessage ) use ( &$onEntitySkippedCalls ) {
126
				$onEntitySkippedCalls[] = array( $id, $reasonMessage );
127
			}
128
		);
129
130
		$fetcher->fetchNext( 10 );
131
132
		$this->assertEquals(
133
			array(
134
				array( new ItemId( 'Q3' ), 'No such entity in the store' ),
135
				array( new ItemId( 'Q6' ), 'The id is in idsForWhichToThrowException' ),
136
				array( new ItemId( 'Q8' ), 'No such entity in the store' ),
137
			),
138
			$onEntitySkippedCalls
139
		);
140
	}
141
142
	public function testWhenAllEntitiesInBatchAreSkipped_aNewFetchCallIsMade() {
143
		$this->fetcher->fetchNext( 2 );
144
145
		$this->assertAreItemsWithIds(
146
			array(
147
				new ItemId( 'Q4' ),
148
			),
149
			$this->fetcher->fetchNext( 1 )
150
		);
151
	}
152
153
	public function testEmptyArrayIsReturnedOnCallsAfterLastData() {
154
		$this->fetcher->fetchNext( 10 );
155
		$this->assertSame( array(), $this->fetcher->fetchNext( 10 ) );
156
		$this->assertSame( array(), $this->fetcher->fetchNext( 10 ) );
157
	}
158
159
	/**
160
	 * @param ItemId[] $expectedIds
161
	 * @param Item[] $items
162
	 */
163
	private function assertAreItemsWithIds( array $expectedIds, array $items ) {
164
		$this->assertContainsOnlyInstancesOf( 'Wikibase\DataModel\Entity\Item', $items );
165
166
		$actualIds = array();
167
168
		foreach ( $items as $item ) {
169
			$actualIds[] = $item->getId();
170
		}
171
172
		$this->assertEquals( $expectedIds, $actualIds );
173
	}
174
175
}
176