1515use Symfony \Component \Security \Core \Authorization \AccessDecisionManagerInterface ;
1616use Symfony \Component \Security \Core \Authorization \Voter \AuthenticatedVoter ;
1717use Symfony \Component \Security \Http \AccessMapInterface ;
18- use Symfony \Component \Security \Http \HttpUtils ;
19- use Symfony \Component \Security \Http \Logout \LogoutUrlGenerator ;
2018use function defined ;
2119
2220class TwoFactorAccessDeciderTest extends TestCase
2321{
24- private const BASE_URL = '/app_dev.php ' ;
25- private const LOGOUT_PATH = '/logout ' ;
26- private const LOGOUT_PATH_WITH_BASE_URL = self ::BASE_URL .self ::LOGOUT_PATH ;
2722 private const ACCESS_MAP_ATTRIBUTES = [TwoFactorInProgressVoter::IS_AUTHENTICATED_2FA_IN_PROGRESS ];
2823
2924 private MockObject |Request $ request ;
3025 private MockObject |TokenInterface $ token ;
3126 private MockObject |AccessMapInterface $ accessMap ;
3227 private MockObject |AccessDecisionManagerInterface $ accessDecisionManager ;
33- private MockObject |HttpUtils $ httpUtils ;
34- private MockObject |LogoutUrlGenerator $ logoutUrlGenerator ;
3528 private TwoFactorAccessDecider $ accessDecider ;
3629
3730 /** @var string[]|null */
@@ -43,9 +36,7 @@ protected function setUp(): void
4336 $ this ->token = $ this ->createMock (TokenInterface::class);
4437 $ this ->accessMap = $ this ->createMock (AccessMapInterface::class);
4538 $ this ->accessDecisionManager = $ this ->createMock (AccessDecisionManagerInterface::class);
46- $ this ->httpUtils = $ this ->createMock (HttpUtils::class);
47- $ this ->logoutUrlGenerator = $ this ->createMock (LogoutUrlGenerator::class);
48- $ this ->accessDecider = new TwoFactorAccessDecider ($ this ->accessMap , $ this ->accessDecisionManager , $ this ->httpUtils , $ this ->logoutUrlGenerator );
39+ $ this ->accessDecider = new TwoFactorAccessDecider ($ this ->accessMap , $ this ->accessDecisionManager );
4940 }
5041
5142 private function stubAccessMapReturnsAttributes (array |null $ attributes ): void
@@ -58,14 +49,6 @@ private function stubAccessMapReturnsAttributes(array|null $attributes): void
5849 ->willReturn ([$ attributes , 'https ' ]);
5950 }
6051
61- private function whenGeneratedLogoutPath (string $ generatedLogoutPath ): void
62- {
63- $ this ->logoutUrlGenerator
64- ->expects ($ this ->any ())
65- ->method ('getLogoutPath ' )
66- ->willReturn ($ generatedLogoutPath );
67- }
68-
6952 private function whenRequestBaseUrl (string $ baseUrl ): void
7053 {
7154 $ this ->request
@@ -83,15 +66,6 @@ private function whenPathAccess(bool $accessGranted): void
8366 ->willReturn ($ accessGranted );
8467 }
8568
86- private function whenIsLogoutPath (bool $ accessGranted ): void
87- {
88- $ this ->httpUtils
89- ->expects ($ this ->any ())
90- ->method ('checkRequestPath ' )
91- ->with ($ this ->request , self ::LOGOUT_PATH )
92- ->willReturn ($ accessGranted );
93- }
94-
9569 /**
9670 * @return iterable<string>
9771 */
@@ -134,7 +108,6 @@ public function isAccessible_pathAccessGranted_returnTrue(): void
134108 {
135109 $ this ->stubAccessMapReturnsAttributes (self ::ACCESS_MAP_ATTRIBUTES );
136110 $ this ->whenPathAccess (true );
137- $ this ->whenIsLogoutPath (false );
138111
139112 $ returnValue = $ this ->accessDecider ->isAccessible ($ this ->request , $ this ->token );
140113 $ this ->assertTrue ($ returnValue );
@@ -146,35 +119,7 @@ public function isAccessible_isPubliclyAccessible_returnTrue(string $publicAcces
146119 {
147120 $ this ->stubAccessMapReturnsAttributes ([$ publicAccessAttribute ]);
148121 $ this ->whenRequestBaseUrl ('' );
149- $ this ->whenGeneratedLogoutPath (self ::LOGOUT_PATH );
150- $ this ->whenPathAccess (false );
151- $ this ->whenIsLogoutPath (false );
152-
153- $ returnValue = $ this ->accessDecider ->isAccessible ($ this ->request , $ this ->token );
154- $ this ->assertTrue ($ returnValue );
155- }
156-
157- #[Test]
158- public function isAccessible_isLogoutPathNoBasePath_returnTrue (): void
159- {
160- $ this ->stubAccessMapReturnsAttributes (self ::ACCESS_MAP_ATTRIBUTES );
161- $ this ->whenRequestBaseUrl ('' );
162- $ this ->whenGeneratedLogoutPath (self ::LOGOUT_PATH );
163- $ this ->whenPathAccess (false );
164- $ this ->whenIsLogoutPath (true );
165-
166- $ returnValue = $ this ->accessDecider ->isAccessible ($ this ->request , $ this ->token );
167- $ this ->assertTrue ($ returnValue );
168- }
169-
170- #[Test]
171- public function isAccessible_isLogoutPathWithBasePath_returnTrue (): void
172- {
173- $ this ->stubAccessMapReturnsAttributes (self ::ACCESS_MAP_ATTRIBUTES );
174- $ this ->whenRequestBaseUrl (self ::BASE_URL );
175- $ this ->whenGeneratedLogoutPath (self ::LOGOUT_PATH_WITH_BASE_URL );
176122 $ this ->whenPathAccess (false );
177- $ this ->whenIsLogoutPath (true );
178123
179124 $ returnValue = $ this ->accessDecider ->isAccessible ($ this ->request , $ this ->token );
180125 $ this ->assertTrue ($ returnValue );
@@ -185,9 +130,7 @@ public function isAccessible_isNotAccessible_returnFalse(): void
185130 {
186131 $ this ->stubAccessMapReturnsAttributes (self ::ACCESS_MAP_ATTRIBUTES );
187132 $ this ->whenRequestBaseUrl ('' );
188- $ this ->whenGeneratedLogoutPath (self ::LOGOUT_PATH );
189133 $ this ->whenPathAccess (false );
190- $ this ->whenIsLogoutPath (false );
191134
192135 $ returnValue = $ this ->accessDecider ->isAccessible ($ this ->request , $ this ->token );
193136 $ this ->assertFalse ($ returnValue );
0 commit comments