-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '30820' of github.com:ProkopovVitaliy/magento2 into 2.4-…
…develop-prs
- Loading branch information
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...pi-functional/testsuite/Magento/Customer/Api/AccountManagementRevokeCustomerTokenTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\Api; | ||
|
||
use Exception; | ||
use Magento\Framework\Exception\AuthenticationException; | ||
use Magento\Framework\Webapi\Rest\Request; | ||
use Magento\Integration\Api\CustomerTokenServiceInterface; | ||
use Magento\TestFramework\ObjectManager; | ||
use Magento\TestFramework\TestCase\WebapiAbstract; | ||
|
||
/** | ||
* Test class for Magento\Integration\Api\CustomerTokenServiceInterface | ||
*/ | ||
class AccountManagementRevokeCustomerTokenTest extends WebapiAbstract | ||
{ | ||
const RESOURCE_PATH = '/V1/integration/customer/revoke-customer-token'; | ||
const INTEGRATION_SERVICE = 'integrationCustomerTokenServiceV1'; | ||
const SERVICE_VERSION = 'V1'; | ||
|
||
/** | ||
* Test token revoking for authenticated customer | ||
* | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
*/ | ||
public function testRevokeCustomerToken(): void | ||
{ | ||
$token = $this->getCustomerToken(); | ||
$serviceInfo = [ | ||
'rest' => [ | ||
'resourcePath' => self::RESOURCE_PATH, | ||
'httpMethod' => Request::HTTP_METHOD_POST, | ||
'token' => $token, | ||
], | ||
'soap' => [ | ||
'service' => self::INTEGRATION_SERVICE, | ||
'serviceVersion' => self::SERVICE_VERSION, | ||
'operation' => self::INTEGRATION_SERVICE . 'RevokeCustomerAccessToken', | ||
'token' => $token, | ||
] | ||
]; | ||
|
||
$requestData = []; | ||
if (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) { | ||
$requestData['customerId'] = 0; | ||
} | ||
|
||
$this->assertTrue($this->_webApiCall($serviceInfo, $requestData)); | ||
} | ||
|
||
/** | ||
* @return string | ||
* | ||
* @throws AuthenticationException | ||
*/ | ||
private function getCustomerToken(): string | ||
{ | ||
$userName = 'customer@example.com'; | ||
$password = 'password'; | ||
|
||
/** @var CustomerTokenServiceInterface $customerTokenService */ | ||
$customerTokenService = ObjectManager::getInstance()->get(CustomerTokenServiceInterface::class); | ||
|
||
return $customerTokenService->createCustomerAccessToken($userName, $password); | ||
} | ||
|
||
/** | ||
* Test token revoking for guest customer | ||
*/ | ||
public function testRevokeCustomerTokenForGuestCustomer(): void | ||
{ | ||
$this->expectException(Exception::class); | ||
$requestData = []; | ||
|
||
if (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) { | ||
$requestData['customerId'] = 0; | ||
} | ||
|
||
$serviceInfo = [ | ||
'rest' => [ | ||
'resourcePath' => self::RESOURCE_PATH, | ||
'httpMethod' => Request::HTTP_METHOD_POST, | ||
], | ||
'soap' => [ | ||
'service' => self::INTEGRATION_SERVICE, | ||
'serviceVersion' => self::SERVICE_VERSION, | ||
'operation' => self::INTEGRATION_SERVICE . 'RevokeCustomerAccessToken', | ||
] | ||
]; | ||
|
||
$this->_webApiCall($serviceInfo, $requestData); | ||
} | ||
} |