Skip to content

Commit

Permalink
Merge branch '30820' of github.com:ProkopovVitaliy/magento2 into 2.4-…
Browse files Browse the repository at this point in the history
…develop-prs
  • Loading branch information
ishakhsuvarov committed Nov 10, 2022
2 parents 4b0cf77 + a0bd182 commit 27b6e58
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/code/Magento/Integration/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/integration/customer/revoke-customer-token" method="POST">
<service class="Magento\Integration\Api\CustomerTokenServiceInterface" method="revokeCustomerAccessToken"/>
<resources>
<resource ref="self"/>
</resources>
<data>
<parameter name="customerId" force="true">%customer_id%</parameter>
</data>
</route>
</routes>
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);
}
}

0 comments on commit 27b6e58

Please sign in to comment.