* @copyright 2014 Fabian Grutschus. All rights reserved. * @license BSD * @link http://github.com/fabiang/xmpp */ namespace Fabiang\Xmpp\Integration; use Behat\Behat\Context\BehatContext; use Behat\Behat\Exception\PendingException; use Fabiang\Xmpp\Util\XML; class AuthenticationContext extends BehatContext { /** * @Given /^Test response data for plain$/ */ public function testResponseDataForPlain() { $this->getConnection()->setData(array( "" . "PLAIN" . "", "", "" )); } /** * @Given /^Test response data for authentication failure$/ */ public function testResponseDataForAuthenticationFailure() { $this->getConnection()->setData(array( "" . "PLAIN" . "", "" )); } /** * @Given /^Test response data for digest-md5 auth$/ */ public function testResponseDataForDigestMdAuth() { $this->getConnection()->setData(array( "", "" . "DIGEST-MD5" . "", '' . XML::base64Encode( 'realm="localhost",nonce="abcdefghijklmnopqrstuvw",' . 'qop="auth",charset=utf-8,algorithm=md5-sess' ) . '', '' . XML::base64Encode('rspauth=1234567890') . '', '' . XML::base64Encode('rspauth=7fb0ac7ac1ff501a330a76e89a0f1633') . '', "" )); } /** * @Then /^plain authentication element should be send$/ */ public function plainAuthenticationElementShouldBeSend() { assertContains( 'AGFhYQBiYmI=', $this->getConnection()->getBuffer() ); } /** * @Then /^digest-md5 authentication element should be send$/ */ public function digestMdAuthenticationElementShouldBeSend() { $buffer = $this->getConnection()->getBuffer(); assertContains('', $buffer[1]); } /** * @Given /^should be authenticated$/ */ public function shouldBeAuthenticated() { assertTrue($this->getConnection()->getOptions()->isAuthenticated()); } /** * @Then /^a authorization exception should be catched$/ */ public function aAuthorizationExceptionShouldBeCatched() { /* @var $exception \Exception */ $exception = $this->getMainContext()->exception; assertInstanceOf('\Fabiang\Xmpp\Exception\Stream\AuthenticationErrorException', $exception); assertSame('Stream Error: "not-authorized"', $exception->getMessage()); } /** * @Then /^digest-md5 response send$/ */ public function digestMdResponseSend() { $buffer = $this->getConnection()->getBuffer(); assertRegExp('#^[\w=]+$#', $buffer[2]); } /** * @Then /^empty digest-md5 response send$/ */ public function emptyDigestMdResponseSend() { $buffer = $this->getConnection()->getBuffer(); assertRegExp('', $buffer[3]); } /** * * @return \Fabiang\Xmpp\Connection\Test */ public function getConnection() { return $this->getMainContext()->getConnection(); } }