Browse Source

Merge branch 'master' into feature/debug-security

Jorge González 10 years ago
parent
commit
c71ee14f5a

+ 1 - 1
VERSION.txt

@@ -16,4 +16,4 @@
 // @license       http://www.opensource.org/licenses/mit-license.php MIT License
 // +--------------------------------------------------------------------------------------------+ //
 ////////////////////////////////////////////////////////////////////////////////////////////////////
-3.2.4
+3.2.5

+ 12 - 3
src/Cache/Engine/XcacheEngine.php

@@ -58,7 +58,7 @@ class XcacheEngine extends CacheEngine
      */
     public function init(array $config = [])
     {
-        if ((PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') || !extension_loaded('xcache')) {
+        if (!extension_loaded('xcache')) {
             return false;
         }
 
@@ -77,10 +77,14 @@ class XcacheEngine extends CacheEngine
     {
         $key = $this->_key($key);
 
+        if (!is_numeric($value)) {
+            $value = serialize($value);
+        }
+
         $duration = $this->_config['duration'];
         $expires = time() + $duration;
         xcache_set($key . '_expires', $expires, $duration);
-        return xcache_set($key, serialize($value), $duration);
+        return xcache_set($key, $value, $duration);
     }
 
     /**
@@ -100,7 +104,12 @@ class XcacheEngine extends CacheEngine
             if ($cachetime < $time || ($time + $this->_config['duration']) < $cachetime) {
                 return false;
             }
-            return unserialize(xcache_get($key));
+
+            $value = xcache_get($key);
+            if (is_string($value) && !is_numeric($value)) {
+                $value = unserialize($value);
+            }
+            return $value;
         }
         return false;
     }

+ 3 - 12
src/Network/Request.php

@@ -523,21 +523,12 @@ class Request implements ArrayAccess
     {
         if ($this->trustProxy && $this->env('HTTP_X_FORWARDED_FOR')) {
             $ipaddr = preg_replace('/(?:,.*)/', '', $this->env('HTTP_X_FORWARDED_FOR'));
+        } elseif ($this->trustProxy && $this->env('HTTP_CLIENT_IP')) {
+            $ipaddr = $this->env('HTTP_CLIENT_IP');
         } else {
-            if ($this->env('HTTP_CLIENT_IP')) {
-                $ipaddr = $this->env('HTTP_CLIENT_IP');
-            } else {
-                $ipaddr = $this->env('REMOTE_ADDR');
-            }
+            $ipaddr = $this->env('REMOTE_ADDR');
         }
 
-        if ($this->env('HTTP_CLIENTADDRESS')) {
-            $tmpipaddr = $this->env('HTTP_CLIENTADDRESS');
-
-            if (!empty($tmpipaddr)) {
-                $ipaddr = preg_replace('/(?:,.*)/', '', $tmpipaddr);
-            }
-        }
         return trim($ipaddr);
     }
 

+ 1 - 1
src/Utility/Text.php

@@ -138,7 +138,7 @@ class Text
      * corresponds to a variable placeholder name in $str.
      * Example:
      * ```
-     * Text::insert(':name is :age years old.', ['name' => 'Bob', '65']);
+     * Text::insert(':name is :age years old.', ['name' => 'Bob', 'age' => '65']);
      * ```
      * Returns: Bob is 65 years old.
      *

+ 26 - 7
tests/TestCase/Cache/Engine/XcacheEngineTest.php

@@ -35,10 +35,7 @@ class XcacheEngineTest extends TestCase
     public function setUp()
     {
         parent::setUp();
-        if ((PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg')) {
-            $this->markTestSkipped('Xcache is not available for the CLI.');
-        }
-        if (!function_exists('xcache_set')) {
+        if (!extension_loaded('xcache')) {
             $this->markTestSkipped('Xcache is not installed or configured properly');
         }
         Cache::enable();
@@ -85,6 +82,7 @@ class XcacheEngineTest extends TestCase
             'prefix' => 'cake_',
             'duration' => 3600,
             'probability' => 100,
+            'groups' => [],
         ];
         $this->assertTrue(isset($config['PHP_AUTH_USER']));
         $this->assertTrue(isset($config['PHP_AUTH_PW']));
@@ -104,6 +102,7 @@ class XcacheEngineTest extends TestCase
         $expecting = '';
         $this->assertEquals($expecting, $result);
 
+        // String
         $data = 'this is a test of the emergency broadcasting system';
         $result = Cache::write('test', $data, 'xcache');
         $this->assertTrue($result);
@@ -112,6 +111,23 @@ class XcacheEngineTest extends TestCase
         $expecting = $data;
         $this->assertEquals($expecting, $result);
 
+        // Integer
+        $data = 100;
+        $result = Cache::write('test', 100, 'xcache');
+        $this->assertTrue($result);
+
+        $result = Cache::read('test', 'xcache');
+        $this->assertSame(100, $result);
+
+        // Object
+        $data = (object)['value' => 'an object'];
+        $result = Cache::write('test', $data, 'xcache');
+        $this->assertTrue($result);
+
+        $result = Cache::read('test', 'xcache');
+        $this->assertInstanceOf('stdClass', $result);
+        $this->assertEquals('an object', $result->value);
+
         Cache::delete('test', 'xcache');
     }
 
@@ -167,6 +183,9 @@ class XcacheEngineTest extends TestCase
      */
     public function testClearCache()
     {
+        if ((PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg')) {
+            $this->markTestSkipped('Xcache administration functions are not available for the CLI.');
+        }
         $data = 'this is a test of the emergency broadcasting system';
         $result = Cache::write('clear_test_1', $data, 'xcache');
         $this->assertTrue($result);
@@ -174,7 +193,7 @@ class XcacheEngineTest extends TestCase
         $result = Cache::write('clear_test_2', $data, 'xcache');
         $this->assertTrue($result);
 
-        $result = Cache::clear();
+        $result = Cache::clear(false, 'xcache');
         $this->assertTrue($result);
     }
 
@@ -188,7 +207,7 @@ class XcacheEngineTest extends TestCase
         $result = Cache::write('test_decrement', 5, 'xcache');
         $this->assertTrue($result);
 
-        $result = Cache::decrement('test_decrement', 'xcache');
+        $result = Cache::decrement('test_decrement', 1, 'xcache');
         $this->assertEquals(4, $result);
 
         $result = Cache::read('test_decrement', 'xcache');
@@ -211,7 +230,7 @@ class XcacheEngineTest extends TestCase
         $result = Cache::write('test_increment', 5, 'xcache');
         $this->assertTrue($result);
 
-        $result = Cache::increment('test_increment', 'xcache');
+        $result = Cache::increment('test_increment', 1, 'xcache');
         $this->assertEquals(6, $result);
 
         $result = Cache::read('test_increment', 'xcache');

+ 6 - 6
tests/TestCase/Network/RequestTest.php

@@ -528,7 +528,7 @@ class RequestTest extends TestCase
      *
      * @return void
      */
-    public function testclientIp()
+    public function testClientIp()
     {
         $request = new Request(['environment' => [
             'HTTP_X_FORWARDED_FOR' => '192.168.1.5, 10.0.1.1, proxy.com',
@@ -539,17 +539,17 @@ class RequestTest extends TestCase
         $request->trustProxy = true;
         $this->assertEquals('192.168.1.5', $request->clientIp());
 
-        $request->trustProxy = false;
+        $request->env('HTTP_X_FORWARDED_FOR', '');
         $this->assertEquals('192.168.1.2', $request->clientIp());
 
+        $request->trustProxy = false;
+        $this->assertEquals('192.168.1.3', $request->clientIp());
+
         $request->env('HTTP_X_FORWARDED_FOR', '');
-        $this->assertEquals('192.168.1.2', $request->clientIp());
+        $this->assertEquals('192.168.1.3', $request->clientIp());
 
         $request->env('HTTP_CLIENT_IP', '');
         $this->assertEquals('192.168.1.3', $request->clientIp());
-
-        $request->env('HTTP_CLIENTADDRESS', '10.0.1.2, 10.0.1.1');
-        $this->assertEquals('10.0.1.2', $request->clientIp());
     }
 
     /**