Issues (43)

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/WikidataRequestHandlerTest.php (2 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 PPP\Wikidata;
4
5
use PPP\DataModel\FirstNode;
6
use PPP\DataModel\IntersectionNode;
7
use PPP\DataModel\JsonLdResourceNode;
8
use PPP\DataModel\MissingNode;
9
use PPP\DataModel\ResourceListNode;
10
use PPP\DataModel\SentenceNode;
11
use PPP\DataModel\SortNode;
12
use PPP\DataModel\StringResourceNode;
13
use PPP\DataModel\TimeResourceNode;
14
use PPP\DataModel\TripleNode;
15
use PPP\DataModel\UnionNode;
16
use PPP\Module\DataModel\ModuleRequest;
17
use PPP\Module\DataModel\ModuleResponse;
18
19
/**
20
 * @covers PPP\Wikidata\WikidataRequestHandler
21
 *
22
 * @licence AGPLv3+
23
 * @author Thomas Pellissier Tanon
24
 */
25
class WikidataRequestHandlerTest extends \PHPUnit_Framework_TestCase {
26
27
	public static function getRequestHandler() {
28
		static $requestHandler = null;
29
30
		if($requestHandler === null) {
31
			$requestHandler = new WikidataRequestHandler(
32
				__DIR__ . '/../../default-config.json',
33
				array(
34
					'enwiki' => 'http://en.wikipedia.org/w/api.php',
35
					'dewiki' => 'http://de.wikipedia.org/w/api.php',
36
					'frwiki' => 'http://fr.wikipedia.org/w/api.php'
37
				)
38
			);
39
		}
40
41
		return $requestHandler;
42
	}
43
44
	/**
45
	 * @dataProvider requestAndResponseProvider
46
	 */
47
	public function testBuildResponse(ModuleRequest $request, array $response) {
48
		$computedResponse = $this->getRequestHandler()->buildResponse($request);
49
		if($this->cleverEquals($computedResponse, $response)) {
50
			$this->assertTrue(true);
51
		} else {
52
			$this->assertEquals($response, $computedResponse);
53
		}
54
	}
55
56
	private function cleverEquals($a, $b) {
57
		if(count($a) !== count($b)) {
58
			return false;
59
		}
60
61
		for($i = 0; $i < count($a); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
Performance Best Practice introduced by
Consider avoiding function calls on each iteration of the for loop.

If you have a function call in the test part of a for loop, this function is executed on each iteration. Often such a function, can be moved to the initialization part and be cached.

// count() is called on each iteration
for ($i=0; $i < count($collection); $i++) { }

// count() is only called once
for ($i=0, $c=count($collection); $i<$c; $i++) { }
Loading history...
62
			if(!$a[$i]->equals($b[$i])) {
63
				return false;
64
			}
65
		}
66
67
		return true;
68
	}
69
70
	public function requestAndResponseProvider() {
71
		return array(
72
			array(
73
				new ModuleRequest(
74
					'en',
75
					new MissingNode(),
76
					'a'
77
				),
78
				array(new ModuleResponse(
79
					'en',
80
					new MissingNode(),
81
					array(),
82
					array("aaaa")
83
				))
84
			),
85
			array(
86
				new ModuleRequest(
87
					'en',
88
					new SentenceNode(''),
89
					'a'
90
				),
91
				array()
92
			),
93
			array(
94
				new ModuleRequest(
95
					'en',
96
					new ResourceListNode(array(new TimeResourceNode('1933-11'))),
97
					'a',
98
					array(
99
						'accuracy' => 0.5
100
					)
101
				),
102
				array(new ModuleResponse(
103
					'en',
104
					new ResourceListNode(array(new TimeResourceNode('1933-11'))),
105
					array(
106
						'accuracy' => 0.25,
107
						'relevance' => 1
108
					)
109
				))
110
			),
111
			array(
112
				new ModuleRequest(
113
					'en',
114
					new TripleNode(
115
						new ResourceListNode(array(new StringResourceNode('Q42'))),
116
						new ResourceListNode(array(new StringResourceNode('P214'))),
117
						new MissingNode()
118
					),
119
					'a'
120
				),
121
				array(new ModuleResponse(
122
					'en',
123
					new ResourceListNode(array(
124
						new JsonLdResourceNode(
125
							'foo',
126
							(object) array(
127
								'@context' => 'http://schema.org',
128
								'@type' => 'Text',
129
								'http://www.w3.org/1999/02/22-rdf-syntax-ns#value' => (object) array(
130
									'@value' => '113230702'
131
								)
132
							)
133
						)
134
					)),
135
					array(
136
						'relevance' => 1
137
					)
138
				))
139
			),
140
			array(
141
				new ModuleRequest(
142
					'en',
143
					new TripleNode(
144
						new ResourceListNode(array(new StringResourceNode('Barack Obama'))),
145
						new ResourceListNode(array(new StringResourceNode('name'))),
146
						new MissingNode()
147
					),
148
					'a'
149
				),
150
				array(new ModuleResponse(
151
					'en',
152
					new ResourceListNode(array(new JsonLdResourceNode(
153
						'Barack Obama',
154
						(object) array(
155
							'@context' => 'http://schema.org',
156
							'@id' => 'http://www.wikidata.org/entity/Q76',
157
							'name' => 'Barack Obama'
158
						)
159
					))),
160
					array(
161
						'relevance' => 1
162
					)
163
				))
164
			),
165
			array(
166
				new ModuleRequest(
167
					'en',
168
					new TripleNode(
169
						new ResourceListNode(array(new StringResourceNode('Q243'))),
170
						new ResourceListNode(array(new StringResourceNode('P2048'))),
171
						new MissingNode()
172
					),
173
					'a'
174
				),
175
				array(new ModuleResponse(
176
					'en',
177
					new ResourceListNode(array(
178
						new JsonLdResourceNode(
179
							'324 m',
180
							(object) array(
181
								'@context' => 'http://schema.org',
182
								'@type' => 'QuantitativeValue',
183
								'value' => (object) array('@type' => 'Integer', '@value' => 324),
184
								'maxValue' => (object) array('@type' => 'Integer', '@value' => 324),
185
								'minValue' => (object) array('@type' => 'Integer', '@value' => 324),
186
								'name' => '324 m',
187
								'unitCode' => 'http://www.wikidata.org/entity/Q11573',
188
								'@reverse' => (object) array(
189
									'height' => (object) array('@id' => 'http://www.wikidata.org/entity/Q243')
190
								)
191
							)
192
						)
193
					)),
194
					array(
195
						'relevance' => 1
196
					)
197
				))
198
			),
199
			array(
200
				new ModuleRequest(
201
					'ru',
202
					new TripleNode(
203
						new MissingNode(),
204
						new ResourceListNode(array(new StringResourceNode('VIAF'))),
205
						new ResourceListNode(array(new StringResourceNode('113230702')))
206
					),
207
					'a'
208
				),
209
				array(new ModuleResponse(
210
					'ru',
211
					new ResourceListNode(array(new JsonLdResourceNode(
212
						'Дуглас Адамс',
213
						(object) array(
214
							'@context' => 'http://schema.org',
215
							'@id' => 'http://www.wikidata.org/entity/Q42',
216
							'name' => 'Douglas Adams'
217
						)
218
					))),
219
					array(
220
						'relevance' => 1
221
					)
222
				))
223
			),
224
			array(
225
				new ModuleRequest(
226
					'en',
227
					new TripleNode(
228
						new TripleNode(
229
							new MissingNode(),
230
							new ResourceListNode(array(new StringResourceNode('VIAF'))),
231
							new ResourceListNode(array(new StringResourceNode('113230702')))
232
						),
233
						new ResourceListNode(array(new StringResourceNode('Birth place'))),
234
						new MissingNode()
235
					),
236
					'a'
237
				),
238
				array(new ModuleResponse(
239
					'en',
240
					new ResourceListNode(array(new JsonLdResourceNode(
241
						'Cambridge',
242
						(object) array(
243
							'@context' => 'http://schema.org',
244
							'@id' => 'http://www.wikidata.org/entity/Q350',
245
							'name' => 'Cambridge'
246
						)
247
					))),
248
					array(
249
						'relevance' => 1
250
					)
251
				))
252
			),
253
			array(
254
				new ModuleRequest(
255
					'en',
256
					new TripleNode(
257
						new MissingNode(),
258
						new ResourceListNode(array(new StringResourceNode('son'))),
259
						new TripleNode(
260
							new MissingNode(),
261
							new ResourceListNode(array(new StringResourceNode('VIAF identifier'))),
262
							new ResourceListNode(array(new StringResourceNode('45777651')))
263
						)
264
					),
265
					'a'
266
				),
267
				array(
268
					new ModuleResponse(
269
						'en',
270
						new ResourceListNode(array(
271
							new JsonLdResourceNode(
272
								'Setnakhte',
273
								(object) array(
274
									'@context' => 'http://schema.org',
275
									'@id' => 'http://www.wikidata.org/entity/Q312402',
276
									'name' => 'Setnakhte'
277
								)
278
							),
279
							new JsonLdResourceNode(
280
								'Tiy-Merenese',
281
								(object) array(
282
									'@context' => 'http://schema.org',
283
									'@id' => 'http://www.wikidata.org/entity/Q1321008',
284
									'name' => 'Tiy-Merenese'
285
								)
286
							)
287
						)),
288
						array(
289
							'relevance' => 1
290
						)
291
					),
292
				)
293
			),
294
			array(
295
				new ModuleRequest(
296
					'en',
297
					new TripleNode(
298
						new ResourceListNode(array(
299
							new StringResourceNode('Douglas Adams'),
300
							new StringResourceNode('Jean-François Champollion')
301
						)),
302
						new ResourceListNode(array(new StringResourceNode('VIAF'))),
303
						new MissingNode()
304
					),
305
					'a'
306
				),
307
				array(new ModuleResponse(
308
					'en',
309
					new ResourceListNode(array(
310
						new JsonLdResourceNode(
311
							'foo',
312
							(object) array(
313
								'@context' => 'http://schema.org',
314
								'@type' => 'Text',
315
								'http://www.w3.org/1999/02/22-rdf-syntax-ns#value' => (object) array(
316
									'@value' => '113230702'
317
								)
318
							)
319
						),
320
						new JsonLdResourceNode(
321
							'foo',
322
							(object) array(
323
								'@context' => 'http://schema.org',
324
								'@type' => 'Text',
325
								'http://www.w3.org/1999/02/22-rdf-syntax-ns#value' => (object) array(
326
									'@value' => '34454460'
327
								)
328
							)
329
						)
330
					)),
331
					array(
332
						'relevance' => 1
333
					)
334
				))
335
			),
336
			array(
337
				new ModuleRequest(
338
					'en',
339
					new UnionNode(array(
340
						new TripleNode(
341
							new ResourceListNode(array(new StringResourceNode('Douglas Adams'))),
342
							new ResourceListNode(array(new StringResourceNode('VIAF'))),
343
							new MissingNode()
344
						),
345
						new TripleNode(
346
							new ResourceListNode(array(new StringResourceNode('Jean-François Champollion'))),
347
							new ResourceListNode(array(new StringResourceNode('VIAF'))),
348
							new MissingNode()
349
						)
350
					)),
351
					'a'
352
				),
353
				array(new ModuleResponse(
354
					'en',
355
					new ResourceListNode(array(
356
						new JsonLdResourceNode(
357
							'foo',
358
							(object) array(
359
								'@context' => 'http://schema.org',
360
								'@type' => 'Text',
361
								'http://www.w3.org/1999/02/22-rdf-syntax-ns#value' => (object) array(
362
									'@value' => '113230702'
363
								)
364
							)
365
						),
366
						new JsonLdResourceNode(
367
							'foo',
368
							(object) array(
369
								'@context' => 'http://schema.org',
370
								'@type' => 'Text',
371
								'http://www.w3.org/1999/02/22-rdf-syntax-ns#value' => (object) array(
372
									'@value' => '34454460'
373
								)
374
							)
375
						)
376
					)),
377
					array(
378
						'relevance' => 1
379
					)
380
				))
381
			),
382
			array(
383
				new ModuleRequest(
384
					'en',
385
					new IntersectionNode(array(
386
						new TripleNode(
387
							new ResourceListNode(array(new StringResourceNode('Douglas Adams'))),
388
							new ResourceListNode(array(new StringResourceNode('VIAF'))),
389
							new MissingNode()
390
						),
391
						new TripleNode(
392
							new ResourceListNode(array(new StringResourceNode('Douglas Adams'))),
393
							new ResourceListNode(array(new StringResourceNode('VIAF'))),
394
							new MissingNode()
395
						)
396
					)),
397
					'a'
398
				),
399
				array(new ModuleResponse(
400
					'en',
401
					new ResourceListNode(array(new JsonLdResourceNode(
402
						'foo',
403
						(object) array(
404
							'@context' => 'http://schema.org',
405
							'@type' => 'Text',
406
							'http://www.w3.org/1999/02/22-rdf-syntax-ns#value' => (object) array(
407
								'@value' => '113230702'
408
							)
409
						)
410
					))),
411
					array(
412
						'relevance' => 1
413
					)
414
				))
415
			),
416
			array(
417
				new ModuleRequest(
418
					'en',
419
					new IntersectionNode(array(
420
						new TripleNode(
421
							new MissingNode(),
422
							new ResourceListNode(array(new StringResourceNode('occupation'))),
423
							new ResourceListNode(array(new StringResourceNode('poet')))
424
						),
425
						new TripleNode(
426
							new MissingNode(),
427
							new ResourceListNode(array(new StringResourceNode('occupation'))),
428
							new ResourceListNode(array(new StringResourceNode('computer scientist')))
429
						),
430
						new TripleNode(
431
							new MissingNode(),
432
							new ResourceListNode(array(new StringResourceNode('sex'))),
433
							new ResourceListNode(array(new StringResourceNode('female')))
434
						)
435
					)),
436
					'a'
437
				),
438
				array(new ModuleResponse(
439
					'en',
440
					new ResourceListNode(array(
441
						new JsonLdResourceNode(
442
							'Ada Lovelace',
443
							(object) array(
444
								'@context' => 'http://schema.org',
445
								'@id' => 'http://www.wikidata.org/entity/Q7259',
446
								'name' => 'Ada Lovelace'
447
							)
448
						)
449
					)),
450
					array(
451
						'relevance' => 1
452
					)
453
				))
454
			),
455
			array(
456
				new ModuleRequest(
457
					'en',
458
					new TripleNode(
459
						new ResourceListNode(array(new StringResourceNode('Nicolas Sarkozy'))),
460
						new ResourceListNode(array(new StringResourceNode('daughter'))),
461
						new MissingNode()
462
					),
463
					'a'
464
				),
465
				array(new ModuleResponse(
466
					'en',
467
					new ResourceListNode(array(new JsonLdResourceNode(
468
						'Giulia Sarkozy',
469
						(object) array(
470
							'@context' => 'http://schema.org',
471
							'@id' => 'http://www.wikidata.org/entity/Q16338096',
472
							'name' => 'Giulia Sarkozy'
473
						)
474
					))),
475
					array(
476
						'relevance' => 1
477
					)
478
				))
479
			),
480
			array(
481
				new ModuleRequest(
482
					'en',
483
					new IntersectionNode(array(
484
						new ResourceListNode(array(new StringResourceNode('Barack Obama'))),
485
						new TripleNode(
486
							new MissingNode(),
487
							new ResourceListNode(array(new StringResourceNode('instance of'))),
488
							new ResourceListNode(array(new StringResourceNode('human')))
489
						)
490
					)),
491
					'a'
492
				),
493
				array(new ModuleResponse(
494
					'en',
495
					new ResourceListNode(array(new JsonLdResourceNode(
496
						'Barack Obama',
497
						(object) array(
498
							'@context' => 'http://schema.org',
499
							'@id' => 'http://www.wikidata.org/entity/Q76',
500
							'name' => 'Barack Obama'
501
						)
502
					))),
503
					array(
504
						'relevance' => 1
505
					)
506
				))
507
			),
508
			array(
509
				new ModuleRequest(
510
					'en',
511
					new FirstNode(new SortNode(
512
						new TripleNode(
513
							new ResourceListNode(array(new StringResourceNode('Douglas Adams'))),
514
							new ResourceListNode(array(new StringResourceNode('VIAF'))),
515
							new MissingNode()
516
						),
517
						new StringResourceNode('default')
518
					)),
519
					'a'
520
				),
521
				array(new ModuleResponse(
522
					'en',
523
					new FirstNode(new SortNode(
524
						new ResourceListNode(array(new JsonLdResourceNode(
525
							'foo',
526
							(object) array(
527
								'@context' => 'http://schema.org',
528
								'@type' => 'Text',
529
								'http://www.w3.org/1999/02/22-rdf-syntax-ns#value' => (object) array(
530
									'@value' => '113230702'
531
								)
532
							)
533
						))),
534
						new StringResourceNode('default')
535
					))
536
				))
537
			),
538
			array(
539
				new ModuleRequest(
540
					'en',
541
					new TripleNode(
542
						new MissingNode(),
543
						new ResourceListNode(array(new StringResourceNode('instance of'))),
544
						new ResourceListNode(array(new StringResourceNode('azertyyuiopqdf')))
545
					),
546
					'a'
547
				),
548
				array()
549
			),
550
			array(
551
				new ModuleRequest(
552
					'en',
553
					new UnionNode(array(
554
						new TripleNode(
555
							new MissingNode(),
556
							new ResourceListNode(array(new StringResourceNode('VIAF of'))),
557
							new ResourceListNode(array(new StringResourceNode('Douglas Adams')))
558
						),
559
						new TripleNode(
560
							new ResourceListNode(array(new StringResourceNode('Douglas Adams'))),
561
							new ResourceListNode(array(new StringResourceNode('VIAF'))),
562
							new MissingNode()
563
						)
564
					)),
565
					'a'
566
				),
567
				array(new ModuleResponse(
568
					'en',
569
					new ResourceListNode(array(new JsonLdResourceNode(
570
						'foo',
571
						(object) array(
572
							'@context' => 'http://schema.org',
573
							'@type' => 'Text',
574
							'http://www.w3.org/1999/02/22-rdf-syntax-ns#value' => (object) array(
575
								'@value' => '113230702'
576
							)
577
						)
578
					))),
579
					array(
580
						'relevance' => 1
581
					)
582
				))
583
			),
584
			/*array( TODO: Implement support of goecoordinates queries
585
				new ModuleRequest(
586
					'en',
587
					new TripleNode(
588
						new MissingNode(),
589
						new ResourceListNode(array(new StringResourceNode('location'))),
590
						new TripleNode(
591
							new ResourceListNode(array(new StringResourceNode('ENS Lyon'))),
592
							new ResourceListNode(array(new StringResourceNode('location'))),
593
							new MissingNode()
594
						)
595
					),
596
					'a'
597
				),
598
				array(new ModuleResponse(
599
					'en',
600
					new ResourceListNode(array(
601
						new JsonLdResourceNode(
602
							'ENS Lyon',
603
							(object) array(
604
								'@context' => 'http://schema.org',
605
								'@id' => 'http://www.wikidata.org/entity/Q10159'
606
							)
607
						),
608
						new JsonLdResourceNode(
609
							'ENS Lyon',
610
							(object) array(
611
								'@context' => 'http://schema.org',
612
								'@id' => 'http://www.wikidata.org/entity/Q3214458'
613
							)
614
						)
615
					)),
616
					array(
617
						'relevance' => 1
618
					)
619
				))
620
			),*/
621
			array(
622
				new ModuleRequest(
623
					'en',
624
					new SentenceNode('Barack Obama'),
625
					'a'
626
				),
627
				array(new ModuleResponse(
628
					'en',
629
					new ResourceListNode(array(new JsonLdResourceNode(
630
						'Barack Obama',
631
						(object) array(
632
							'@context' => 'http://schema.org',
633
							'@id' => 'http://www.wikidata.org/entity/Q76',
634
							'name' => 'Barack Obama'
635
						)
636
					))),
637
					array(
638
						'relevance' => 1
639
					)
640
				))
641
			),
642
			array(
643
				new ModuleRequest(
644
					'en',
645
					new SentenceNode('Who is Tpt?'),
646
					'a'
647
				),
648
				array()
649
			),
650
		);
651
	}
652
}
653