-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Admin login issue fix. #32099
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
magento-engcom-team
merged 6 commits into
magento:2.4-develop
from
engcom-Foxtrot:admin-login-issue
Apr 26, 2021
Merged
Admin login issue fix. #32099
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dda7a4c
Admin login issue fix.
engcom-Foxtrot e51e5b9
magento/magento2#32100: Admin login issue fix - MFTF coverage.
engcom-Foxtrot 805f580
Merge branch '2.4-develop' into admin-login-issue
engcom-Foxtrot 06d918f
magento/magento2#32100: Admin login issue fix.
engcom-Foxtrot db86583
magento/magento2#32100: Admin login issue fix.
engcom-Foxtrot b3ca755
magento/magento2#32100: Admin login issue fix - unit test coverage.
engcom-Foxtrot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
app/code/Magento/Backend/Test/Mftf/Data/AdminWebConfigData.xml
This file contains hidden or 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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
|
||
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd"> | ||
<entity name="AdminEnableUrlRewritesConfigData"> | ||
<data key="path">web/seo/use_rewrites</data> | ||
<data key="value">1</data> | ||
</entity> | ||
<entity name="AdminDisableUrlRewritesConfigData"> | ||
<data key="path">web/seo/use_rewrites</data> | ||
<data key="value">0</data> | ||
</entity> | ||
</entities> |
35 changes: 35 additions & 0 deletions
35
app/code/Magento/Backend/Test/Mftf/Test/AdminLoginSuccessfulWithRewritesDisabledTest.xml
This file contains hidden or 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,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
|
||
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> | ||
<test name="AdminLoginSuccessfulWithRewritesDisabledTest"> | ||
<annotations> | ||
<features value="Backend"/> | ||
<stories value="Login on the Admin Login page"/> | ||
<title | ||
value="Admin should be able to log into the Magento Admin backend successfully if url rewrites are disabled"/> | ||
<description | ||
value="Admin should be able to log into the Magento Admin backend successfully if url rewrites are disabled"/> | ||
<severity value="CRITICAL"/> | ||
<group value="example"/> | ||
<group value="login"/> | ||
</annotations> | ||
|
||
<before> | ||
<magentoCLI command="config:set {{AdminDisableUrlRewritesConfigData.path}} {{AdminDisableUrlRewritesConfigData.value}}" stepKey="disableUrlRewrites"/> | ||
</before> | ||
<after> | ||
<magentoCLI command="config:set {{AdminEnableUrlRewritesConfigData.path}} {{AdminEnableUrlRewritesConfigData.value}}" stepKey="enableUrlRewrites"/> | ||
</after> | ||
|
||
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> | ||
<actionGroup ref="AssertAdminSuccessLoginActionGroup" stepKey="assertLoggedIn"/> | ||
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdmin"/> | ||
</test> | ||
</tests> |
198 changes: 198 additions & 0 deletions
198
app/code/Magento/Backend/Test/Unit/Controller/Adminhtml/Auth/LoginTest.php
This file contains hidden or 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,198 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Backend\Test\Unit\Controller\Adminhtml\Auth; | ||
|
||
use Laminas\Uri\Http; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Backend\App\Area\FrontNameResolver; | ||
use Magento\Backend\App\BackendAppList; | ||
use Magento\Backend\Controller\Adminhtml\Auth\Login; | ||
use Magento\Backend\Helper\Data; | ||
use Magento\Backend\Model\Auth; | ||
use Magento\Backend\Model\Url; | ||
use Magento\Backend\Model\UrlFactory; | ||
use Magento\Backend\Model\View\Result\Redirect; | ||
use Magento\Framework\App\Cache\StateInterface as CacheState; | ||
use Magento\Framework\App\Cache\TypeListInterface as CacheTypeList; | ||
use Magento\Framework\App\RequestInterface as Request; | ||
use Magento\Framework\App\State; | ||
use Magento\Framework\Controller\Result\RedirectFactory; | ||
use Magento\Framework\Message\ManagerInterface as MessageManager; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; | ||
use Magento\Framework\View\Result\PageFactory; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test for \Magento\Backend\Controller\Adminhtml\Auth\Login. | ||
*/ | ||
class LoginTest extends TestCase | ||
{ | ||
/** | ||
* @var Login | ||
*/ | ||
private $controller; | ||
|
||
/** | ||
* @var Redirect|MockObject | ||
*/ | ||
private $redirectMock; | ||
|
||
/** | ||
* @var Request|MockObject | ||
*/ | ||
private $requestMock; | ||
|
||
/** | ||
* @var Auth|MockObject | ||
*/ | ||
private $authMock; | ||
|
||
/** | ||
* @var Http|MockObject | ||
*/ | ||
private $uriMock; | ||
|
||
/** | ||
* @var PageFactory|MockObject | ||
*/ | ||
private $resultPageFactoryMock; | ||
|
||
/** | ||
* @var BackendAppList|MockObject | ||
*/ | ||
private $backendAppListMock; | ||
|
||
/** | ||
* @var UrlFactory|MockObject | ||
*/ | ||
private $backendUrlFactoryMock; | ||
|
||
/** | ||
* @var Url|MockObject | ||
*/ | ||
private $backendUrlMock; | ||
|
||
/** | ||
* @var FrontNameResolver|MockObject | ||
*/ | ||
private $frontNameResolverMock; | ||
|
||
/** | ||
* @var RedirectFactory|MockObject | ||
*/ | ||
private $resultRedirectFactoryMock; | ||
|
||
/** | ||
* @var Data|MockObject | ||
*/ | ||
private $helperMock; | ||
|
||
protected function setUp(): void | ||
{ | ||
$objectManagerHelper = new ObjectManagerHelper($this); | ||
|
||
$this->helperMock = $this->createMock(Data::class); | ||
$this->requestMock = $this->getMockBuilder(Request::class) | ||
->setMethods(['getUri', 'getRequestUri']) | ||
->getMockForAbstractClass(); | ||
$this->redirectMock = $this->getMockBuilder(Redirect::class) | ||
->disableOriginalConstructor() | ||
->disableOriginalClone() | ||
->getMock(); | ||
$this->resultRedirectFactoryMock = $this->createMock(RedirectFactory::class); | ||
$this->resultPageFactoryMock = $this->createMock(PageFactory::class); | ||
$this->authMock = $this->createMock(Auth::class); | ||
$this->backendAppListMock = $this->createMock(BackendAppList::class); | ||
$this->backendUrlMock = $this->createMock(Url::class); | ||
$this->backendUrlFactoryMock = $this->createMock(UrlFactory::class); | ||
$this->frontNameResolverMock = $this->createMock(FrontNameResolver::class); | ||
$this->uriMock = $this->createMock(Http::class); | ||
|
||
$this->resultRedirectFactoryMock->expects($this->any()) | ||
->method('create') | ||
->willReturn($this->redirectMock); | ||
$this->backendUrlFactoryMock->expects($this->any()) | ||
->method('create') | ||
->willReturn($this->backendUrlMock); | ||
$this->requestMock->expects($this->any()) | ||
->method('getUri') | ||
->willReturn($this->uriMock); | ||
|
||
$contextMock = $this->getMockBuilder(Context::class) | ||
->disableOriginalConstructor() | ||
->disableOriginalClone() | ||
->getMock(); | ||
|
||
$contextMock->expects($this->once()) | ||
->method('getResultFactory') | ||
->willReturn($this->resultRedirectFactoryMock); | ||
$contextMock->expects($this->once()) | ||
->method('getRequest') | ||
->willReturn($this->requestMock); | ||
$contextMock->expects($this->once()) | ||
->method('getHelper') | ||
->willReturn($this->helperMock); | ||
$contextMock->expects($this->once()) | ||
->method('getResultRedirectFactory') | ||
->willReturn($this->resultRedirectFactoryMock); | ||
$contextMock->expects($this->once()) | ||
->method('getAuth') | ||
->willReturn($this->authMock); | ||
|
||
$this->controller = $objectManagerHelper->getObject( | ||
Login::class, | ||
[ | ||
'context' => $contextMock, | ||
'resultPageFactory' => $this->resultPageFactoryMock, | ||
'backendAppList' => $this->backendAppListMock, | ||
'backendUrlFactory' => $this->backendUrlFactoryMock, | ||
'frontNameResolver' => $this->frontNameResolverMock, | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Test for isValidBackendUri method. | ||
* | ||
* @param string $requestUri | ||
* @param string $baseUrl | ||
* @param string $backendFrontName | ||
* @param bool $redirect | ||
* | ||
* @dataProvider isValidBackendUriDataProvider | ||
*/ | ||
public function testIsValidBackendUri(string $requestUri, string $baseUrl, string $backendFrontName, bool $redirect) | ||
{ | ||
$this->uriMock->expects($this->once())->method('isValid')->willReturn(true); | ||
$this->authMock->expects($this->once())->method('isLoggedIn')->willReturn(false); | ||
$this->requestMock->expects($this->once())->method('getRequestUri')->willReturn($requestUri); | ||
$this->backendUrlMock->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl); | ||
$this->frontNameResolverMock->expects($this->once())->method('getFrontName')->willReturn($backendFrontName); | ||
|
||
$this->resultPageFactoryMock->expects($this->exactly($redirect ? 0 : 1))->method('create'); | ||
$this->resultRedirectFactoryMock->expects($this->exactly($redirect ? 1 : 0))->method('create'); | ||
|
||
$this->controller->execute(); | ||
} | ||
|
||
/** | ||
* Data provider for testIsValidBackendUri. | ||
* | ||
* @return array[] | ||
*/ | ||
public function isValidBackendUriDataProvider() | ||
{ | ||
return [ | ||
'Rewrites on, valid url' => ['/index.php/admin', 'http://magento2.local/', 'admin', true], | ||
'Rewrites on, invalid url' => ['/admin', 'http://magento2.local/', 'admin', false], | ||
'Rewrites off, valid url' => ['/index.php/admin', 'http://magento2.local/index.php/', 'admin', false], | ||
'Rewrites off, invalid url' => ['/admin', 'http://magento2.local/index.php/', 'admin', true], | ||
]; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@engcom-Foxtrot
TBH it's better to cover this functionality with some unit or integration test, functional test is good, but there for sure not a single test case. What do you think?