diff --git a/lib/Cake/Cache/Engine/MemcachedEngine.php b/lib/Cake/Cache/Engine/MemcachedEngine.php index f7fbca3e2..6b5dd738f 100755 --- a/lib/Cake/Cache/Engine/MemcachedEngine.php +++ b/lib/Cake/Cache/Engine/MemcachedEngine.php @@ -96,6 +96,11 @@ class MemcachedEngine extends CacheEngine { } if ($this->settings['login'] !== null && $this->settings['password'] !== null) { + if (!method_exists($this->_Memcached, 'setSaslAuthData')) { + throw new CacheException( + __d('cake_dev', 'Memcached extension is not build with SASL support') + ); + } $this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']); } } diff --git a/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php b/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php index c1e926640..73741dabc 100755 --- a/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php +++ b/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php @@ -133,6 +133,33 @@ class MemcachedEngineTest extends CakeTestCase { $this->assertTrue($MemcachedCompressed->getMemcached()->getOption(Memcached::OPT_COMPRESSION)); } +/** + * test using authentication without memcached installed with SASL support + * throw an exception + * + * @return void + */ + public function testSaslAuthException() { + $Memcached = new TestMemcachedEngine(); + $settings = array( + 'engine' => 'Memcached', + 'servers' => array('127.0.0.1:11211'), + 'persistent' => false, + 'login' => 'test', + 'password' => 'password' + ); + + $this->skipIf( + method_exists($Memcached->getMemcached(), 'setSaslAuthData'), + 'Memcached extension is installed with SASL support' + ); + + $this->setExpectedException( + 'CacheException', 'Memcached extension is not build with SASL support' + ); + $Memcached->init($settings); + } + /** * testSettings method *