|
5 | 5 | namespace Kreait\Firebase\Tests\Integration\Request; |
6 | 6 |
|
7 | 7 | use DateTimeImmutable; |
| 8 | +use Kreait\Firebase\Auth\MfaInfo; |
8 | 9 | use Kreait\Firebase\Contract\Auth; |
9 | 10 | use Kreait\Firebase\Request\CreateUser; |
10 | 11 | use Kreait\Firebase\Request\UpdateUser; |
11 | 12 | use Kreait\Firebase\Tests\IntegrationTestCase; |
| 13 | +use Kreait\Firebase\Util\DT; |
12 | 14 | use PHPUnit\Framework\Attributes\Test; |
13 | 15 |
|
14 | 16 | use function bin2hex; |
@@ -203,4 +205,60 @@ public function timeOfLastPasswordUpdateIsIncluded(): void |
203 | 205 | $this->auth->deleteUser($user->uid); |
204 | 206 | } |
205 | 207 | } |
| 208 | + |
| 209 | + #[Test] |
| 210 | + public function setMultiFactor(): void |
| 211 | + { |
| 212 | + $user = $this->auth->createUser( |
| 213 | + CreateUser::new()->withVerifiedEmail(self::randomEmail(__FUNCTION__)), |
| 214 | + ); |
| 215 | + |
| 216 | + $factor = [ |
| 217 | + 'mfaEnrollmentId' => '85dc3f7b-7bef-45b9-b9e6-0a1c2c656fed', |
| 218 | + 'phoneInfo' => '+31123456789', |
| 219 | + 'displayName' => '', |
| 220 | + 'enrolledAt' => '2025-02-28T15:30:00Z', |
| 221 | + ]; |
| 222 | + |
| 223 | + $enrolledAt = DT::toUTCDateTimeImmutable($factor['enrolledAt']); |
| 224 | + |
| 225 | + try { |
| 226 | + $check = $this->auth->updateUser($user->uid, ['multifactors' => [$factor]]); |
| 227 | + |
| 228 | + $this->assertInstanceOf(MfaInfo::class, $check->mfaInfo); |
| 229 | + $this->assertSame($factor['mfaEnrollmentId'], $check->mfaInfo->mfaEnrollmentId); |
| 230 | + $this->assertSame($factor['phoneInfo'], $check->mfaInfo->phoneInfo); |
| 231 | + $this->assertSame($factor['displayName'], $check->mfaInfo->displayName); |
| 232 | + $this->assertEquals($enrolledAt, $check->mfaInfo->enrolledAt); |
| 233 | + } finally { |
| 234 | + $this->auth->deleteUser($user->uid); |
| 235 | + } |
| 236 | + } |
| 237 | + |
| 238 | + #[Test] |
| 239 | + public function resetMultiFactor(): void |
| 240 | + { |
| 241 | + $user = $this->auth->createUser( |
| 242 | + CreateUser::new()->withVerifiedEmail(self::randomEmail(__FUNCTION__)), |
| 243 | + ); |
| 244 | + |
| 245 | + $factor = [ |
| 246 | + 'mfaEnrollmentId' => '85dc3f7b-7bef-45b9-b9e6-0a1c2c656fed', |
| 247 | + 'phoneInfo' => '+31123456789', |
| 248 | + 'displayName' => '', |
| 249 | + 'enrolledAt' => '2025-02-28T15:30:00Z', |
| 250 | + ]; |
| 251 | + |
| 252 | + try { |
| 253 | + $updatedUser = $this->auth->updateUser($user->uid, ['multifactors' => [$factor]]); |
| 254 | + |
| 255 | + $this->assertInstanceOf(MfaInfo::class, $updatedUser->mfaInfo); |
| 256 | + |
| 257 | + $check = $this->auth->updateUser($user->uid, ['resetmultifactor' => true]); |
| 258 | + |
| 259 | + $this->assertNotInstanceOf(MfaInfo::class, $check->mfaInfo); |
| 260 | + } finally { |
| 261 | + $this->auth->deleteUser($user->uid); |
| 262 | + } |
| 263 | + } |
206 | 264 | } |
0 commit comments