|
7 | 7 | use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface;
|
8 | 8 | use Scheb\TwoFactorBundle\Security\Authorization\Voter\TwoFactorInProgressVoter;
|
9 | 9 | use Scheb\TwoFactorBundle\Tests\TestCase;
|
| 10 | +use Symfony\Component\HttpFoundation\Request; |
10 | 11 | use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
11 | 12 | use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
|
12 | 13 | use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
| 14 | +use Symfony\Component\Security\Core\User\UserInterface; |
13 | 15 |
|
14 | 16 | class TwoFactorInProgressVoterTest extends TestCase
|
15 | 17 | {
|
@@ -58,4 +60,58 @@ public static function provideAttributeAndExpectedResult(): array
|
58 | 60 | [TwoFactorInProgressVoter::IS_AUTHENTICATED_2FA_IN_PROGRESS, VoterInterface::ACCESS_GRANTED],
|
59 | 61 | ];
|
60 | 62 | }
|
| 63 | + |
| 64 | + /** |
| 65 | + * @test |
| 66 | + * @dataProvider provideTypesForSupportCheck |
| 67 | + */ |
| 68 | + public function supports_type(string $checkType, bool $expectedResult): void |
| 69 | + { |
| 70 | + $returnValue = $this->voter->supportsType($checkType); |
| 71 | + $this->assertEquals($expectedResult, $returnValue); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @return array<array<mixed>> |
| 76 | + */ |
| 77 | + public static function provideTypesForSupportCheck(): array |
| 78 | + { |
| 79 | + return [ |
| 80 | + [UserInterface::class, true], |
| 81 | + ['any', true], |
| 82 | + ['int', true], |
| 83 | + ['array', true], |
| 84 | + ['string', true], |
| 85 | + ['null', true], |
| 86 | + [Request::class, true], |
| 87 | + ]; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * @test |
| 92 | + * @dataProvider provideAttributesForSupportCheck |
| 93 | + */ |
| 94 | + public function supports_attribute(string $attribute, int $expectedResult): void |
| 95 | + { |
| 96 | + $returnValue = $this->voter->supportsAttribute($attribute); |
| 97 | + $this->assertEquals(VoterInterface::ACCESS_GRANTED === $expectedResult, $returnValue); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Copied from provideAttributeAndExpectedResult() but removed null. |
| 102 | + * |
| 103 | + * @return array<array<mixed>> |
| 104 | + */ |
| 105 | + public static function provideAttributesForSupportCheck(): array |
| 106 | + { |
| 107 | + return [ |
| 108 | + ['any', VoterInterface::ACCESS_ABSTAIN], |
| 109 | + [AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED, VoterInterface::ACCESS_ABSTAIN], |
| 110 | + [AuthenticatedVoter::IS_AUTHENTICATED_FULLY, VoterInterface::ACCESS_ABSTAIN], |
| 111 | + |
| 112 | + // Granted |
| 113 | + [AuthenticatedVoter::PUBLIC_ACCESS, VoterInterface::ACCESS_GRANTED], |
| 114 | + [TwoFactorInProgressVoter::IS_AUTHENTICATED_2FA_IN_PROGRESS, VoterInterface::ACCESS_GRANTED], |
| 115 | + ]; |
| 116 | + } |
61 | 117 | }
|
0 commit comments