Lines
88.88%
8 / 9
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| FakeGoogleIdTokenVerifier | 88.88% | 8 / 9 | 50.00% | 1 / 2 | 5.03 | 0.00% | 0 / 1 | |||
| token | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 2 | |||||
| verify | 87.50% | 7 / 8 | 0.00% | 0 / 1 | 3.02 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace App\Security; | |
| 6 | ||
| 7 | /** | |
| 8 | * Fake Google ID token verification for the test env (and opt-in in dev, see DevGoogleIdTokenVerifier). | |
| 9 | * | |
| 10 | * Accepts tokens built with {@see self::token()}; anything else is invalid. | |
| 11 | */ | |
| 12 | final class FakeGoogleIdTokenVerifier implements GoogleIdTokenVerifierInterface | |
| 13 | { | |
| 14 | public static function token(string $googleId, string $email, bool $emailVerified = true): string | |
| 15 | { | |
| 16 | return \implode('|', ['fake', $googleId, $email, $emailVerified ? 'verified' : 'unverified']); | |
| 17 | } | |
| 18 | ||
| 19 | #[\Override] | |
| 20 | public function verify(string $idToken): ?array | |
| 21 | { | |
| 22 | $parts = \explode('|', $idToken); | |
| 23 | ||
| 24 | if (4 !== \count($parts) || 'fake' !== $parts[0]) { | |
| 25 | return null; | |
| 26 | } | |
| 27 | ||
| 28 | return [ | |
| 29 | 'sub' => $parts[1], | |
| 30 | 'email' => $parts[2], | |
| 31 | 'email_verified' => 'verified' === $parts[3], | |
| 32 | ]; | |
| 33 | } | |
| 34 | } |