Skip to content

Commit dad4dfb

Browse files
authored
ENGCOM-4654: Fixed inactive admin user token #20772
2 parents 41dad46 + 76bf8db commit dad4dfb

File tree

6 files changed

+51
-61
lines changed

6 files changed

+51
-61
lines changed

app/code/Magento/Integration/Model/AdminTokenService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function __construct(
7272
}
7373

7474
/**
75-
* {@inheritdoc}
75+
* @inheritdoc
7676
*/
7777
public function createAdminAccessToken($username, $password)
7878
{
@@ -110,7 +110,7 @@ public function revokeAdminAccessToken($adminId)
110110
{
111111
$tokenCollection = $this->tokenModelCollectionFactory->create()->addFilterByAdminId($adminId);
112112
if ($tokenCollection->getSize() == 0) {
113-
throw new LocalizedException(__('This user has no tokens.'));
113+
return true;
114114
}
115115
try {
116116
foreach ($tokenCollection as $token) {

app/code/Magento/Integration/Test/Unit/Model/AdminTokenServiceTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
use Magento\Integration\Model\Oauth\Token;
1010

11+
/**
12+
* Test for Magento\Integration\Model\AdminTokenService class.
13+
*/
1114
class AdminTokenServiceTest extends \PHPUnit\Framework\TestCase
1215
{
1316
/** \Magento\Integration\Model\AdminTokenService */
@@ -99,10 +102,6 @@ public function testRevokeAdminAccessToken()
99102
$this->assertTrue($this->_tokenService->revokeAdminAccessToken($adminId));
100103
}
101104

102-
/**
103-
* @expectedException \Magento\Framework\Exception\LocalizedException
104-
* @expectedExceptionMessage This user has no tokens.
105-
*/
106105
public function testRevokeAdminAccessTokenWithoutAdminId()
107106
{
108107
$this->_tokenModelCollectionMock->expects($this->once())

dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertAccessTokensErrorRevokeMessage.php

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\User\Test\Constraint;
8+
9+
use Magento\User\Test\Page\Adminhtml\UserEdit;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
12+
/**
13+
* Assert that success message appears after click on 'Force Sing-In' button.
14+
*/
15+
class AssertAccessTokensSuccessfullyRevoked extends AbstractConstraint
16+
{
17+
/**
18+
* User revoke tokens success message.
19+
*/
20+
const SUCCESS_MESSAGE = 'You have revoked the user\'s tokens.';
21+
22+
/**
23+
* Assert that success message appears after click on 'Force Sing-In' button.
24+
*
25+
* @param UserEdit $userEdit
26+
* @return void
27+
*/
28+
public function processAssert(UserEdit $userEdit): void
29+
{
30+
\PHPUnit\Framework\Assert::assertEquals(
31+
self::SUCCESS_MESSAGE,
32+
$userEdit->getMessagesBlock()->getSuccessMessage()
33+
);
34+
}
35+
36+
/**
37+
* Return string representation of object
38+
*
39+
* @return string
40+
*/
41+
public function toString()
42+
{
43+
return self::SUCCESS_MESSAGE . ' message is present on UserEdit page.';
44+
}
45+
}

dev/tests/functional/tests/app/Magento/User/Test/TestCase/RevokeAllAccessTokensForAdminWithoutTokensTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<testCase name="Magento\User\Test\TestCase\RevokeAllAccessTokensForAdminWithoutTokensTest" summary="Revoke All Access Tokens for Admin without Tokens" ticketId="MAGETWO-29675">
1010
<variation name="RevokeAllAccessTokensForAdminWithoutTokensTestVariation1">
1111
<data name="user/dataset" xsi:type="string">custom_admin</data>
12-
<constraint name="Magento\User\Test\Constraint\AssertAccessTokensErrorRevokeMessage" />
12+
<constraint name="Magento\User\Test\Constraint\AssertAccessTokensSuccessfullyRevoked" />
1313
</variation>
1414
</testCase>
1515
</config>

dev/tests/integration/testsuite/Magento/User/Controller/Adminhtml/User/InvalidateTokenTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ public function testInvalidateTokenNoTokens()
8989
// invalidate token
9090
$this->getRequest()->setParam('user_id', $adminUserId);
9191
$this->dispatch('backend/admin/user/invalidateToken');
92-
$this->assertSessionMessages(
93-
$this->equalTo(['This user has no tokens.']),
94-
MessageInterface::TYPE_ERROR
95-
);
9692
}
9793

9894
public function testInvalidateTokenNoUser()
@@ -110,9 +106,5 @@ public function testInvalidateTokenInvalidUser()
110106
// invalidate token
111107
$this->getRequest()->setParam('user_id', $adminUserId);
112108
$this->dispatch('backend/admin/user/invalidateToken');
113-
$this->assertSessionMessages(
114-
$this->equalTo(['This user has no tokens.']),
115-
MessageInterface::TYPE_ERROR
116-
);
117109
}
118110
}

0 commit comments

Comments
 (0)