Skip to content

Commit 27b6e58

Browse files
committed
Merge branch '30820' of github.com:ProkopovVitaliy/magento2 into 2.4-develop-prs
2 parents 4b0cf77 + a0bd182 commit 27b6e58

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

app/code/Magento/Integration/etc/webapi.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@
1919
<resource ref="anonymous"/>
2020
</resources>
2121
</route>
22+
<route url="/V1/integration/customer/revoke-customer-token" method="POST">
23+
<service class="Magento\Integration\Api\CustomerTokenServiceInterface" method="revokeCustomerAccessToken"/>
24+
<resources>
25+
<resource ref="self"/>
26+
</resources>
27+
<data>
28+
<parameter name="customerId" force="true">%customer_id%</parameter>
29+
</data>
30+
</route>
2231
</routes>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Customer\Api;
10+
11+
use Exception;
12+
use Magento\Framework\Exception\AuthenticationException;
13+
use Magento\Framework\Webapi\Rest\Request;
14+
use Magento\Integration\Api\CustomerTokenServiceInterface;
15+
use Magento\TestFramework\ObjectManager;
16+
use Magento\TestFramework\TestCase\WebapiAbstract;
17+
18+
/**
19+
* Test class for Magento\Integration\Api\CustomerTokenServiceInterface
20+
*/
21+
class AccountManagementRevokeCustomerTokenTest extends WebapiAbstract
22+
{
23+
const RESOURCE_PATH = '/V1/integration/customer/revoke-customer-token';
24+
const INTEGRATION_SERVICE = 'integrationCustomerTokenServiceV1';
25+
const SERVICE_VERSION = 'V1';
26+
27+
/**
28+
* Test token revoking for authenticated customer
29+
*
30+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
31+
*/
32+
public function testRevokeCustomerToken(): void
33+
{
34+
$token = $this->getCustomerToken();
35+
$serviceInfo = [
36+
'rest' => [
37+
'resourcePath' => self::RESOURCE_PATH,
38+
'httpMethod' => Request::HTTP_METHOD_POST,
39+
'token' => $token,
40+
],
41+
'soap' => [
42+
'service' => self::INTEGRATION_SERVICE,
43+
'serviceVersion' => self::SERVICE_VERSION,
44+
'operation' => self::INTEGRATION_SERVICE . 'RevokeCustomerAccessToken',
45+
'token' => $token,
46+
]
47+
];
48+
49+
$requestData = [];
50+
if (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) {
51+
$requestData['customerId'] = 0;
52+
}
53+
54+
$this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
55+
}
56+
57+
/**
58+
* @return string
59+
*
60+
* @throws AuthenticationException
61+
*/
62+
private function getCustomerToken(): string
63+
{
64+
$userName = '[email protected]';
65+
$password = 'password';
66+
67+
/** @var CustomerTokenServiceInterface $customerTokenService */
68+
$customerTokenService = ObjectManager::getInstance()->get(CustomerTokenServiceInterface::class);
69+
70+
return $customerTokenService->createCustomerAccessToken($userName, $password);
71+
}
72+
73+
/**
74+
* Test token revoking for guest customer
75+
*/
76+
public function testRevokeCustomerTokenForGuestCustomer(): void
77+
{
78+
$this->expectException(Exception::class);
79+
$requestData = [];
80+
81+
if (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) {
82+
$requestData['customerId'] = 0;
83+
}
84+
85+
$serviceInfo = [
86+
'rest' => [
87+
'resourcePath' => self::RESOURCE_PATH,
88+
'httpMethod' => Request::HTTP_METHOD_POST,
89+
],
90+
'soap' => [
91+
'service' => self::INTEGRATION_SERVICE,
92+
'serviceVersion' => self::SERVICE_VERSION,
93+
'operation' => self::INTEGRATION_SERVICE . 'RevokeCustomerAccessToken',
94+
]
95+
];
96+
97+
$this->_webApiCall($serviceInfo, $requestData);
98+
}
99+
}

0 commit comments

Comments
 (0)