Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
RestTest Class Reference
Inheritance diagram for RestTest:
WebapiAbstract

Public Member Functions

 testGetRequestTokenInvalidConsumerKey ()
 
 testGetRequestTokenInvalidConsumerSecret ()
 
 testGetAccessToken ()
 
 testGetAccessTokenInvalidVerifier ()
 
 testGetAccessTokenConsumerMismatch ()
 
 testAccessApiInvalidAccessToken ()
 
- Public Member Functions inherited from WebapiAbstract
 addModelToDelete ($model, $secure=false)
 
 processRestExceptionResult (\Exception $e)
 

Static Public Member Functions

static consumerFixture ($date=null)
 
- Static Public Member Functions inherited from WebapiAbstract
static setUpBeforeClass ()
 
static tearDownAfterClass ()
 
static setFixture ($key, $fixture, $tearDown=self::AUTO_TEAR_DOWN_AFTER_METHOD)
 
static getFixture ($key)
 
static callModelDelete ($model, $secure=false)
 
static deleteFixture ($key, $secure=false)
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 
 _getOauthClient ($consumerKey, $consumerSecret)
 
- Protected Member Functions inherited from WebapiAbstract
 tearDown ()
 
 _webApiCall ( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
 
 _markTestAsSoapOnly ($message=null)
 
 _markTestAsRestOnly ($message=null)
 
 _getWebApiAdapter ($webApiAdapterCode)
 
 _assertMessagesEqual ($expectedMessages, $receivedMessages)
 
 _cleanAppConfigCache ()
 
 _restoreAppConfig ()
 
 checkSoapFault ( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)
 
 _checkFaultParams ($expectedErrorParams, $errorDetails)
 
 _checkWrappedErrors ($expectedWrappedErrors, $errorDetails)
 

Protected Attributes

 $_oAuthClients = []
 
- Protected Attributes inherited from WebapiAbstract
 $_appCache
 
 $_modelsToDelete = []
 
 $_origConfigValues = []
 
 $_webApiAdapters
 
 $_webApiAdaptersMap
 

Static Protected Attributes

static $_consumer
 
static $_token
 
static $_consumerKey
 
static $_consumerSecret
 
static $_verifier
 
- Static Protected Attributes inherited from WebapiAbstract
static $_fixturesNamespace
 
static $_fixtures = []
 
static $_methodLevelFixtures = []
 
static $_classLevelFixtures = []
 

Additional Inherited Members

- Data Fields inherited from WebapiAbstract
const AUTO_TEAR_DOWN_DISABLED = 0
 
const AUTO_TEAR_DOWN_AFTER_METHOD = 1
 
const AUTO_TEAR_DOWN_AFTER_CLASS = 2
 
const ADAPTER_SOAP = 'soap'
 
const ADAPTER_REST = 'rest'
 
- Static Protected Member Functions inherited from WebapiAbstract
static _setFixtureNamespace ()
 
static _unsetFixtureNamespace ()
 
static _getFixtureNamespace ()
 
static _deleteFixtures ($fixtures)
 

Detailed Description

@magentoApiDataFixture consumerFixture

Definition at line 13 of file RestTest.php.

Member Function Documentation

◆ _getOauthClient()

_getOauthClient (   $consumerKey,
  $consumerSecret 
)
protected

Definition at line 197 of file RestTest.php.

198  {
199  if (!isset($this->_oAuthClients[$consumerKey])) {
200  $credentials = new \OAuth\Common\Consumer\Credentials($consumerKey, $consumerSecret, TESTS_BASE_URL);
201  $this->_oAuthClients[$consumerKey] = new \Magento\TestFramework\Authentication\Rest\OauthClient(
202  $credentials
203  );
204  }
205  return $this->_oAuthClients[$consumerKey];
206  }

◆ consumerFixture()

static consumerFixture (   $date = null)
static

Create a consumer

Clear the credentials because during the fixture generation, any previous credentials are invalidated

Definition at line 42 of file RestTest.php.

43  {
46 
47  $consumerCredentials = \Magento\TestFramework\Authentication\OauthHelper::getConsumerCredentials($date);
48  self::$_consumerKey = $consumerCredentials['key'];
49  self::$_consumerSecret = $consumerCredentials['secret'];
50  self::$_verifier = $consumerCredentials['verifier'];
51  self::$_consumer = $consumerCredentials['consumer'];
52  self::$_token = $consumerCredentials['token'];
53  }

◆ setUp()

setUp ( )
protected

Definition at line 33 of file RestTest.php.

34  {
35  $this->_markTestAsRestOnly();
36  parent::setUp();
37  }

◆ tearDown()

tearDown ( )
protected

Definition at line 55 of file RestTest.php.

56  {
57  parent::tearDown();
58  $this->_oAuthClients = [];
59  if (isset(self::$_consumer)) {
60  self::$_consumer->delete();
61  self::$_token->delete();
62  }
63  }

◆ testAccessApiInvalidAccessToken()

testAccessApiInvalidAccessToken ( )

@expectedException \Exception @expectedExceptionMessage 400 Bad Request

Definition at line 184 of file RestTest.php.

185  {
186  $oAuthClient = $this->_getOauthClient(self::$_consumerKey, self::$_consumerSecret);
187  $requestToken = $oAuthClient->requestRequestToken();
188  $accessToken = $oAuthClient->requestAccessToken(
189  $requestToken->getRequestToken(),
191  $requestToken->getRequestTokenSecret()
192  );
193  $accessToken->setAccessToken('invalid');
194  $oAuthClient->validateAccessToken($accessToken);
195  }
_getOauthClient($consumerKey, $consumerSecret)
Definition: RestTest.php:197

◆ testGetAccessToken()

testGetAccessToken ( )

Definition at line 120 of file RestTest.php.

121  {
122  $oAuthClient = $this->_getOauthClient(self::$_consumerKey, self::$_consumerSecret);
123  $requestToken = $oAuthClient->requestRequestToken();
124  $accessToken = $oAuthClient->requestAccessToken(
125  $requestToken->getRequestToken(),
127  $requestToken->getRequestTokenSecret()
128  );
129  $this->assertNotEmpty($accessToken->getAccessToken(), "Access token value is not set.");
130  $this->assertNotEmpty($accessToken->getAccessTokenSecret(), "Access token secret is not set.");
131 
132  $this->assertEquals(
133  \Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN,
134  strlen($accessToken->getAccessToken()),
135  "Access token value length should be " . \Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN
136  );
137  $this->assertEquals(
138  \Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN_SECRET,
139  strlen($accessToken->getAccessTokenSecret()),
140  "Access token secret length should be " . \Magento\Framework\Oauth\Helper\Oauth::LENGTH_TOKEN_SECRET
141  );
142  }
_getOauthClient($consumerKey, $consumerSecret)
Definition: RestTest.php:197

◆ testGetAccessTokenConsumerMismatch()

testGetAccessTokenConsumerMismatch ( )

@expectedException \Exception @expectedExceptionMessage 401 Unauthorized

Definition at line 163 of file RestTest.php.

164  {
165  $oAuthClientA = $this->_getOauthClient(self::$_consumerKey, self::$_consumerSecret);
166  $requestTokenA = $oAuthClientA->requestRequestToken();
167  $oauthVerifierA = self::$_verifier;
168 
170  $oAuthClientB = $this->_getOauthClient(self::$_consumerKey, self::$_consumerSecret);
171  $oAuthClientB->requestRequestToken();
172 
173  $oAuthClientB->requestAccessToken(
174  $requestTokenA->getRequestToken(),
175  $oauthVerifierA,
176  $requestTokenA->getRequestTokenSecret()
177  );
178  }
static consumerFixture($date=null)
Definition: RestTest.php:42
_getOauthClient($consumerKey, $consumerSecret)
Definition: RestTest.php:197

◆ testGetAccessTokenInvalidVerifier()

testGetAccessTokenInvalidVerifier ( )

@expectedException \Exception @expectedExceptionMessage 401 Unauthorized

Definition at line 148 of file RestTest.php.

149  {
150  $oAuthClient = $this->_getOauthClient(self::$_consumerKey, self::$_consumerSecret);
151  $requestToken = $oAuthClient->requestRequestToken();
152  $oAuthClient->requestAccessToken(
153  $requestToken->getRequestToken(),
154  'invalid verifier',
155  $requestToken->getRequestTokenSecret()
156  );
157  }
_getOauthClient($consumerKey, $consumerSecret)
Definition: RestTest.php:197

◆ testGetRequestTokenInvalidConsumerKey()

testGetRequestTokenInvalidConsumerKey ( )

@expectedException \Exception @expectedExceptionMessage 401 Unauthorized

Definition at line 104 of file RestTest.php.

105  {
106  $oAuthClient = $this->_getOauthClient('invalid_key', self::$_consumerSecret);
107  $oAuthClient->requestRequestToken();
108  }
_getOauthClient($consumerKey, $consumerSecret)
Definition: RestTest.php:197

◆ testGetRequestTokenInvalidConsumerSecret()

testGetRequestTokenInvalidConsumerSecret ( )

@expectedException \Exception @expectedExceptionMessage 401 Unauthorized

Definition at line 114 of file RestTest.php.

115  {
116  $oAuthClient = $this->_getOauthClient(self::$_consumerKey, 'invalid_secret');
117  $oAuthClient->requestRequestToken();
118  }
_getOauthClient($consumerKey, $consumerSecret)
Definition: RestTest.php:197

Field Documentation

◆ $_consumer

$_consumer
staticprotected

Definition at line 19 of file RestTest.php.

◆ $_consumerKey

$_consumerKey
staticprotected

Definition at line 25 of file RestTest.php.

◆ $_consumerSecret

$_consumerSecret
staticprotected

Definition at line 28 of file RestTest.php.

◆ $_oAuthClients

$_oAuthClients = []
protected

Definition at line 16 of file RestTest.php.

◆ $_token

$_token
staticprotected

Definition at line 22 of file RestTest.php.

◆ $_verifier

$_verifier
staticprotected

Definition at line 31 of file RestTest.php.


The documentation for this class was generated from the following file: