Issues (7)

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.

phpunit/Unit/ApiSummaryCardContentParserTest.php (1 issue)

Labels
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 SUC\Tests;
4
5
use SUC\ApiSummaryCardContentParser;
6
use SUC\CacheHelper;
7
use Onoi\BlobStore\BlobStore;
8
use Onoi\BlobStore\Container;
9
use ApiMain;
10
use ApiResult;
11
use FauxRequest;
12
use RequestContext;
13
use WebRequest;
14
use Title;
15
16
/**
17
 * @covers \SUC\ApiSummaryCardContentParser
18
 * @group summary-cards
19
 *
20
 * @license GNU GPL v2+
21
 * @since   1.0
22
 *
23
 * @author mwjames
24
 */
25
class ApiSummaryCardContentParserTest extends \PHPUnit_Framework_TestCase {
26
27
	protected function setUp() {
28
		if ( version_compare( $GLOBALS['wgVersion'], '1.25', '<' ) ) {
29
			$this->markTestSkipped( "Don't test < 1.25 API due to changes in 1.25." );
30
		}
31
	}
32
33
	public function testCanConstruct() {
34
35
		$cacheHelper = $this->getMockBuilder( '\SUC\CacheHelper' )
36
			->disableOriginalConstructor()
37
			->getMock();
38
39
		$instance = new ApiSummaryCardContentParser(
40
			$this->newApiMain( array() ),
41
			'summarycards'
42
		);
43
44
		$instance->setCacheHelper( $cacheHelper );
45
46
		$this->assertInstanceOf(
47
			'SUC\ApiSummaryCardContentParser',
48
			$instance
49
		);
50
	}
51
52
	public function testExecuteOnEmptyRequest() {
53
54
		$cacheHelper = $this->getMockBuilder( '\SUC\CacheHelper' )
55
			->disableOriginalConstructor()
56
			->getMock();
57
58
		$instance = new ApiSummaryCardContentParser(
59
			$this->newApiMain( array() ),
60
			'summarycards'
61
		);
62
63
		$instance->setCacheHelper( $cacheHelper );
64
		$instance->execute();
65
66
		$this->assertEquals(
67
			array(
68
				'summarycards' => array(
69
					'text' => '',
70
					'time' => false
71
				),
72
				'_type'   => 'assoc'
73
			),
74
			$instance->getResult()->getResultData()
75
		);
76
	}
77
78
	public function testExecuteOnNonCachedParseRequest() {
79
80
		$container = $this->getMockBuilder( Container::class )
81
			->disableOriginalConstructor()
82
			->getMock();
83
84
		$blobStore = $this->getMockBuilder( BlobStore::class )
85
			->disableOriginalConstructor()
86
			->getMock();
87
88
		$blobStore->expects( $this->atLeastOnce() )
89
			->method( 'read' )
90
			->will( $this->returnValue( $container ) );
91
92
		$cacheHelper = $this->getMockBuilder( CacheHelper::class )
93
			->disableOriginalConstructor()
94
			->getMock();
95
96
		$cacheHelper->expects( $this->any() )
97
			->method( 'getBlobStore' )
98
			->will( $this->returnValue( $blobStore ) );
99
100
		$cacheHelper->expects( $this->atLeastOnce() )
101
			->method( 'newTitleFromText' )
102
			->will( $this->returnValue( Title::newFromText( __METHOD__ ) ) );
103
104
		$params = array(
105
			'text'  => 'Some text',
106
			'title' => 'Foo'
107
		);
108
109
		$instance = new ApiSummaryCardContentParser(
110
			$this->newApiMain( $params ),
111
			'summarycards'
112
		);
113
114
		$instance->setCacheHelper( $cacheHelper );
115
		$instance->execute();
116
117
		$result = $instance->getResult()->getResultData();
118
119
		$this->assertInternalType(
120
			'float',
121
			$result['summarycards']['time']['parse']
122
		);
123
	}
124
125
	public function testExecuteOnUntouchedTemplate() {
126
127
		$container = $this->getMockBuilder( Container::class )
128
			->disableOriginalConstructor()
129
			->getMock();
130
131
		$container->expects( $this->atLeastOnce() )
132
			->method( 'has' )
133
			->will( $this->returnValue( true ) );
134
135
		$blobStore = $this->getMockBuilder( BlobStore::class )
136
			->disableOriginalConstructor()
137
			->getMock();
138
139
		$blobStore->expects( $this->atLeastOnce() )
140
			->method( 'read' )
141
			->will( $this->returnValue( $container ) );
142
143
		$cacheHelper = $this->getMockBuilder( CacheHelper::class )
144
			->disableOriginalConstructor()
145
			->getMock();
146
147
		$cacheHelper->expects( $this->any() )
148
			->method( 'getBlobStore' )
149
			->will( $this->returnValue( $blobStore ) );
150
151
		$cacheHelper->expects( $this->atLeastOnce() )
152
			->method( 'newTitleFromText' )
153
			->will( $this->returnValue( Title::newFromText( __METHOD__ ) ) );
154
155
		$params = array(
156
			'text'  => 'Some text',
157
			'title' => 'Foo',
158
			'template' => 'Bar'
159
		);
160
161
		$instance = new ApiSummaryCardContentParser(
162
			$this->newApiMain( $params ),
163
			'summarycards'
164
		);
165
166
		$instance->setCacheHelper( $cacheHelper );
167
		$instance->execute();
168
169
		$result = $instance->getResult()->getResultData();
170
171
		$this->assertInternalType(
172
			'float',
173
			$result['summarycards']['time']['cached']
174
		);
175
	}
176
177
	private function newApiMain( array $params ) {
178
		return new ApiMain( $this->newRequestContext( $params ), true );
179
	}
180
181
	private function newRequestContext( $request = array() ) {
182
183
		$context = new RequestContext();
184
185
		if ( $request instanceof WebRequest ) {
0 ignored issues
show
The class WebRequest does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
186
			$context->setRequest( $request );
187
		} else {
188
			$context->setRequest( new FauxRequest( $request, true ) );
189
		}
190
191
		$user = $this->getMockBuilder( '\User' )
192
			->disableOriginalConstructor()
193
			->getMock();
194
195
		$context->setUser( $user );
196
197
		return $context;
198
	}
199
200
}
201