| @@ 29-79 (lines=51) @@ | ||
| 26 | use Rossmitchell\Twofactor\Tests\Integration\FixtureLoader\Traits\AdminUserLoader; |
|
| 27 | use Rossmitchell\Twofactor\Tests\Integration\FixtureLoader\Traits\ConfigurationLoader; |
|
| 28 | ||
| 29 | 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 | ||
| @@ 29-79 (lines=51) @@ | ||
| 26 | use Rossmitchell\Twofactor\Tests\Integration\FixtureLoader\Traits\AdminUserLoader; |
|
| 27 | use Rossmitchell\Twofactor\Tests\Integration\FixtureLoader\Traits\ConfigurationLoader; |
|
| 28 | ||
| 29 | class QRCodeShouldNotBeGeneratedWhenDisabledTest 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(0, '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->assertEmpty($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 | ||
| @@ 29-79 (lines=51) @@ | ||
| 26 | use Rossmitchell\Twofactor\Tests\Integration\FixtureLoader\Traits\AdminUserLoader; |
|
| 27 | use Rossmitchell\Twofactor\Tests\Integration\FixtureLoader\Traits\ConfigurationLoader; |
|
| 28 | ||
| 29 | class QRCodeShouldNotBeGeneratedWhenTwoFactorDisabledTest 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_disabled.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(0, '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->assertEmpty($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 | ||