Skip to content

Commit cbdb3dd

Browse files
authored
Merge pull request #441 from magento-performance/CABPI-390
CABPI-390: Do not allow to enable AdminAdobeIms when 2FA is disabled on IMS
2 parents 0e0022a + 3d8679f commit cbdb3dd

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

app/code/Magento/AdminAdobeIms/Console/Command/AdminAdobeImsEnableCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
160160
self::TWO_FACTOR_AUTH_ARGUMENT
161161
);
162162

163-
if ($clientId && $clientSecret && $organizationId) {
163+
if ($clientId && $clientSecret && $organizationId && $isTwoFactorAuthEnabled) {
164164
$enabled = $this->enableModule($clientId, $clientSecret, $organizationId, $isTwoFactorAuthEnabled);
165165
if ($enabled) {
166166
$output->writeln(__('Admin Adobe IMS integration is enabled'));
@@ -169,7 +169,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
169169
}
170170

171171
throw new LocalizedException(
172-
__('The Client ID, Client Secret and Organization ID are required ' .
172+
__('The Client ID, Client Secret, Organization ID and 2FA Auth are required ' .
173173
'when enabling the Admin Adobe IMS Module')
174174
);
175175
} catch (\Exception $e) {
@@ -189,6 +189,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
189189
* @param string $organizationId
190190
* @param bool $isTwoFactorAuthEnabled
191191
* @return bool
192+
* @throws LocalizedException
192193
* @throws InvalidArgumentException
193194
*/
194195
private function enableModule(

app/code/Magento/AdminAdobeIms/Service/ImsConfig.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\App\Config\Storage\WriterInterface;
1717
use Magento\Framework\App\Config\ScopeConfigInterface;
1818
use Magento\Framework\Encryption\EncryptorInterface;
19+
use Magento\Framework\Exception\LocalizedException;
1920
use Magento\Framework\UrlInterface;
2021

2122
class ImsConfig extends Config
@@ -30,7 +31,6 @@ class ImsConfig extends Config
3031
public const XML_PATH_VALIDATE_TOKEN_URL = 'adobe_ims/integration/validate_token_url';
3132
public const XML_PATH_LOGOUT_URL = 'adobe_ims/integration/logout_url';
3233
public const XML_PATH_CERTIFICATE_PATH = 'adobe_ims/integration/certificate_path';
33-
public const XML_PATH_ADOBE_IMS_2FA_ENABLED = 'adobe_ims/integration/adobe_ims_2fa_enabled';
3434
public const XML_PATH_ADMIN_AUTH_URL_PATTERN = 'adobe_ims/integration/admin/auth_url_pattern';
3535
public const XML_PATH_ADMIN_REAUTH_URL_PATTERN = 'adobe_ims/integration/admin/reauth_url_pattern';
3636
public const XML_PATH_ADMIN_ADOBE_IMS_SCOPES = 'adobe_ims/integration/admin/scopes';
@@ -110,13 +110,20 @@ public function loggingEnabled(): bool
110110
* @param string $organizationId
111111
* @param bool $isAdobeIms2FAEnabled
112112
* @return void
113+
* @throws LocalizedException
113114
*/
114115
public function enableModule(
115116
string $clientId,
116117
string $clientSecret,
117118
string $organizationId,
118119
bool $isAdobeIms2FAEnabled
119120
): void {
121+
if (!$isAdobeIms2FAEnabled) {
122+
throw new LocalizedException(
123+
__('2FA Auth is required when enabling the Admin Adobe IMS Module')
124+
);
125+
}
126+
120127
$this->updateConfig(
121128
self::XML_PATH_ENABLED,
122129
'1'
@@ -136,11 +143,6 @@ public function enableModule(
136143
self::XML_PATH_PRIVATE_KEY,
137144
$clientSecret
138145
);
139-
140-
$this->updateConfig(
141-
self::XML_PATH_ADOBE_IMS_2FA_ENABLED,
142-
(string) $isAdobeIms2FAEnabled
143-
);
144146
}
145147

146148
/**
@@ -158,7 +160,6 @@ public function disableModule(): void
158160
$this->deleteConfig(self::XML_PATH_ORGANIZATION_ID);
159161
$this->deleteConfig(self::XML_PATH_API_KEY);
160162
$this->deleteConfig(self::XML_PATH_PRIVATE_KEY);
161-
$this->deleteConfig(self::XML_PATH_ADOBE_IMS_2FA_ENABLED);
162163
}
163164

164165
/**
@@ -198,7 +199,7 @@ public function getValidateTokenUrl(string $code, string $tokenType): string
198199
* @param string $value
199200
* @return void
200201
*/
201-
public function updateConfig(string $path, string $value): void
202+
private function updateConfig(string $path, string $value): void
202203
{
203204
$this->writer->save(
204205
$path,
@@ -213,7 +214,7 @@ public function updateConfig(string $path, string $value): void
213214
* @param string $value
214215
* @return void
215216
*/
216-
public function updateSecureConfig(string $path, string $value): void
217+
private function updateSecureConfig(string $path, string $value): void
217218
{
218219
$value = str_replace(['\n', '\r'], ["\n", "\r"], $value);
219220

@@ -233,7 +234,7 @@ public function updateSecureConfig(string $path, string $value): void
233234
* @param string $path
234235
* @return void
235236
*/
236-
public function deleteConfig(string $path): void
237+
private function deleteConfig(string $path): void
237238
{
238239
$this->writer->delete($path);
239240
}
@@ -286,7 +287,7 @@ public function getAdminAdobeImsReAuthUrl(): string
286287
*
287288
* @return string
288289
*/
289-
public function getScopes(): string
290+
private function getScopes(): string
290291
{
291292
return implode(
292293
',',

app/code/Magento/AdminAdobeIms/Test/Unit/Command/AdminAdobeImsEnableCommandTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ protected function setUp(): void
102102
* @param InvokedCountMatcher$enableMethodCallExpection
103103
* @param InvokedCountMatcher $cleanMethodCallExpection
104104
* @param string $outputMessage
105+
* @param bool $isTwoFactorAuthEnabled
105106
* @return void
106107
* @throws Exception
107108
* @dataProvider cliCommandProvider
@@ -110,7 +111,8 @@ public function testAdminAdobeImsModuleEnableWillClearCacheWhenSuccessful(
110111
bool $testAuthMode,
111112
InvokedCountMatcher $enableMethodCallExpection,
112113
InvokedCountMatcher $cleanMethodCallExpection,
113-
string $outputMessage
114+
string $outputMessage,
115+
bool $isTwoFactorAuthEnabled
114116
): void {
115117
$inputMock = $this->getMockBuilder(InputInterface::class)
116118
->getMockForAbstractClass();
@@ -123,6 +125,7 @@ public function testAdminAdobeImsModuleEnableWillClearCacheWhenSuccessful(
123125
$this->imsCommandOptionService->method('getOrganizationId')->willReturn('orgId');
124126
$this->imsCommandOptionService->method('getClientId')->willReturn('clientId');
125127
$this->imsCommandOptionService->method('getClientSecret')->willReturn('clientSecret');
128+
$this->imsCommandOptionService->method('isTwoFactorAuthEnabled')->willReturn($isTwoFactorAuthEnabled);
126129

127130
$this->imsConnectionMock->method('testAuth')
128131
->willReturn($testAuthMode);
@@ -161,15 +164,33 @@ public function cliCommandProvider(): array
161164
true,
162165
$this->once(),
163166
$this->once(),
164-
'Admin Adobe IMS integration is enabled'
167+
'Admin Adobe IMS integration is enabled',
168+
true
165169
],
166170
[
167171
false,
168172
$this->never(),
169173
$this->never(),
170-
'<error>The Client ID, Client Secret and Organization ID are required ' .
171-
'when enabling the Admin Adobe IMS Module</error>'
174+
'<error>The Client ID, Client Secret, Organization ID and 2FA Auth are required ' .
175+
'when enabling the Admin Adobe IMS Module</error>',
176+
true
172177
],
178+
[
179+
true,
180+
$this->never(),
181+
$this->never(),
182+
'<error>The Client ID, Client Secret, Organization ID and 2FA Auth are required ' .
183+
'when enabling the Admin Adobe IMS Module</error>',
184+
false
185+
],
186+
[
187+
false,
188+
$this->never(),
189+
$this->never(),
190+
'<error>The Client ID, Client Secret, Organization ID and 2FA Auth are required ' .
191+
'when enabling the Admin Adobe IMS Module</error>',
192+
false
193+
]
173194
];
174195
}
175196

0 commit comments

Comments
 (0)