Skip to content

Commit

Permalink
Publish is silent on failure unless ack requested. Fixes #86
Browse files Browse the repository at this point in the history
  • Loading branch information
mbonneau committed Mar 3, 2015
1 parent 912671b commit f380c80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Thruway/Realm.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ private function processAuthenticated(Session $session, Message $msg)
if (!$this->getAuthorizationManager()->isAuthorizedTo($session, $msg)) {
Logger::alert($this,
"Permission denied: " . $msg->getActionName() . " " . $msg->getUri() . " for " . $session->getAuthenticationDetails()->getAuthId());

// we are not to send messages in response to publish messages unless
// they set acknowledge = true
if ($msg instanceof PublishMessage) {
if (!$msg->acknowledge()) return;
}

$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, "wamp.error.not_authorized"));

return;
Expand Down
11 changes: 8 additions & 3 deletions tests/Unit/RealmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,18 @@ public function testUnauthorizedActions() {
$realm->setAuthorizationManager($authorizationManager);

$subscribeMsg = new \Thruway\Message\SubscribeMessage(\Thruway\Common\Utils::getUniqueId(), [], "some_topic");
$publishMsg = new \Thruway\Message\PublishMessage(\Thruway\Common\Utils::getUniqueId(), [], "some_topic");
$publishMsg = new \Thruway\Message\PublishMessage(\Thruway\Common\Utils::getUniqueId(), (object)["acknowledge"=>true], "some_topic");
$registerMsg = new \Thruway\Message\RegisterMessage(\Thruway\Common\Utils::getUniqueId(), [], 'some_procedure');
$callMsg = new \Thruway\Message\CallMessage(\Thruway\Common\Utils::getUniqueId(), [], "some_procedure");

$authorizationManager->expects($this->exactly(4))
$authorizationManager->expects($this->exactly(5))
->method("isAuthorizedTo")
->withConsecutive(
[$this->isInstanceOf('\Thruway\Session'), $this->isInstanceOf('\Thruway\Message\SubscribeMessage')],
[$this->isInstanceOf('\Thruway\Session'), $this->isInstanceOf('\Thruway\Message\PublishMessage')],
[$this->isInstanceOf('\Thruway\Session'), $this->isInstanceOf('\Thruway\Message\RegisterMessage')],
[$this->isInstanceOf('\Thruway\Session'), $this->isInstanceOf('\Thruway\Message\CallMessage')]
[$this->isInstanceOf('\Thruway\Session'), $this->isInstanceOf('\Thruway\Message\CallMessage')],
[$this->isInstanceOf('\Thruway\Session'), $this->isInstanceOf('\Thruway\Message\PublishMessage')]
)
->willReturn(false);;

Expand Down Expand Up @@ -158,6 +159,10 @@ public function testUnauthorizedActions() {
$realm->onMessage($session, $publishMsg);
$realm->onMessage($session, $registerMsg);
$realm->onMessage($session, $callMsg);

// make sure publish doesn't send error back when ack is false
$publishMsg2 = $publishMsg = new \Thruway\Message\PublishMessage(\Thruway\Common\Utils::getUniqueId(), [], "some_topic");;
$realm->onMessage($session, $publishMsg2);
}

public function testImmediateAbort() {
Expand Down

0 comments on commit f380c80

Please sign in to comment.