]> BookStack Code Mirror - bookstack/blobdiff - tests/Auth/MfaVerificationTest.php
Modernize third party services' logos
[bookstack] / tests / Auth / MfaVerificationTest.php
index d007fa49017b108c3f6ed177595b674e9f607bff..ee6f3ecc83143ac52b0780ec2a2bbf76a0a2a3df 100644 (file)
@@ -149,7 +149,7 @@ class MfaVerificationTest extends TestCase
 
         /** @var TestResponse $mfaView */
         $mfaView = $this->followingRedirects()->post('/login', [
-            'email' => $user->email,
+            'email'    => $user->email,
             'password' => 'password',
         ]);
 
@@ -179,7 +179,7 @@ class MfaVerificationTest extends TestCase
 
         /** @var TestResponse $resp */
         $resp = $this->followingRedirects()->post('/login', [
-            'email' => $user->email,
+            'email'    => $user->email,
             'password' => 'password',
         ]);
 
@@ -187,13 +187,17 @@ class MfaVerificationTest extends TestCase
         $resp->assertElementContains('a[href$="/mfa/setup"]', 'Configure');
 
         $this->get('/mfa/backup_codes/generate');
-        $this->followingRedirects()->post('/mfa/backup_codes/confirm');
+        $resp = $this->post('/mfa/backup_codes/confirm');
+        $resp->assertRedirect('/login');
         $this->assertDatabaseHas('mfa_values', [
             'user_id' => $user->id,
         ]);
 
+        $resp = $this->get('/login');
+        $resp->assertSeeText('Multi-factor method configured, Please now login again using the configured method.');
+
         $resp = $this->followingRedirects()->post('/login', [
-            'email' => $user->email,
+            'email'    => $user->email,
             'password' => 'password',
         ]);
         $resp->assertSeeText('Enter one of your remaining backup codes below:');
@@ -223,6 +227,7 @@ class MfaVerificationTest extends TestCase
         $role = $user->roles->first();
         $role->mfa_enforced = true;
         $role->save();
+
         try {
             $loginService->login($user, 'testing');
         } catch (StoppedAuthenticationException $e) {
@@ -234,7 +239,6 @@ class MfaVerificationTest extends TestCase
             $resp = $this->call($method, $path);
             $resp->assertRedirect('/login');
         }
-
     }
 
     /**
@@ -248,7 +252,7 @@ class MfaVerificationTest extends TestCase
         $user->save();
         MfaValue::upsertWithValue($user, MfaValue::METHOD_TOTP, $secret);
         $loginResp = $this->post('/login', [
-            'email' => $user->email,
+            'email'    => $user->email,
             'password' => 'password',
         ]);
 
@@ -258,18 +262,17 @@ class MfaVerificationTest extends TestCase
     /**
      * @return Array<User, string, TestResponse>
      */
-    protected function startBackupCodeLogin($codes = ['kzzu6-1pgll','bzxnf-plygd','bwdsp-ysl51','1vo93-ioy7n','lf7nw-wdyka','xmtrd-oplac']): array
+    protected function startBackupCodeLogin($codes = ['kzzu6-1pgll', 'bzxnf-plygd', 'bwdsp-ysl51', '1vo93-ioy7n', 'lf7nw-wdyka', 'xmtrd-oplac']): array
     {
         $user = $this->getEditor();
         $user->password = Hash::make('password');
         $user->save();
         MfaValue::upsertWithValue($user, MfaValue::METHOD_BACKUP_CODES, json_encode($codes));
         $loginResp = $this->post('/login', [
-            'email' => $user->email,
+            'email'    => $user->email,
             'password' => 'password',
         ]);
 
         return [$user, $codes, $loginResp];
     }
-
-}
\ No newline at end of file
+}