Issues (52)

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/Diff/ItemPatcherTest.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\DataModel\Services\Tests\Diff;
4
5
use Diff\DiffOp\Diff\Diff;
6
use Diff\DiffOp\DiffOpAdd;
7
use Diff\DiffOp\DiffOpChange;
8
use Diff\DiffOp\DiffOpRemove;
9
use InvalidArgumentException;
10
use PHPUnit\Framework\TestCase;
11
use Wikibase\DataModel\Entity\Item;
12
use Wikibase\DataModel\Entity\Property;
13
use Wikibase\DataModel\Services\Diff\ItemDiff;
14
use Wikibase\DataModel\Services\Diff\ItemPatcher;
15
use Wikibase\DataModel\SiteLink;
16
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
17
use Wikibase\DataModel\Statement\Statement;
18
19
/**
20
 * @covers \Wikibase\DataModel\Services\Diff\ItemPatcher
21
 *
22
 * @license GPL-2.0-or-later
23
 * @author Jeroen De Dauw < [email protected] >
24
 */
25
class ItemPatcherTest extends TestCase {
26
27
	public function testGivenEmptyDiff_itemIsReturnedAsIs() {
28
		$item = new Item();
29
		$item->getFingerprint()->setLabel( 'en', 'foo' );
30
		$item->getSiteLinkList()->addNewSiteLink( 'enwiki', 'bar' );
31
32
		$patchedItem = $this->getPatchedItem( $item, new ItemDiff() );
33
34
		$this->assertInstanceOf( Item::class, $patchedItem );
35
		$this->assertTrue( $item->equals( $patchedItem ) );
36
	}
37
38
	private function getPatchedItem( Item $item, ItemDiff $patch ) {
39
		$patchedItem = $item->copy();
40
41
		$patcher = new ItemPatcher();
42
		$patcher->patchEntity( $patchedItem, $patch );
43
44
		return $patchedItem;
45
	}
46
47
	public function testCanPatchEntityType() {
48
		$patcher = new ItemPatcher();
49
		$this->assertTrue( $patcher->canPatchEntityType( 'item' ) );
50
		$this->assertFalse( $patcher->canPatchEntityType( 'property' ) );
51
		$this->assertFalse( $patcher->canPatchEntityType( '' ) );
52
		$this->assertFalse( $patcher->canPatchEntityType( null ) );
53
	}
54
55
	public function testGivenNonItem_exceptionIsThrown() {
56
		$patcher = new ItemPatcher();
57
58
		$this->setExpectedException( InvalidArgumentException::class );
0 ignored issues
show
Deprecated Code introduced by Thiemo Mättig
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() 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...
59
		$patcher->patchEntity( Property::newFromType( 'kittens' ), new ItemDiff() );
60
	}
61
62
	public function testPatchesLabels() {
63
		$item = new Item();
64
		$item->getFingerprint()->setLabel( 'en', 'foo' );
65
		$item->getFingerprint()->setLabel( 'de', 'bar' );
66
67
		$patch = new ItemDiff( [
68
			'label' => new Diff( [
69
				'en' => new DiffOpChange( 'foo', 'spam' ),
70
				'nl' => new DiffOpAdd( 'baz' ),
71
			] )
72
		] );
73
74
		$patchedItem = $this->getPatchedItem( $item, $patch );
75
76
		$this->assertSame(
77
			[
78
				'en' => 'spam',
79
				'de' => 'bar',
80
				'nl' => 'baz',
81
			],
82
			$patchedItem->getFingerprint()->getLabels()->toTextArray()
83
		);
84
	}
85
86
	public function testDescriptionsArePatched() {
87
		$property = new Item();
88
		$property->setDescription( 'en', 'foo' );
89
		$property->setDescription( 'de', 'bar' );
90
91
		$patch = new ItemDiff( [
92
			'description' => new Diff( [
93
				'en' => new DiffOpChange( 'foo', 'spam' ),
94
				'nl' => new DiffOpAdd( 'baz' ),
95
			] ),
96
		] );
97
98
		$patcher = new ItemPatcher();
99
		$patcher->patchEntity( $property, $patch );
100
101
		$this->assertSame( [
102
			'en' => 'spam',
103
			'de' => 'bar',
104
			'nl' => 'baz',
105
		], $property->getFingerprint()->getDescriptions()->toTextArray() );
106
	}
107
108
	public function testStatementsArePatched() {
109
		$removedStatement = new Statement( new PropertyNoValueSnak( 1 ), null, null, 's1' );
110
		$addedStatement = new Statement( new PropertyNoValueSnak( 2 ), null, null, 's2' );
111
112
		$item = new Item();
113
		$item->getStatements()->addStatement( $removedStatement );
114
115
		$patch = new ItemDiff( [
116
			'claim' => new Diff( [
117
				's1' => new DiffOpRemove( $removedStatement ),
118
				's2' => new DiffOpAdd( $addedStatement ),
119
			] ),
120
		] );
121
122
		$expected = new Item();
123
		$expected->getStatements()->addStatement( $addedStatement );
124
125
		$patcher = new ItemPatcher();
126
		$patcher->patchEntity( $item, $patch );
127
		$this->assertTrue( $expected->equals( $item ) );
128
	}
129
130
	public function testSiteLinksArePatched() {
131
		$removedSiteLink = new SiteLink( 'rewiki', 'Removed' );
132
		$addedSiteLink = new SiteLink( 'adwiki', 'Added' );
133
134
		$item = new Item();
135
		$item->getSiteLinkList()->addSiteLink( $removedSiteLink );
136
137
		$patch = new ItemDiff( [
138
			'links' => new Diff( [
139
				'rewiki' => new Diff( [
140
					'name' => new DiffOpRemove( 'Removed' ),
141
				] ),
142
				'adwiki' => new Diff( [
143
					'name' => new DiffOpAdd( 'Added' ),
144
					'badges' => new Diff(),
145
				] ),
146
			] ),
147
		] );
148
149
		$expected = new Item();
150
		$expected->getSiteLinkList()->addSiteLink( $addedSiteLink );
151
152
		$patcher = new ItemPatcher();
153
		$patcher->patchEntity( $item, $patch );
154
		$this->assertTrue( $expected->equals( $item ) );
155
	}
156
157
}
158