]> BookStack Code Mirror - bookstack/blobdiff - tests/Auth/AuthTest.php
Modernize third party services' logos
[bookstack] / tests / Auth / AuthTest.php
index acf67cb9a60db5216db03d84151c21ab9dbc9ed6..79f00bed093cbd28c0c550820e41e76a0b799133 100644 (file)
@@ -7,7 +7,7 @@ use BookStack\Auth\User;
 use BookStack\Entities\Models\Page;
 use BookStack\Notifications\ConfirmEmail;
 use BookStack\Notifications\ResetPassword;
-use DB;
+use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Notification;
 use Tests\TestCase;
 use Tests\TestResponse;
@@ -77,8 +77,8 @@ class AuthTest extends TestCase
 
         $this->get('/register');
         $resp = $this->followingRedirects()->post('/register', [
-            'name' => '1',
-            'email' => '1',
+            'name'     => '1',
+            'email'    => '1',
             'password' => '1',
         ]);
         $resp->assertSee('The name must be at least 2 characters.');
@@ -241,10 +241,10 @@ class AuthTest extends TestCase
             ->assertSee('Reset Password');
 
         $resp = $this->post('/password/reset', [
-            'email' => '[email protected]',
-            'password' => 'randompass',
+            'email'                 => '[email protected]',
+            'password'              => 'randompass',
             'password_confirmation' => 'randompass',
-            'token' => $n->first()->token
+            'token'                 => $n->first()->token,
         ]);
         $resp->assertRedirect('/');
 
@@ -260,13 +260,12 @@ class AuthTest extends TestCase
         $resp->assertSee('A password reset link will be sent to [email protected] if that email address is found in the system.');
         $resp->assertDontSee('We can\'t find a user');
 
-
         $this->get('/password/reset/arandometokenvalue')->assertSee('Reset Password');
         $resp = $this->post('/password/reset', [
-            'email' => '[email protected]',
-            'password' => 'randompass',
+            'email'                 => '[email protected]',
+            'password'              => 'randompass',
             'password_confirmation' => 'randompass',
-            'token' => 'arandometokenvalue'
+            'token'                 => 'arandometokenvalue',
         ]);
         $resp->assertRedirect('/password/reset/arandometokenvalue');
 
@@ -283,6 +282,22 @@ class AuthTest extends TestCase
             ->assertElementContains('a', 'Sign up');
     }
 
+    public function test_reset_password_request_is_throttled()
+    {
+        $editor = $this->getEditor();
+        Notification::fake();
+        $this->get('/password/email');
+        $this->followingRedirects()->post('/password/email', [
+            'email' => $editor->email,
+        ]);
+
+        $resp = $this->followingRedirects()->post('/password/email', [
+            'email' => $editor->email,
+        ]);
+        Notification::assertTimesSent(1, ResetPassword::class);
+        $resp->assertSee('A password reset link will be sent to ' . $editor->email . ' if that email address is found in the system.');
+    }
+
     public function test_login_redirects_to_initially_requested_url_correctly()
     {
         config()->set('app.url', 'http://localhost');
@@ -319,6 +334,7 @@ class AuthTest extends TestCase
         $this->assertTrue(auth()->check());
         $this->assertTrue(auth('ldap')->check());
         $this->assertTrue(auth('saml2')->check());
+        $this->assertTrue(auth('oidc')->check());
     }
 
     public function test_login_authenticates_nonadmins_on_default_guard_only()
@@ -331,6 +347,7 @@ class AuthTest extends TestCase
         $this->assertTrue(auth()->check());
         $this->assertFalse(auth('ldap')->check());
         $this->assertFalse(auth('saml2')->check());
+        $this->assertFalse(auth('oidc')->check());
     }
 
     public function test_failed_logins_are_logged_when_message_configured()