Beispiel #1
0
 protected function _setupNonce($isUsed = false, $timestamp = 0)
 {
     $nonceMock = $this->getMockBuilder('Magento\\Integration\\Model\\Oauth\\Nonce')->disableOriginalConstructor()->setMethods(array('loadByCompositeKey', 'getNonce', 'getTimestamp', 'setNonce', 'setConsumerId', 'setTimestamp', 'save', '__wakeup'))->getMock();
     $nonceMock->expects($this->any())->method('getNonce')->will($this->returnValue($isUsed));
     $nonceMock->expects($this->any())->method('loadByCompositeKey')->will($this->returnSelf());
     $nonceMock->expects($this->any())->method('getTimestamp')->will($this->returnValue($timestamp));
     $nonceMock->expects($this->any())->method('setNonce')->will($this->returnSelf());
     $nonceMock->expects($this->any())->method('setConsumerId')->will($this->returnSelf());
     $nonceMock->expects($this->any())->method('setTimestamp')->will($this->returnSelf());
     $nonceMock->expects($this->any())->method('save')->will($this->returnSelf());
     $this->_nonceFactory->expects($this->any())->method('create')->will($this->returnValue($nonceMock));
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function validateNonce(ConsumerInterface $consumer, $nonce, $timestamp)
 {
     try {
         $timestamp = (int) $timestamp;
         if ($timestamp <= 0 || $timestamp > time() + self::TIME_DEVIATION) {
             throw new \Magento\Framework\Oauth\OauthInputException('Incorrect timestamp value in the oauth_timestamp parameter');
         }
         /** @var \Magento\Integration\Model\Oauth\Nonce $nonceObj */
         $nonceObj = $this->_nonceFactory->create()->loadByCompositeKey($nonce, $consumer->getId());
         if ($nonceObj->getNonce()) {
             throw new \Magento\Framework\Oauth\Exception('The nonce is already being used by the consumer with ID %1', [$consumer->getId()]);
         }
         $nonceObj->setNonce($nonce)->setConsumerId($consumer->getId())->setTimestamp($timestamp)->save();
     } catch (\Magento\Framework\Oauth\Exception $exception) {
         throw $exception;
     } catch (\Exception $exception) {
         throw new \Magento\Framework\Oauth\Exception('An error occurred validating the nonce');
     }
 }