Issues (1752)

Security Analysis    not enabled

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.

class/cache/cache.test.php (7 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
 * Test - Cache class
4
 * @package     fwolflib
5
 * @subpackage	class.test
6
 * @copyright   Copyright 2012, Fwolf
7
 * @author      Fwolf <[email protected]>
8
 * @since		2012-11-06
9
 */
10
11
// Define like this, so test can run both under eclipse and web alone.
12
// {{{
13
if (! defined('SIMPLE_TEST')) {
14
	define('SIMPLE_TEST', 'simpletest/');
15
	require_once(SIMPLE_TEST . 'autorun.php');
16
}
17
// Then set output encoding
18
//header('Content-Type: text/html; charset=utf-8');
19
// }}}
20
21
// Require library define file which need test
22
require_once(dirname(__FILE__) . '/../fwolflib.php');
23
require_once(FWOLFLIB . 'class/cache/cache.php');
24
require_once(FWOLFLIB . 'func/ecl.php');
25
require_once(FWOLFLIB . 'func/request.php');
26
require_once(FWOLFLIB . 'func/string.php');
27
// Test memcached client
28
//require_once dirname(__FILE__) . '/../../../memcached-client/memcached.php';
29
30
class TestCache extends UnitTestCase {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type TestCache has been defined more than once; this definition is ignored, only the first definition in class/cache.test.php (L28-103) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
31
32
	/**
33
	 * Cache object
34
	 * @var	object
35
	 */
36
	protected $oCh = null;
37
38
39
	/**
40
	 * Constructor
41
	 */
42
	public function __construct () {
43
44
	} // end of func __construct
45
46
47
	public function TestCacheDefault () {
48
		//$this->oCh = new Cache();
49
		//$this->oCh = Cache::Create('unsupported');
50
		//$this->assertEqual(NULL, $this->oCh);
51
52
		$this->oCh = Cache::Create('');
0 ignored issues
show
The method Create() does not seem to exist on object<Cache>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
		$this->assertEqual('', $this->oCh->aCfg['cache-type']);
54
55
		$key = 'key';
56
		$val = 'val';
57
		$this->oCh->Set($key, $val);
58
		$this->assertEqual($val, $this->oCh->Get($key));
59
60
		$this->oCh->Del($key);
61
		$this->assertEqual(NULL, $this->oCh->Get($key));
62
63
64
		// Val encode and decode
65
		$x = 'This is string.';
66
		$this->assertEqual($x, $this->oCh->ValDecode(
67
			$this->oCh->ValEncode($x, 0), 0));
68
		// Invalid flag
69
		$this->assertEqual($x, $this->oCh->ValDecode(
70
			$this->oCh->ValEncode($x, 100), 100));
71
72
		$x = array('a' => 'b');
73
		$this->assertEqual($x, $this->oCh->ValDecode(
74
			$this->oCh->ValEncode($x, 0), 0));
75
		$this->assertEqual($x, $this->oCh->ValDecode(
76
			$this->oCh->ValEncode($x, 1), 1));
77
78
/*
79
		// Json decode object has no class, so diff with original
80
		// Also array in object must be convert back from stdClass
81
		$this->oCh->SetCfg('cache-store-method', 2);
82
		$x = new Fwolflib;
83
		$this->assertEqual($x, $this->oCh->ValDecode(
84
			$this->oCh->ValEncode($x, 0), 0));
85
86
		$y = $this->oCh->ValDecode($this->oCh->ValEncode($x, 2), 2);
87
		$y->aCfg = (array)$y->aCfg;
88
		$this->assertEqual($x, $y);
89
		var_dump($x);
90
		var_dump($y);
91
*/
92
93
		// Expire time
94
		$x = 0;
95
		$this->assertEqual($x, $this->oCh->ExpireTime($x));
96
97
		$x = time() + 2592000;
98
		$this->assertEqual($x, $this->oCh->ExpireTime(2592000));
99
100
		$x = 2592001;
101
		$this->assertEqual($x, $this->oCh->ExpireTime(2592001));
102
103
		$x = time() + 2592000;
104
		$this->assertEqual($x, $this->oCh->ExpireTime());
105
106
		// Get log
107
		//var_dump(Cache::$aLogGet);
108
109
	} // end of func TestCacheDefault
110
111
112
	public function TestCacheFile () {
113
/*
114
		// Wrong cfg test
115
		$this->oCh = Cache::Create('file'
116
			, array('cache-file-dir' => '/proc/'));
117
		$this->assertEqual(false, $this->oCh->ChkCfg());
118
119
		$this->oCh = Cache::Create('file'
120
			, array('cache-file-rule' => '0blah'));
121
		$this->assertEqual(false, $this->oCh->ChkCfg());
122
*/
123
124
		$this->oCh = Cache::Create('file');
0 ignored issues
show
The method Create() does not seem to exist on object<Cache>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
125
		$this->oCh->SetCfg('cache-file-rule', '1140');
126
		$key = 'site/index';
127
128
		$x = '/tmp/cache/d0/ex/3ed0dc6e';
129
		$y = $this->oCh->FilePath($key);
130
		$this->assertEqual($x, $y);
131
132
		$this->oCh->SetCfg(array('cache-file-rule' => '1131'));
133
		$x = '/tmp/cache/d0/te/3ed0dc6e';
134
		$y = $this->oCh->FilePath($key);
135
		$this->assertEqual($x, $y);
136
137
		// Notice: Directly use key's part as path may cause wrong
138
		$this->oCh->SetCfg(array('cache-file-rule' => '2342'));
139
		$x = '/tmp/cache/57//i/3ed0dc6e';
140
		$y = $this->oCh->FilePath($key);
141
		$this->assertEqual($x, $y);
142
143
		// Common usage
144
		$this->oCh->SetCfg(array('cache-file-rule' => '1011'));
145
		$x = '/tmp/cache/3e/d0/3ed0dc6e';
146
		$y = $this->oCh->FilePath($key);
147
		$this->assertEqual($x, $y);
148
149
		// Common usage 2
150
		$this->oCh->SetCfg(array('cache-file-rule' => '2021'));
151
		$x = '/tmp/cache/b6/9c/3ed0dc6e';
152
		$y = $this->oCh->FilePath($key);
153
		$this->assertEqual($x, $y);
154
155
		// Common usage 3
156
		$this->oCh->SetCfg(array('cache-file-rule' => '55'));
157
		$x = '/tmp/cache/89/3ed0dc6e';
158
		$y = $this->oCh->FilePath($key);
159
		$this->assertEqual($x, $y);
160
161
162
		// Skip cache write after test.
163
/*
164
		// Cache set
165
		$v = 'blah';
166
		$this->oCh->SetCfg('cache-store-method', 1);
167
		$this->oCh->Set($key, $v);
168
		$this->assertEqual(json_encode($v), file_get_contents($x));
169
170
		// Cache expire
171
		$this->assertEqual(true, $this->oCh->Expire($key, -10));
172
		$this->assertEqual(true, $this->oCh->Expire($key, strtotime('2012-1-1')));
173
		$this->assertEqual(false, $this->oCh->Expire($key, 10));
174
		$this->assertEqual(false, $this->oCh->Expire($key, 1));
175
		$this->assertEqual(false, $this->oCh->Expire($key, 0));
176
		$this->assertEqual(false, $this->oCh->Expire($key, NULL));
177
178
		// Cache get
179
		$this->assertEqual($v, $this->oCh->Get($key));
180
		$this->assertEqual(NULL, $this->oCh->Get($key, -10));
181
		$this->assertEqual($v, $this->oCh->Get($key, 0));
182
		$this->assertEqual($v, $this->oCh->Get($key, 5));
183
		$this->assertEqual($v, $this->oCh->Get($key, NULL));
184
185
		$v = '你好';
186
		$this->oCh->SetCfg('cache-store-method', 0);
187
		$this->oCh->Set($key, $v);
188
		$this->assertEqual($v, $this->oCh->Get($key));
189
190
		$v = array('你' => '好');
191
		$this->oCh->SetCfg('cache-store-method', 1);
192
		$this->oCh->Set($key, $v);
193
		$this->assertEqual($v, $this->oCh->Get($key));
194
195
		// Cache del
196
		$this->oCh->Del($key);
197
		$this->assertEqual(NULL, $this->oCh->Get($key));
198
199
*/
200
		// End of cache write test.
201
202
		// Get log
203
		//var_dump(Cache::$aLogGet);
204
205
	} // end of func TestCacheFile
206
207
208
    function TestCacheMemcached () {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
209
		$this->oCh = Cache::Create('memcached');
0 ignored issues
show
The method Create() does not seem to exist on object<Cache>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
210
211
		// Empty server list
212
		$ar = $this->oCh->oMemcached->getServerList();
213
		$this->assertEqual($ar, array());
214
215
216
		// Set server cfg
217
		$x = array(
218
			array(
219
				'host'		=> 'localhost',
220
				'port'		=> 11211,
221
				'weight'	=> 0,
222
			),
223
		);
224
		$this->oCh->SetCfg('cache-memcached-server', $x);
225
		unset($this->oCh->oMemcached);
226
		$ar = $this->oCh->oMemcached->getServerList();
227
		$this->assertEqual($ar, $x);
228
229
		$y = array('localhost', 11211);
230
		$this->oCh->SetCfgServer($y);
231
		$this->assertEqual($x, $this->oCh->oMemcached->getServerList());
232
233
		// Memcache server recognize by array position, not assoc key
234
		$y = array('h' => 'localhost', 'p' => 11211);
235
		$this->oCh->SetCfgServer($y);
236
		$this->assertEqual($x, $this->oCh->oMemcached->getServerList());
237
238
		// Skip cache write after test
239
/*
240
		// Multi server
241
		$x = array(
242
			// Dead one
243
			array(
244
				'host'		=> 'localhost',
245
				'port'		=> 11212,
246
				'weight'	=> 67
247
			),
248
			// Alive one
249
			array(
250
				'host'		=> 'localhost',
251
				'port'		=> 11211,
252
				'weight'	=> 33
253
			),
254
		);
255
		$this->oCh->SetCfgServer($x);
256
		$this->assertEqual(array($x[1])
257
			, $this->oCh->oMemcached->getServerList());
258
259
		// Cache write
260
		$key = RandomString(8, 'a0');
261
		$x = 'blah';
262
		$this->oCh->Set($key, $x, 60);
263
		$this->assertEqual($x, $this->oCh->Get($key));
264
265
		$x = array('blah', array('foo' => 'boo'));
266
		$this->oCh->Set($key, $x, 60);
267
		$this->assertEqual($x, $this->oCh->Get($key));
268
269
		// Cache expire
270
		$this->oCh->SetCfg('cache-memcached-autosplit', 1);
271
		$this->oCh->Set($key, $x, 60);
272
		$this->assertEqual(false, $this->oCh->Expire($key));
273
		$this->oCh->Set($key, $x, -10);
274
		$this->assertEqual(true, $this->oCh->Expire($key));
275
		$this->oCh->SetCfg('cache-memcached-autosplit', 0);
276
		$this->oCh->Set($key, $x, 60);
277
		$this->assertEqual(false, $this->oCh->Expire($key));
278
		$this->oCh->Set($key, $x, -10);
279
		$this->assertEqual(true, $this->oCh->Expire($key));
280
281
		// Cache del
282
		$this->oCh->Del($key);
283
		$this->assertEqual(NULL, $this->oCh->Get($key));
284
285
		// Long key
286
		$key = str_repeat('-', 300);
287
		$x = 'blah';
288
		$this->oCh->Set($key, $x, 60);
289
		$this->assertEqual($x, $this->oCh->Get($key));
290
		$this->oCh->Del($key);
291
		$this->assertEqual(NULL, $this->oCh->Get($key));
292
293
		// Empty key
294
		$key = '';
295
		$x = 'blah';
296
		$this->oCh->Set($key, $x, 60);
297
		$this->assertEqual($x, $this->oCh->Get($key));
298
299
		// Cache get with expire
300
		$key = RandomString(8, 'a0');
301
		$this->oCh->Set($key, $x, -10);
302
		$this->assertEqual(NULL, $this->oCh->Get($key));
303
		$this->oCh->Set($key, $x, 0);
304
		$this->assertEqual($x, $this->oCh->Get($key));
305
		$this->oCh->Set($key, $x, 5);
306
		$this->assertEqual($x, $this->oCh->Get($key));
307
		$this->oCh->Set($key, $x, NULL);
308
		$this->assertEqual($x, $this->oCh->Get($key));
309
310
		// Massive set
311
//		$s = RandomString(2000000, 'a0');
312
//		for ($i = 0; $i < 100; $i++) {
313
//			$this->oCh->Set($i, $s, 3600);
314
//		}
315
//		$this->assertEqual(0, $this->oCh->oMemcached->getResultCode());
316
317
		// Big value exceed max item size
318
//		$s = RandomString(3000000, 'a0');
319
//		$this->oCh->Del($key);		// Clear previous setted value
320
//		$this->oCh->SetCfg('cache-memcached-autosplit', 1);
321
//		$this->oCh->Set($key, $s, 3600);
322
//		$this->assertEqual($s, $this->oCh->Get($key));
323
//		$this->assertEqual(false, $this->oCh->Expire($key));
324
//		$this->oCh->Del($key);
325
//		$this->assertEqual(NULL, $this->oCh->Get($key));
326
//		$this->assertEqual(true, $this->oCh->Expire($key));
327
//		$this->oCh->SetCfg('cache-memcached-autosplit', 0);
328
//		$this->oCh->Set($key, $s, 3600);
329
//		$this->assertEqual(NULL, $this->oCh->Get($key));
330
331
		// Big value size is computed AFTER compress if compress on
332
//		$s = RandomString(1500000, 'a0');
333
//		$this->oCh->oMemcached->setOption(Memcached::OPT_COMPRESSION
334
//			, false);
335
//		$this->oCh->SetCfg('cache-memcached-autosplit', 0);
336
//		$this->oCh->Set($key, $s, 3600);
337
//		$this->assertEqual(NULL, $this->oCh->Get($key));
338
//		$this->oCh->oMemcached->setOption(Memcached::OPT_COMPRESSION
339
//			, true);
340
//		$this->oCh->Set($key, $s, 3600);
341
//		$this->assertEqual($s, $this->oCh->Get($key));
342
343
*/
344
		// End of cache write test
345
346
		// Get log
347
		//var_dump(Cache::$aLogGet);
348
349
	} // end of func TestCacheMemcached
350
351
352
} // end of class TestCache
353
354
355
// Change output charset in this way.
356
// {{{
357
$s_url = GetSelfUrl(false);
0 ignored issues
show
Deprecated Code introduced by
The function GetSelfUrl() has been deprecated with message: Use Fwlib\Util\HttpUtil::getSelfUrl()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
358
$s_url = substr($s_url, strrpos($s_url, '/') + 1);
359
if ('cache.test.php' == $s_url) {
360
	$test = new TestCache();
361
	$test->run(new HtmlReporter('utf-8'));
362
}
363
// }}}
364
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
365