|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* A two factor authentication module that protects both the admin and customer logins |
|
4
|
|
|
* Copyright (C) 2017 Ross Mitchell |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of Rossmitchell/Twofactor. |
|
7
|
|
|
* |
|
8
|
|
|
* Rossmitchell/Twofactor is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU General Public License as published by |
|
10
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
11
|
|
|
* (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace Rossmitchell\Twofactor\Tests\Integration\Admin\EnterCodePage; |
|
23
|
|
|
|
|
24
|
|
|
use Magento\User\Model\User; |
|
25
|
|
|
use Rossmitchell\Twofactor\Tests\Integration\Abstracts\AbstractTestClass; |
|
26
|
|
|
use Rossmitchell\Twofactor\Tests\Integration\FixtureLoader\Traits\AdminUserLoader; |
|
27
|
|
|
use Rossmitchell\Twofactor\Tests\Integration\FixtureLoader\Traits\ConfigurationLoader; |
|
28
|
|
|
|
|
29
|
|
View Code Duplication |
class QRCodeShouldBeGeneratedOnSaveTest extends AbstractTestClass |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
use AdminUserLoader; |
|
32
|
|
|
use ConfigurationLoader; |
|
33
|
|
|
|
|
34
|
|
|
public static function getAdminUserDataPath() |
|
35
|
|
|
{ |
|
36
|
|
|
return __DIR__ . '/../_files/adminUser.php'; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public static function getConfigurationDataPath() |
|
40
|
|
|
{ |
|
41
|
|
|
return __DIR__ . '/../_files/two_factor_enabled.php'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @magentoDbIsolation enabled |
|
46
|
|
|
* @magentoDataFixture loadAdminUsers |
|
47
|
|
|
* @magentoDataFixture loadConfiguration |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testQrCodeOnSave() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->disableSecretKeys(); |
|
52
|
|
|
$this->loginAdmin('two_factor_disabled', 'password123'); |
|
53
|
|
|
$this->setPostParams(1, 'password123'); |
|
54
|
|
|
$this->dispatch('/backend/admin/system_account/save'); |
|
55
|
|
|
/** @var User $user */ |
|
56
|
|
|
$user = $this->createObject(User::class); |
|
57
|
|
|
$user->loadByUsername('two_factor_disabled'); |
|
58
|
|
|
$this->assertNotEmpty($user->getData('two_factor_secret')); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
private function setPostParams($useTwoFactor, $password) |
|
62
|
|
|
{ |
|
63
|
|
|
$adminUser = $this->getAdminSession()->getUser(); |
|
64
|
|
|
|
|
65
|
|
|
$this->getRequest() |
|
66
|
|
|
->setMethod('POST') |
|
67
|
|
|
->setParam('form_key', $this->getFormKey()) |
|
68
|
|
|
->setParam('username', $adminUser->getUserName()) |
|
69
|
|
|
->setParam('firstname', $adminUser->getFirstName()) |
|
70
|
|
|
->setParam('lastname', $adminUser->getLastName()) |
|
71
|
|
|
->setParam('user_id', $adminUser->getId()) |
|
72
|
|
|
->setParam('email', $adminUser->getEmail()) |
|
73
|
|
|
->setParam('password', '') |
|
74
|
|
|
->setParam('password_confirmation', '') |
|
75
|
|
|
->setParam('interface_locale', $adminUser->getInterfaceLocale()) |
|
76
|
|
|
->setParam('use_two_factor', "$useTwoFactor") |
|
77
|
|
|
->setParam('current_password', $password); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.