1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Spryker Commerce OS. |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types = 1); |
9
|
|
|
|
10
|
|
|
namespace PyzTest\Glue\MultiFactorAuth\StorefrontApi; |
11
|
|
|
|
12
|
|
|
use Codeception\Util\HttpCode; |
13
|
|
|
use PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester; |
14
|
|
|
use PyzTest\Glue\MultiFactorAuth\StorefrontApi\Fixtures\MultiFactorAuthStorefrontApiFixtures; |
15
|
|
|
use Spryker\Glue\MultiFactorAuth\MultiFactorAuthConfig; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Auto-generated group annotations |
19
|
|
|
* |
20
|
|
|
* @group PyzTest |
21
|
|
|
* @group Glue |
22
|
|
|
* @group MultiFactorAuth |
23
|
|
|
* @group StorefrontApi |
24
|
|
|
* @group MultiFactorAuthStorefrontApiCest |
25
|
|
|
* Add your own group annotations below this line |
26
|
|
|
*/ |
27
|
|
|
class MultiFactorAuthStorefrontApiCest |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var string|null |
31
|
|
|
*/ |
32
|
|
|
protected ?string $mfaCode = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected const INVALID_MFA_CODE = '000000'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected const INVALID_MFA_TYPE = 'invalid-type'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var \PyzTest\Glue\MultiFactorAuth\StorefrontApi\Fixtures\MultiFactorAuthStorefrontApiFixtures|null |
46
|
|
|
*/ |
47
|
|
|
protected ?MultiFactorAuthStorefrontApiFixtures $fixtures = null; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function loadFixtures(MultiFactorAuthStorefrontApiTester $I): void |
55
|
|
|
{ |
56
|
|
|
/** @var \PyzTest\Glue\MultiFactorAuth\StorefrontApi\Fixtures\MultiFactorAuthStorefrontApiFixtures $fixtures */ |
57
|
|
|
$fixtures = $I->loadFixtures(MultiFactorAuthStorefrontApiFixtures::class); |
58
|
|
|
$this->fixtures = $fixtures; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function requestGetMultiFactorAuthTypes(MultiFactorAuthStorefrontApiTester $I): void |
67
|
|
|
{ |
68
|
|
|
// Arrange |
69
|
|
|
$I->authorizeCustomerToStorefrontApi($this->fixtures->getCustomerTransfer()); |
|
|
|
|
70
|
|
|
|
71
|
|
|
// Act |
72
|
|
|
$I->sendJsonApiGet(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPES); |
73
|
|
|
|
74
|
|
|
// Assert |
75
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::OK); |
76
|
|
|
$I->seeResponseIsJson(); |
77
|
|
|
$I->seeJsonApiResponseDataContainsResourceCollectionOfType(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPES); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
|
|
public function requestActivateMultiFactorAuthType(MultiFactorAuthStorefrontApiTester $I): void |
86
|
|
|
{ |
87
|
|
|
// Arrange |
88
|
|
|
$I->authorizeCustomerToStorefrontApi($this->fixtures->getCustomerTransfer()); |
89
|
|
|
|
90
|
|
|
// Act |
91
|
|
|
$this->activateMultiFactorAuth($I); |
92
|
|
|
|
93
|
|
|
// Assert |
94
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::NO_CONTENT); |
95
|
|
|
|
96
|
|
|
$this->deactivateMultiFactorAuth($I); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
101
|
|
|
* |
102
|
|
|
* @return void |
103
|
|
|
*/ |
104
|
|
|
public function requestActivateMultiFactorAuthTypeWithInvalidType(MultiFactorAuthStorefrontApiTester $I): void |
105
|
|
|
{ |
106
|
|
|
// Arrange |
107
|
|
|
$I->authorizeCustomerToStorefrontApi($this->fixtures->getCustomerTransfer()); |
108
|
|
|
|
109
|
|
|
// Act |
110
|
|
|
$requestPayload = [ |
111
|
|
|
'data' => [ |
112
|
|
|
'type' => MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_ACTIVATE, |
113
|
|
|
'attributes' => [ |
114
|
|
|
'type' => static::INVALID_MFA_TYPE, |
115
|
|
|
], |
116
|
|
|
], |
117
|
|
|
]; |
118
|
|
|
$I->sendJsonApiPost($this->fixtures->generateUrl(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_ACTIVATE), $requestPayload); |
119
|
|
|
|
120
|
|
|
// Assert |
121
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::BAD_REQUEST); |
122
|
|
|
$I->seeResponseIsJson(); |
123
|
|
|
|
124
|
|
|
$this->deactivateMultiFactorAuth($I); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
129
|
|
|
* |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
|
|
public function requestVerifyMultiFactorAuthType(MultiFactorAuthStorefrontApiTester $I): void |
133
|
|
|
{ |
134
|
|
|
// Arrange |
135
|
|
|
$I->authorizeCustomerToStorefrontApi($this->fixtures->getCustomerTransfer()); |
136
|
|
|
|
137
|
|
|
// Act |
138
|
|
|
$this->activateMultiFactorAuth($I); |
139
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::NO_CONTENT); |
140
|
|
|
|
141
|
|
|
$this->verifyMultiFactorAuth($I); |
142
|
|
|
|
143
|
|
|
// Assert |
144
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::NO_CONTENT); |
145
|
|
|
|
146
|
|
|
$this->deactivateMultiFactorAuth($I); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
151
|
|
|
* |
152
|
|
|
* @return void |
153
|
|
|
*/ |
154
|
|
|
public function requestVerifyMultiFactorAuthTypeWithoutActivation(MultiFactorAuthStorefrontApiTester $I): void |
155
|
|
|
{ |
156
|
|
|
// Arrange |
157
|
|
|
$I->authorizeCustomerToStorefrontApi($this->fixtures->getCustomerTransfer()); |
158
|
|
|
|
159
|
|
|
// Act |
160
|
|
|
$this->verifyMultiFactorAuth($I); |
161
|
|
|
|
162
|
|
|
// Assert |
163
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::BAD_REQUEST); |
164
|
|
|
$I->seeResponseIsJson(); |
165
|
|
|
|
166
|
|
|
$this->deactivateMultiFactorAuth($I); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
171
|
|
|
* |
172
|
|
|
* @return void |
173
|
|
|
*/ |
174
|
|
|
public function requestVerifyMultiFactorAuthTypeWithInvalidCode(MultiFactorAuthStorefrontApiTester $I): void |
175
|
|
|
{ |
176
|
|
|
// Arrange |
177
|
|
|
$I->authorizeCustomerToStorefrontApi($this->fixtures->getCustomerTransfer()); |
178
|
|
|
|
179
|
|
|
$this->activateMultiFactorAuth($I); |
180
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::NO_CONTENT); |
181
|
|
|
|
182
|
|
|
// Act |
183
|
|
|
$I->haveHttpHeader(MultiFactorAuthConfig::HEADER_MULTI_FACTOR_AUTH_CODE, static::INVALID_MFA_CODE); |
184
|
|
|
$requestPayload = $this->fixtures->createRequestPayload(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_VERIFY); |
185
|
|
|
$I->sendJsonApiPost($this->fixtures->generateUrl(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_VERIFY), $requestPayload); |
186
|
|
|
|
187
|
|
|
// Assert |
188
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::FORBIDDEN); |
189
|
|
|
$I->seeResponseIsJson(); |
190
|
|
|
|
191
|
|
|
$this->deactivateMultiFactorAuth($I); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
196
|
|
|
* |
197
|
|
|
* @return void |
198
|
|
|
*/ |
199
|
|
|
public function requestDeactivateMultiFactorAuthType(MultiFactorAuthStorefrontApiTester $I): void |
200
|
|
|
{ |
201
|
|
|
// Arrange |
202
|
|
|
$I->authorizeCustomerToStorefrontApi($this->fixtures->getCustomerTransfer()); |
203
|
|
|
|
204
|
|
|
$this->activateMultiFactorAuth($I); |
205
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::NO_CONTENT); |
206
|
|
|
|
207
|
|
|
$this->verifyMultiFactorAuth($I); |
208
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::NO_CONTENT); |
209
|
|
|
|
210
|
|
|
$this->deactivateMultiFactorAuth($I); |
211
|
|
|
|
212
|
|
|
// Assert |
213
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::NO_CONTENT); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
218
|
|
|
* |
219
|
|
|
* @return void |
220
|
|
|
*/ |
221
|
|
|
public function requestDeactivateMultiFactorAuthTypeWithoutActivation(MultiFactorAuthStorefrontApiTester $I): void |
222
|
|
|
{ |
223
|
|
|
// Arrange |
224
|
|
|
$I->authorizeCustomerToStorefrontApi($this->fixtures->getCustomerTransfer()); |
225
|
|
|
|
226
|
|
|
// Act |
227
|
|
|
$this->deactivateMultiFactorAuth($I); |
228
|
|
|
|
229
|
|
|
// Assert |
230
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::BAD_REQUEST); |
231
|
|
|
$I->seeResponseIsJson(); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
236
|
|
|
* |
237
|
|
|
* @return void |
238
|
|
|
*/ |
239
|
|
|
public function requestDeactivateMultiFactorAuthTypeWithInvalidCode(MultiFactorAuthStorefrontApiTester $I): void |
240
|
|
|
{ |
241
|
|
|
// Arrange |
242
|
|
|
$I->authorizeCustomerToStorefrontApi($this->fixtures->getCustomerTransfer()); |
243
|
|
|
|
244
|
|
|
$this->activateMultiFactorAuth($I); |
245
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::NO_CONTENT); |
246
|
|
|
|
247
|
|
|
$this->verifyMultiFactorAuth($I); |
248
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::NO_CONTENT); |
249
|
|
|
|
250
|
|
|
// Act |
251
|
|
|
$I->haveHttpHeader(MultiFactorAuthConfig::HEADER_MULTI_FACTOR_AUTH_CODE, static::INVALID_MFA_CODE); |
252
|
|
|
$requestPayload = $this->fixtures->createRequestPayload(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_DEACTIVATE); |
253
|
|
|
$I->sendJsonApiPost($this->fixtures->generateUrl(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_DEACTIVATE), $requestPayload); |
254
|
|
|
|
255
|
|
|
// Assert |
256
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::FORBIDDEN); |
257
|
|
|
$I->seeResponseIsJson(); |
258
|
|
|
|
259
|
|
|
$this->deactivateMultiFactorAuth($I); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
264
|
|
|
* |
265
|
|
|
* @return void |
266
|
|
|
*/ |
267
|
|
|
public function requestDeactivateMultiFactorAuthTypeWithoutVerification(MultiFactorAuthStorefrontApiTester $I): void |
268
|
|
|
{ |
269
|
|
|
// Arrange |
270
|
|
|
$I->authorizeCustomerToStorefrontApi($this->fixtures->getCustomerTransfer()); |
271
|
|
|
|
272
|
|
|
$this->activateMultiFactorAuth($I); |
273
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::NO_CONTENT); |
274
|
|
|
|
275
|
|
|
// Act |
276
|
|
|
$this->deactivateMultiFactorAuth($I); |
277
|
|
|
|
278
|
|
|
// Assert |
279
|
|
|
$I->seeJsonApiResponseCodeIs(HttpCode::BAD_REQUEST); |
280
|
|
|
$I->seeResponseIsJson(); |
281
|
|
|
|
282
|
|
|
$I->authorizeCustomerToStorefrontApi($this->fixtures->getCustomerTransfer()); |
283
|
|
|
$this->verifyMultiFactorAuth($I); |
284
|
|
|
|
285
|
|
|
$this->deactivateMultiFactorAuth($I); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
290
|
|
|
* |
291
|
|
|
* @return void |
292
|
|
|
*/ |
293
|
|
|
protected function activateMultiFactorAuth(MultiFactorAuthStorefrontApiTester $I): void |
294
|
|
|
{ |
295
|
|
|
$requestPayload = $this->fixtures->createRequestPayload(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_ACTIVATE); |
296
|
|
|
$I->sendJsonApiPost($this->fixtures->generateUrl(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_ACTIVATE), $requestPayload); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
301
|
|
|
* |
302
|
|
|
* @return void |
303
|
|
|
*/ |
304
|
|
|
protected function verifyMultiFactorAuth(MultiFactorAuthStorefrontApiTester $I): void |
305
|
|
|
{ |
306
|
|
|
$this->mfaCode = $I->getCustomerMultiFactorAuthCodeFromDatabase( |
307
|
|
|
$this->fixtures->getCustomerTransfer(), |
308
|
|
|
'email', |
309
|
|
|
); |
310
|
|
|
|
311
|
|
|
$I->comment(sprintf('Using MFA code from database: %s', $this->mfaCode)); |
312
|
|
|
|
313
|
|
|
$requestPayload = $this->fixtures->createRequestPayload(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_VERIFY); |
314
|
|
|
$I->haveHttpHeader(MultiFactorAuthConfig::HEADER_MULTI_FACTOR_AUTH_CODE, $this->mfaCode); |
315
|
|
|
$I->sendJsonApiPost($this->fixtures->generateUrl(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_VERIFY), $requestPayload); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @param \PyzTest\Glue\MultiFactorAuth\MultiFactorAuthStorefrontApiTester $I |
320
|
|
|
* |
321
|
|
|
* @return void |
322
|
|
|
*/ |
323
|
|
|
protected function deactivateMultiFactorAuth(MultiFactorAuthStorefrontApiTester $I): void |
324
|
|
|
{ |
325
|
|
|
if ($this->mfaCode === null) { |
326
|
|
|
$this->mfaCode = $I->getCustomerMultiFactorAuthCodeFromDatabase( |
327
|
|
|
$this->fixtures->getCustomerTransfer(), |
328
|
|
|
'email', |
329
|
|
|
); |
330
|
|
|
$I->comment(sprintf('Using MFA code from database for deactivation: %s', $this->mfaCode)); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
$I->haveHttpHeader(MultiFactorAuthConfig::HEADER_MULTI_FACTOR_AUTH_CODE, $this->mfaCode); |
334
|
|
|
$requestPayload = $this->fixtures->createRequestPayload(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_DEACTIVATE); |
335
|
|
|
$I->sendJsonApiPost($this->fixtures->generateUrl(MultiFactorAuthConfig::RESOURCE_MULTI_FACTOR_AUTH_TYPE_DEACTIVATE), $requestPayload); |
336
|
|
|
} |
337
|
|
|
} |
338
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.