Issues (36)

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/ByHttpRequest/CannedResultArrayTest.php (3 issues)

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 SEQL\ByHttpRequest\Tests;
4
5
use SEQL\ByHttpRequest\CannedResultArray;
6
use SMW\DIWikiPage;
7
use SMW\DIProperty;
8
use SMWDINumber as DINumber;
9
10
/**
11
 * @covers \SEQL\ByHttpRequest\CannedResultArray
12
 * @group semantic-external-query-lookup
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 *
17
 * @author mwjames
18
 */
19
class CannedResultArrayTest extends \PHPUnit_Framework_TestCase {
20
21
	private $jsonResponseParser;
22
23
	protected function setUp() {
24
25
		$this->jsonResponseParser = $this->getMockBuilder( '\SEQL\ByHttpRequest\JsonResponseParser' )
26
			->disableOriginalConstructor()
27
			->getMock();
28
	}
29
30
	public function testCanConstruct() {
31
32
		$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' )
33
			->disableOriginalConstructor()
34
			->getMock();
35
36
		$this->assertInstanceOf(
37
			'\SEQL\ByHttpRequest\CannedResultArray',
38
			new CannedResultArray( new DIWikiPage( 'Foo', NS_MAIN ), $printRequest, $this->jsonResponseParser )
39
		);
40
	}
41
42
	public function testGetResultSubject() {
43
44
		$subject = new DIWikiPage( 'Foo', NS_MAIN );
45
46
		$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' )
47
			->disableOriginalConstructor()
48
			->getMock();
49
50
		$instance = new CannedResultArray(
51
			$subject,
52
			$printRequest,
53
			$this->jsonResponseParser
54
		);
55
56
		$this->assertEquals(
57
			$subject,
58
			$instance->getResultSubject()
59
		);
60
	}
61
62
	public function testGetContentForMode_PRINT_THIS() {
63
64
		$subject = new DIWikiPage( 'Foo', NS_MAIN );
65
66
		$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' )
67
			->disableOriginalConstructor()
68
			->getMock();
69
70
		$printRequest->expects( $this->any() )
71
			->method( 'getMode' )
72
			->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_THIS ) );
73
74
		$instance = new CannedResultArray(
75
			$subject,
76
			$printRequest,
77
			$this->jsonResponseParser
78
		);
79
80
		$this->assertDataItem(
81
			$subject,
82
			$instance
83
		);
84
	}
85
86
	public function testGetContentForMode_PRINT_CCAT() {
87
88
		$subject = new DIWikiPage( 'Foo', NS_MAIN );
89
		$category = new DIWikiPage( 'Bar', NS_CATEGORY, 'mw-foo' );
90
91
		$this->jsonResponseParser->expects( $this->any() )
92
			->method( 'getPropertyValuesFor' )
93
			->with(
94
				$this->equalTo( $subject ),
95
				$this->equalTo( new DIProperty( '_INST' ) ) )
96
			->will( $this->returnValue( array( $category ) ) );
97
98
		$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' )
99
			->disableOriginalConstructor()
100
			->getMock();
101
102
		$printRequest->expects( $this->any() )
103
			->method( 'getMode' )
104
			->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_CCAT ) );
105
106
		$instance = new CannedResultArray(
107
			$subject,
108
			$printRequest,
109
			$this->jsonResponseParser
110
		);
111
112
		$this->assertDataItem(
113
			$category,
114
			$instance
115
		);
116
	}
117
118
	public function testGetContentOnDifferentPropertyLabelForMode_PRINT_PROP() {
119
120
		$subject = new DIWikiPage( 'Foo', NS_MAIN );
121
		$dataItem = new DINumber( 1001 );
122
123
		$propertyValue = $this->getMockBuilder( '\SMWPropertyValue' )
124
			->disableOriginalConstructor()
125
			->getMock();
126
127
		$propertyValue->expects( $this->any() )
128
			->method( 'isValid' )
129
			->will( $this->returnValue( true ) );
130
131
		$propertyValue->expects( $this->any() )
132
			->method( 'getDataItem' )
133
			->will( $this->returnValue( new DIProperty( 'ABC' ) ) );
134
135
		$dataValue = $this->getMockBuilder( '\SMWDataValue' )
136
			->disableOriginalConstructor()
137
			->setMethods( array( 'getDataItem' ) )
138
			->getMockForAbstractClass();
139
140
		$dataValue->expects( $this->any() )
141
			->method( 'getDataItem' )
142
			->will( $this->returnValue( $dataItem ) );
143
144
		$this->jsonResponseParser->expects( $this->any() )
145
			->method( 'getPropertyValuesFor' )
146
			->with(
147
				$this->equalTo( $subject ),
148
				$this->equalTo( new DIProperty( 'isPropertyFromInMemoryExternalRepositoryCache' ) ) )
149
			->will( $this->returnValue( array( $dataValue ) ) );
150
151
		$this->jsonResponseParser->expects( $this->any() )
152
			->method( 'findPropertyFromInMemoryExternalRepositoryCache' )
153
			->with(
154
				$this->equalTo( new DIProperty( 'withDifferentPropertyLabel' ) ) )
155
			->will( $this->returnValue( new DIProperty( 'isPropertyFromInMemoryExternalRepositoryCache' ) ) );
156
157
		$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' )
158
			->disableOriginalConstructor()
159
			->getMock();
160
161
		$printRequest->expects( $this->any() )
162
			->method( 'getMode' )
163
			->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_PROP ) );
164
165
		$printRequest->expects( $this->any() )
166
			->method( 'getData' )
167
			->will( $this->returnValue( $propertyValue ) );
168
169
		$printRequest->expects( $this->atLeastOnce() )
170
			->method( 'getLabel' )
171
			->will( $this->returnValue( 'withDifferentPropertyLabel' ) );
172
173
		$instance = new CannedResultArray(
174
			$subject,
175
			$printRequest,
176
			$this->jsonResponseParser
177
		);
178
179
		$this->assertDataItem(
180
			$dataItem,
181
			$instance
182
		);
183
	}
184
185
	public function testGetContentOnQuantityTypeWithSameLabelForMode_PRINT_PROP() {
186
187
		$subject = new DIWikiPage( 'Foo', NS_MAIN );
188
189
		$property = new DIProperty( 'QuantityType' );
190
		$property->setPropertyTypeId( '_qty' );
0 ignored issues
show
Deprecated Code introduced by
The method SMW\DIProperty::setPropertyTypeId() has been deprecated with message: since 3.0, use DIProperty::setPropertyValueType

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...
191
192
		$dataItem = new DINumber( 1001 );
193
194
		$propertyValue = $this->getMockBuilder( '\SMWPropertyValue' )
195
			->disableOriginalConstructor()
196
			->getMock();
197
198
		$propertyValue->expects( $this->any() )
199
			->method( 'isValid' )
200
			->will( $this->returnValue( true ) );
201
202
		$propertyValue->expects( $this->any() )
203
			->method( 'getDataItem' )
204
			->will( $this->returnValue( new DIProperty( 'ABC' ) ) );
205
206
		$dataValue = $this->getMockBuilder( '\SMWDataValue' )
207
			->disableOriginalConstructor()
208
			->setMethods( array( 'getDataItem' ) )
209
			->getMockForAbstractClass();
210
211
		$dataValue->expects( $this->any() )
212
			->method( 'getDataItem' )
213
			->will( $this->returnValue( $dataItem ) );
214
215
		$this->jsonResponseParser->expects( $this->any() )
216
			->method( 'getPropertyValuesFor' )
217
			->with(
218
				$this->equalTo( $subject ),
219
				$this->equalTo( $property ) )
220
			->will( $this->returnValue( array( $dataValue ) ) );
221
222
		$this->jsonResponseParser->expects( $this->any() )
223
			->method( 'findPropertyFromInMemoryExternalRepositoryCache' )
224
			->with(
225
				$this->equalTo( new DIProperty( 'ABC' ) ) )
226
			->will( $this->returnValue( $property ) );
227
228
		$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' )
229
			->disableOriginalConstructor()
230
			->getMock();
231
232
		$printRequest->expects( $this->any() )
233
			->method( 'getMode' )
234
			->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_PROP ) );
235
236
		$printRequest->expects( $this->any() )
237
			->method( 'getData' )
238
			->will( $this->returnValue( $propertyValue ) );
239
240
		$printRequest->expects( $this->atLeastOnce() )
241
			->method( 'getLabel' )
242
			->will( $this->returnValue( '' ) );
243
244
		$instance = new CannedResultArray(
245
			$subject,
246
			$printRequest,
247
			$this->jsonResponseParser
248
		);
249
250
		$this->assertDataItem(
251
			$dataItem,
252
			$instance
253
		);
254
	}
255
256
	public function testOptions() {
257
258
		$subject = new DIWikiPage( 'Foo', NS_MAIN );
259
260
		$printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' )
261
			->disableOriginalConstructor()
262
			->getMock();
263
264
		$printRequest->expects( $this->any() )
265
			->method( 'getMode' )
266
			->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_THIS ) );
267
268
		$instance = new CannedResultArray(
269
			$subject,
270
			$printRequest,
271
			$this->jsonResponseParser
272
		);
273
274
		$dataValue = $instance->getNextDataValue();
275
276
		$this->assertInternalType(
277
			'string',
278
			$dataValue->getOptionValueFor( 'user.language' )
0 ignored issues
show
The method getOptionValueFor() does not exist on SMWDataValue. Did you maybe mean getOption()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
279
		);
280
281
		$this->assertInternalType(
282
			'string',
283
			$dataValue->getOptionValueFor( 'content.language' )
0 ignored issues
show
The method getOptionValueFor() does not exist on SMWDataValue. Did you maybe mean getOption()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
284
		);
285
	}
286
287
	private function assertDataItem( $dataItem, $instance ) {
288
289
		$this->assertEquals(
290
			$dataItem,
291
			$instance->getNextDataItem()
292
		);
293
294
		$instance->reset();
295
296
		$this->assertInstanceOf(
297
			'\SMWDataValue',
298
			$instance->getNextDataValue()
299
		);
300
301
		$this->assertEquals(
302
			array( $dataItem ),
303
			$instance->getContent()
304
		);
305
	}
306
307
}
308