Skip to content

Commit

Permalink
Throw an exception if attempting to use authentication without SASL s…
Browse files Browse the repository at this point in the history
…upport installed
  • Loading branch information
wa0x6e committed Aug 27, 2013
1 parent f093a31 commit bdd00c2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Cake/Cache/Engine/MemcachedEngine.php
Expand Up @@ -96,6 +96,11 @@ public function init($settings = array()) {
}

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']);
}
}
Expand Down
27 changes: 27 additions & 0 deletions lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php
Expand Up @@ -133,6 +133,33 @@ public function testCompressionSetting() {
$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
*
Expand Down

0 comments on commit bdd00c2

Please sign in to comment.