/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage The tokens could not be revoked. */ public function testRevokeCustomerAccessTokenCannotRevoked() { $exception = new \Exception(); $customerId = 1; $this->_tokenModelCollectionMock->expects($this->once())->method('addFilterByCustomerId')->with($customerId)->will($this->returnValue($this->_tokenModelCollectionMock)); $this->_tokenModelCollectionMock->expects($this->once())->method('getSize')->will($this->returnValue(1)); $this->_tokenModelCollectionMock->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->_tokenMock]))); $this->_tokenMock->expects($this->never())->method('save'); $this->_tokenMock->expects($this->once())->method('setRevoked')->will($this->throwException($exception)); $this->_tokenService->revokeCustomerAccessToken($customerId); }
public function testGetAccessSuccess() { $this->_consumerMock->expects($this->any())->method('load')->with(self::VALUE_CONSUMER_ID)->will($this->returnValue($this->_consumerMock)); $this->_tokenMock->expects($this->once())->method('getType')->will($this->returnValue(Token::TYPE_ACCESS)); $this->_tokenProviderMock->expects($this->any())->method('getIntegrationTokenByConsumerId')->will($this->returnValue($this->_tokenMock)); $this->assertEquals($this->_service->getAccessToken(self::VALUE_CONSUMER_ID), $this->_tokenMock); }
public function testPostToConsumer() { $consumerId = 1; $key = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY); $secret = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_SECRET); $oauthVerifier = $this->_generateRandomString(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN_VERIFIER); $consumerData = ['entity_id' => $consumerId, 'key' => $key, 'secret' => $secret]; $this->_consumerMock->expects($this->once())->method('load')->with($this->equalTo($consumerId))->will($this->returnSelf()); $this->_consumerMock->expects($this->once())->method('getId')->will($this->returnValue($consumerId)); $this->_consumerMock->expects($this->once())->method('getData')->will($this->returnValue($consumerData)); $this->_httpClientMock->expects($this->once())->method('setUri')->with('http://www.magento.com')->will($this->returnSelf()); $this->_httpClientMock->expects($this->once())->method('setParameterPost')->will($this->returnSelf()); $this->_tokenMock->expects($this->once())->method('createVerifierToken')->with($consumerId)->will($this->returnSelf()); $this->_tokenMock->expects($this->any())->method('getVerifier')->will($this->returnValue($oauthVerifier)); $this->_dataHelper->expects($this->once())->method('getConsumerPostMaxRedirects')->will($this->returnValue(5)); $this->_dataHelper->expects($this->once())->method('getConsumerPostTimeout')->will($this->returnValue(120)); $verifier = $this->_oauthService->postToConsumer($consumerId, 'http://www.magento.com'); $this->assertEquals($oauthVerifier, $verifier, 'Checking Oauth Verifier'); }
protected function _setupToken($doesExist = true, $type = \Magento\Integration\Model\Oauth\Token::TYPE_VERIFIER, $consumerId = self::CONSUMER_ID, $verifier = null, $isRevoked = false) { $this->_tokenMock->expects($this->any())->method('getId')->will($this->returnValue($doesExist ? self::CONSUMER_ID : null)); $verifier = $verifier ?: $this->_oauthVerifier; $this->_tokenMock->expects($this->any())->method('load')->will($this->returnSelf()); $this->_tokenMock->expects($this->any())->method('getType')->will($this->returnValue($type)); $this->_tokenMock->expects($this->any())->method('createRequestToken')->will($this->returnSelf()); $this->_tokenMock->expects($this->any())->method('getToken')->will($this->returnValue($this->_oauthToken)); $this->_tokenMock->expects($this->any())->method('getSecret')->will($this->returnValue($this->_oauthSecret)); $this->_tokenMock->expects($this->any())->method('getConsumerId')->will($this->returnValue($consumerId)); $this->_tokenMock->expects($this->any())->method('getVerifier')->will($this->returnValue($verifier)); $this->_tokenMock->expects($this->any())->method('convertToAccess')->will($this->returnSelf()); $this->_tokenMock->expects($this->any())->method('getRevoked')->will($this->returnValue($isRevoked)); }
/** * @expectedException \Magento\Framework\Oauth\Exception * @expectedExceptionMessage Access token has been revoked */ public function testValidateAccessTokenRevoked() { $accessTokenString = '12345678901234567890123456789012'; $tokenId = 1; $consumerId = 1; $this->accessTokenMock->expects($this->once())->method('load')->with($accessTokenString, 'token')->willReturnSelf(); $this->tokenFactoryMock->expects($this->once())->method('create')->willReturn($this->accessTokenMock); $this->accessTokenMock->expects($this->any())->method('getId')->willReturn($tokenId); $this->accessTokenMock->expects($this->any())->method('getConsumerId')->willReturn($consumerId); $this->consumerFactoryMock->expects($this->any())->method('create')->willReturn($this->consumerMock); $this->consumerMock->expects($this->any())->method('load')->willReturnSelf(); $this->consumerMock->expects($this->any())->method('getId')->willReturn($consumerId); $this->accessTokenMock->expects($this->once())->method('getType')->willReturn(Token::TYPE_ACCESS); $this->accessTokenMock->expects($this->once())->method('getRevoked')->willReturn(1); $this->tokenProvider->validateAccessToken($accessTokenString); }