Skip to content

Commit faf7f6a

Browse files
committed
AC-10982::[2FA] Integrate with Duo Web SDK to support Universal Prompt-unit tests fixes
1 parent 0dfdb24 commit faf7f6a

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

TwoFactorAuth/Model/Provider/Engine/DuoSecurity.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ public function getApiHostname(): string
159159
*/
160160
private function getClientSecret(): string
161161
{
162-
return $this->encryptor->decrypt($this->scopeConfig->getValue(static::XML_PATH_CLIENT_SECRET));
162+
// return default value if client secret is not set as per Duo Library
163+
return $this->encryptor->decrypt(
164+
$this->scopeConfig->getValue(static::XML_PATH_CLIENT_SECRET)
165+
) ?: 'abcdefghijklmnopqrstuvwxyz0123456789abcd';
163166
}
164167

165168
/**
@@ -169,7 +172,8 @@ private function getClientSecret(): string
169172
*/
170173
private function getClientId(): string
171174
{
172-
return $this->scopeConfig->getValue(static::XML_PATH_CLIENT_ID);
175+
// return default value if client id is not set as per Duo Library
176+
return $this->scopeConfig->getValue(static::XML_PATH_CLIENT_ID) ?: 'ABCDEFGHIJKLMNOPQRST';
173177
}
174178

175179
/**

TwoFactorAuth/Test/Unit/Model/Provider/Engine/DuoSecurityTest.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,33 +85,38 @@ public static function getIsEnabledTestDataSet(): array
8585
{
8686
return [
8787
[
88-
'value',
89-
'value',
90-
'value',
88+
'test.duosecurity.com',
89+
'ABCDEFGHIJKLMNOPQRST',
90+
'abcdefghijklmnopqrstuvwxyz0123456789abcd',
91+
'0:3:pE7QRAv43bvos7oeve+ULjQ1QCoZw0NMXXtHZtYdmlBR4Nb18IpauosSz1jKFYjo1nPCsOwHk1mOlFpGObrzpSb3zF0=',
9192
true
9293
],
9394
[
9495
null,
9596
null,
9697
null,
98+
null,
9799
false
98100
],
99101
[
100-
'value',
102+
'test.duosecurity.com',
103+
null,
101104
null,
102105
null,
103106
false
104107
],
105108
[
106109
null,
107-
'value',
110+
'ABCDEFGHIJKLMNOPQRST',
111+
null,
108112
null,
109113
false
110114
],
111115
[
112116
null,
113117
null,
114-
'value',
118+
'abcdefghijklmnopqrstuvwxyz0123456789abcd',
119+
'0:3:pE7QRAv43bvos7oeve+ULjQ1QCoZw0NMXXtHZtYdmlBR4Nb18IpauosSz1jKFYjo1nPCsOwHk1mOlFpGObrzpSb3zF0=',
115120
false
116121
]
117122
];
@@ -130,17 +135,24 @@ public static function getIsEnabledTestDataSet(): array
130135
public function testIsEnabled(
131136
?string $apiHostname,
132137
?string $clientId,
133-
?string $clientSecret,
138+
?string $encryptedClientSecret,
139+
?string $decryptedClientSecret,
134140
bool $expected
135141
): void {
136142
$this->configMock->method('getValue')->willReturnMap(
137143
[
138144
[DuoSecurity::XML_PATH_API_HOSTNAME, 'default', null, $apiHostname],
139145
[DuoSecurity::XML_PATH_CLIENT_ID, 'default', null, $clientId],
140-
[DuoSecurity::XML_PATH_CLIENT_SECRET, 'default', null, $clientSecret]
146+
[DuoSecurity::XML_PATH_CLIENT_SECRET, 'default', null, $encryptedClientSecret]
141147
]
142148
);
143149

150+
// Mocking EncryptorInterface
151+
$this->encryptorMock->expects($this->any())
152+
->method('decrypt')
153+
->with($encryptedClientSecret)
154+
->willReturn($decryptedClientSecret);
155+
144156
$this->assertEquals($expected, $this->model->isEnabled());
145157
}
146158

TwoFactorAuth/etc/config.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<api_key backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
2020
</authy>
2121
<duo>
22+
<client_id>ABCDEFGHIJKLMNOPQRST</client_id>
23+
<client_secret backend_model="Magento\Config\Model\Config\Backend\Encrypted">abcdefghijklmnopqrstuvwxyz0123456789abcd</client_secret>
2224
<secret_key backend_model="Magento\Config\Model\Config\Backend\Encrypted"/>
2325
</duo>
2426
<google>

0 commit comments

Comments
 (0)