Skip to content

Fixed inactive admin user token #20772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/code/Magento/Integration/Model/AdminTokenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function createAdminAccessToken($username, $password)
{
Expand Down Expand Up @@ -110,7 +110,7 @@ public function revokeAdminAccessToken($adminId)
{
$tokenCollection = $this->tokenModelCollectionFactory->create()->addFilterByAdminId($adminId);
if ($tokenCollection->getSize() == 0) {
throw new LocalizedException(__('This user has no tokens.'));
return true;
}
try {
foreach ($tokenCollection as $token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

use Magento\Integration\Model\Oauth\Token;

/**
* Test for Magento\Integration\Model\AdminTokenService class.
*/
class AdminTokenServiceTest extends \PHPUnit\Framework\TestCase
{
/** \Magento\Integration\Model\AdminTokenService */
Expand Down Expand Up @@ -99,10 +102,6 @@ public function testRevokeAdminAccessToken()
$this->assertTrue($this->_tokenService->revokeAdminAccessToken($adminId));
}

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage This user has no tokens.
*/
public function testRevokeAdminAccessTokenWithoutAdminId()
{
$this->_tokenModelCollectionMock->expects($this->once())
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\User\Test\Constraint;

use Magento\User\Test\Page\Adminhtml\UserEdit;
use Magento\Mtf\Constraint\AbstractConstraint;

/**
* Assert that success message appears after click on 'Force Sing-In' button.
*/
class AssertAccessTokensSuccessfullyRevoked extends AbstractConstraint
{
/**
* User revoke tokens success message.
*/
const SUCCESS_MESSAGE = 'You have revoked the user\'s tokens.';

/**
* Assert that success message appears after click on 'Force Sing-In' button.
*
* @param UserEdit $userEdit
* @return void
*/
public function processAssert(UserEdit $userEdit): void
{
\PHPUnit\Framework\Assert::assertEquals(
self::SUCCESS_MESSAGE,
$userEdit->getMessagesBlock()->getSuccessMessage()
);
}

/**
* Return string representation of object
*
* @return string
*/
public function toString()
{
return self::SUCCESS_MESSAGE . ' message is present on UserEdit page.';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<testCase name="Magento\User\Test\TestCase\RevokeAllAccessTokensForAdminWithoutTokensTest" summary="Revoke All Access Tokens for Admin without Tokens" ticketId="MAGETWO-29675">
<variation name="RevokeAllAccessTokensForAdminWithoutTokensTestVariation1">
<data name="user/dataset" xsi:type="string">custom_admin</data>
<constraint name="Magento\User\Test\Constraint\AssertAccessTokensErrorRevokeMessage" />
<constraint name="Magento\User\Test\Constraint\AssertAccessTokensSuccessfullyRevoked" />
</variation>
</testCase>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ public function testInvalidateTokenNoTokens()
// invalidate token
$this->getRequest()->setParam('user_id', $adminUserId);
$this->dispatch('backend/admin/user/invalidateToken');
$this->assertSessionMessages(
$this->equalTo(['This user has no tokens.']),
MessageInterface::TYPE_ERROR
);
}

public function testInvalidateTokenNoUser()
Expand All @@ -110,9 +106,5 @@ public function testInvalidateTokenInvalidUser()
// invalidate token
$this->getRequest()->setParam('user_id', $adminUserId);
$this->dispatch('backend/admin/user/invalidateToken');
$this->assertSessionMessages(
$this->equalTo(['This user has no tokens.']),
MessageInterface::TYPE_ERROR
);
}
}