Permalink
Browse files

Merge branch 'hotfix/3295'

Close #3295
  • Loading branch information...
2 parents d6bd296 + ccb9df6 commit e6d08c8d1855aa9d88897ace36bdfc194d4bfe6a @weierophinney weierophinney committed Jan 14, 2013
@@ -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);
@@ -11,6 +11,7 @@
namespace Zend\Feed\PubSubHubbub\Subscriber;
use Zend\Feed\PubSubHubbub;
+use Zend\Feed\PubSubHubbub\Exception;
use Zend\Uri;
/**
@@ -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();
}
@@ -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);
@@ -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)

0 comments on commit e6d08c8

Please sign in to comment.