@@ -12,7 +12,7 @@ class TwoFactorAuthenticationTest extends TestCase
1212{
1313 use RefreshDatabase;
1414
15- public function test_two_factor_settings_page_is_displayed ()
15+ public function test_two_factor_settings_page_can_be_rendered ()
1616 {
1717 if (! Features::canManageTwoFactorAuthentication ()) {
1818 $ this ->markTestSkipped ('Two-factor authentication is not enabled. ' );
@@ -34,7 +34,7 @@ public function test_two_factor_settings_page_is_displayed()
3434 );
3535 }
3636
37- public function test_two_factor_settings_page_requires_password_confirmation ()
37+ public function test_two_factor_settings_page_requires_password_confirmation_when_enabled ()
3838 {
3939 if (! Features::canManageTwoFactorAuthentication ()) {
4040 $ this ->markTestSkipped ('Two-factor authentication is not enabled. ' );
@@ -53,7 +53,7 @@ public function test_two_factor_settings_page_requires_password_confirmation()
5353 $ response ->assertRedirect (route ('password.confirm ' ));
5454 }
5555
56- public function test_two_factor_settings_page_does_not_requires_password_confirmation_if_that_feature_is_disabled ()
56+ public function test_two_factor_settings_page_does_not_requires_password_confirmation_when_disabled ()
5757 {
5858 if (! Features::canManageTwoFactorAuthentication ()) {
5959 $ this ->markTestSkipped ('Two-factor authentication is not enabled. ' );
@@ -74,7 +74,7 @@ public function test_two_factor_settings_page_does_not_requires_password_confirm
7474 );
7575 }
7676
77- public function test_two_factor_settings_page_returns_forbidden_when_two_factor_is_disabled ()
77+ public function test_two_factor_settings_page_returns_forbidden_response_when_two_factor_is_disabled ()
7878 {
7979 if (! Features::canManageTwoFactorAuthentication ()) {
8080 $ this ->markTestSkipped ('Two-factor authentication is not enabled. ' );
@@ -89,123 +89,4 @@ public function test_two_factor_settings_page_returns_forbidden_when_two_factor_
8989 ->get (route ('two-factor.show ' ))
9090 ->assertForbidden ();
9191 }
92-
93- public function test_controller_sets_confirming_data_when_enabling_two_factor_with_confirmation ()
94- {
95- if (! Features::canManageTwoFactorAuthentication ()) {
96- $ this ->markTestSkipped ('Two-factor authentication is not enabled. ' );
97- }
98-
99- Features::twoFactorAuthentication ([
100- 'confirm ' => true ,
101- 'confirmPassword ' => false ,
102- ]);
103-
104- $ user = User::factory ()->create ();
105-
106- $ this ->actingAs ($ user )
107- ->withSession (['auth.password_confirmed_at ' => time ()])
108- ->withSession (['two_factor_empty_at ' => time () - 10 ])
109- ->post (route ('two-factor.enable ' ));
110-
111- $ this ->get (route ('two-factor.show ' ))
112- ->assertOk ();
113-
114- $ this ->assertNotNull (session ('two_factor_confirming_at ' ));
115- }
116-
117- public function test_user_can_view_setting_page_when_confirm_disabled ()
118- {
119- if (! Features::canManageTwoFactorAuthentication ()) {
120- $ this ->markTestSkipped ('Two-factor authentication is not enabled. ' );
121- }
122-
123- Features::twoFactorAuthentication ([
124- 'confirm ' => false ,
125- 'confirmPassword ' => false ,
126- ]);
127-
128- $ user = User::factory ()->create ();
129-
130- $ this ->actingAs ($ user )
131- ->get (route ('two-factor.show ' ))
132- ->assertOk ()
133- ->assertInertia (fn (Assert $ page ) => $ page
134- ->component ('settings/two-factor ' )
135- ->where ('requiresConfirmation ' , false )
136- );
137- }
138-
139- public function test_controller_sets_empty_session_data_when_transitioning_to_disabled_state ()
140- {
141- if (! Features::canManageTwoFactorAuthentication ()) {
142- $ this ->markTestSkipped ('Two-factor authentication is not enabled. ' );
143- }
144-
145- Features::twoFactorAuthentication ([
146- 'confirm ' => true ,
147- 'confirmPassword ' => false ,
148- ]);
149-
150- $ user = User::factory ()->create ();
151-
152- $ this ->actingAs ($ user )
153- ->get (route ('two-factor.show ' ))
154- ->assertSessionHas ('two_factor_empty_at ' );
155- }
156-
157- public function test_controller_removes_confirming_session_data_when_cleanup_triggered ()
158- {
159- if (! Features::canManageTwoFactorAuthentication ()) {
160- $ this ->markTestSkipped ('Two-factor authentication is not enabled. ' );
161- }
162-
163- Features::twoFactorAuthentication ([
164- 'confirm ' => true ,
165- 'confirmPassword ' => false ,
166- ]);
167-
168- $ user = User::factory ()->create ();
169-
170- $ user ->forceFill ([
171- 'two_factor_secret ' => encrypt ('test-secret ' ),
172- 'two_factor_recovery_codes ' => encrypt (json_encode (['code1 ' , 'code2 ' ])),
173- ])->save ();
174-
175- $ this ->actingAs ($ user )
176- ->withSession (['two_factor_confirming_at ' => time () - 100 ])
177- ->get (route ('two-factor.show ' ))
178- ->assertSessionMissing ('two_factor_confirming_at ' )
179- ->assertSessionHas ('two_factor_empty_at ' );
180- }
181-
182- public function test_two_factor_authentication_disabled_when_confirmation_abandoned_between_requests ()
183- {
184- if (! Features::canManageTwoFactorAuthentication ()) {
185- $ this ->markTestSkipped ('Two-factor authentication is not enabled. ' );
186- }
187-
188- Features::twoFactorAuthentication ([
189- 'confirm ' => true ,
190- 'confirmPassword ' => false ,
191- ]);
192-
193- $ user = User::factory ()->create ();
194-
195- $ user ->forceFill ([
196- 'two_factor_secret ' => encrypt ('test-secret ' ),
197- 'two_factor_recovery_codes ' => encrypt (json_encode (['code1 ' , 'code2 ' ])),
198- 'two_factor_confirmed_at ' => null ,
199- ])->save ();
200-
201- $ this ->actingAs ($ user )
202- ->withSession (['two_factor_confirming_at ' => time () - 100 ])
203- ->get (route ('two-factor.show ' ));
204-
205- $ this ->assertDatabaseHas ('users ' , [
206- 'id ' => $ user ->id ,
207- 'two_factor_secret ' => null ,
208- 'two_factor_recovery_codes ' => null ,
209- ]);
210- }
21192}
0 commit comments