Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3295' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Jan 14, 2013
6 parents 3e03422 + 7968e2e + 51d3d2a + 096a05e + 7e58137 + a7ef12f commit 8abd6e8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/PubSubHubbub/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ protected function _getRequestParameters($hubUrl, $mode)
'verify_token' => hash('sha256', $params['hub.verify_token']),
'secret' => null,
'expiration_time' => $expires,
'subscription_state' => PubSubHubbub::SUBSCRIPTION_NOTVERIFIED,
'subscription_state' => ($mode == 'unsubscribe')? PubSubHubbub::SUBSCRIPTION_TODELETE : PubSubHubbub::SUBSCRIPTION_NOTVERIFIED,
);
$this->getStorage()->setSubscription($data);

Expand Down
26 changes: 21 additions & 5 deletions src/PubSubHubbub/Subscriber/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Zend\Feed\PubSubHubbub\Subscriber;

use Zend\Feed\PubSubHubbub;
use Zend\Feed\PubSubHubbub\Exception;
use Zend\Uri;

/**
Expand Down Expand Up @@ -93,19 +94,34 @@ public function handle(array $httpGetData = null, $sendResponseNow = false)
* Handle any (un)subscribe confirmation requests
*/
} elseif ($this->isValidHubVerification($httpGetData)) {
$data = $this->currentSubscriptionData;
$this->getHttpResponse()->setContent($httpGetData['hub_challenge']);
$data['subscription_state'] = PubSubHubbub\PubSubHubbub::SUBSCRIPTION_VERIFIED;
if (isset($httpGetData['hub_lease_seconds'])) {
$data['lease_seconds'] = $httpGetData['hub_lease_seconds'];

switch (strtolower($httpGetData['hub_mode'])) {
case 'subscribe':
$data = $this->currentSubscriptionData;
$data['subscription_state'] = PubSubHubbub\PubSubHubbub::SUBSCRIPTION_VERIFIED;
if (isset($httpGetData['hub_lease_seconds'])) {
$data['lease_seconds'] = $httpGetData['hub_lease_seconds'];
}
$this->getStorage()->setSubscription($data);
break;
case 'unsubscribe':
$verifyTokenKey = $this->_detectVerifyTokenKey($httpGetData);
$this->getStorage()->deleteSubscription($verifyTokenKey);
break;
default:
throw new Exception\RuntimeException(sprintf(
'Invalid hub_mode ("%s") provided',
$httpGetData['hub_mode']
));
}
$this->getStorage()->setSubscription($data);
/**
* Hey, C'mon! We tried everything else!
*/
} else {
$this->getHttpResponse()->setStatusCode(404);
}

if ($sendResponseNow) {
$this->sendResponse();
}
Expand Down
14 changes: 3 additions & 11 deletions test/PubSubHubbub/Subscriber/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,9 @@ public function testRespondsToValidConfirmationWith200Response()
->will($this->returnValue(1));

$this->_tableGateway->expects($this->once())
->method('update')
->with(
$this->equalTo(array('id' => 'verifytokenkey',
'verify_token' => hash('sha256', 'cba'),
'created_time' => $t->getTimestamp(),
'lease_seconds' => 1234567,
'subscription_state'=> 'verified',
'expiration_time' => $t->add(new DateInterval('PT1234567S'))
->format('Y-m-d H:i:s'))),
$this->equalTo(array('id' => 'verifytokenkey'))
);
->method('delete')
->with($this->equalTo(array('id' => 'verifytokenkey')))
->will($this->returnValue(true));

$this->_callback->handle($this->_get);
$this->assertTrue($this->_callback->getHttpResponse()->getStatusCode() == 200);
Expand Down
3 changes: 3 additions & 0 deletions test/PubSubHubbub/SubscriberHttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public function testUnsubscriptionRequestSendsExpectedPostData()
.'%3A%2F%2Fwww.example.com%2Ftopic&hub.verify=sync&hub.verify=async'
.'&hub.verify_token=abc',
$this->client->getResponse()->getBody());

$subscriptionRecord = $this->subscriber->getStorage()->getSubscription();
$this->assertEquals($subscriptionRecord['subscription_state'], PubSubHubbub::SUBSCRIPTION_TODELETE);
}

protected function _getCleanMock($className)
Expand Down

0 comments on commit 8abd6e8

Please sign in to comment.