/**
  * @expectedException \Magento\Framework\Oauth\Exception
  * @expectedExceptionMessage A consumer having the specified key does not exist
  */
 public function testGetConsumerByKeyNonExistentConsumer()
 {
     $consumerKeyString = '12345678901234567890123456789012';
     $consumerId = null;
     $this->consumerFactoryMock->expects($this->once())->method('create')->willReturn($this->consumerMock);
     $this->consumerMock->expects($this->once())->method('loadByKey')->with($consumerKeyString)->willReturnSelf();
     $this->consumerMock->expects($this->once())->method('getId')->willReturn($consumerId);
     $this->tokenProvider->getConsumerByKey($consumerKeyString);
 }
 /**
  * {@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'));
     }
 }
Beispiel #3
0
 /**
  * Check if token belongs to the same consumer.
  *
  * @param Token $token
  * @param \Magento\Framework\Oauth\ConsumerInterface $consumer
  * @return bool
  */
 protected function _isTokenAssociatedToConsumer($token, $consumer)
 {
     return $token->getConsumerId() == $consumer->getId();
 }