Throw an exception if attempting to use authentication without SASL support installed

This commit is contained in:
Kamisama 2013-08-27 13:57:57 -04:00
parent f093a31740
commit bdd00c2307
2 changed files with 32 additions and 0 deletions

View file

@ -96,6 +96,11 @@ class MemcachedEngine extends CacheEngine {
} }
if ($this->settings['login'] !== null && $this->settings['password'] !== null) { 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']); $this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']);
} }
} }

View file

@ -133,6 +133,33 @@ class MemcachedEngineTest extends CakeTestCase {
$this->assertTrue($MemcachedCompressed->getMemcached()->getOption(Memcached::OPT_COMPRESSION)); $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 * testSettings method
* *