]> BookStack Code Mirror - bookstack/blobdiff - tests/Auth/LdapTest.php
Add base64 image support
[bookstack] / tests / Auth / LdapTest.php
index 3cb39ca2c59c63a8315a76c44ebbaed1881bbfe2..840dfd630eeeea91c1cf3a8dd9e98b6d7aa6fb97 100644 (file)
@@ -4,6 +4,7 @@ use BookStack\Auth\Access\LdapService;
 use BookStack\Auth\Role;
 use BookStack\Auth\Access\Ldap;
 use BookStack\Auth\User;
+use BookStack\Exceptions\LdapException;
 use Mockery\MockInterface;
 use Tests\BrowserKitTest;
 
@@ -40,6 +41,14 @@ class LdapTest extends BrowserKitTest
         $this->mockUser = factory(User::class)->make();
     }
 
+    protected function runFailedAuthLogin()
+    {
+        $this->commonLdapMocks(1, 1, 1, 1, 1);
+        $this->mockLdap->shouldReceive('searchAndGetEntries')->times(1)
+            ->andReturn(['count' => 0]);
+        $this->post('/login', ['username' => 'timmyjenkins', 'password' => 'cattreedog']);
+    }
+
     protected function mockEscapes($times = 1)
     {
         $this->mockLdap->shouldReceive('escape')->times($times)->andReturnUsing(function($val) {
@@ -550,6 +559,22 @@ class LdapTest extends BrowserKitTest
         ]);
     }
 
+    public function test_start_tls_called_if_option_set()
+    {
+        config()->set(['services.ldap.start_tls' => true]);
+        $this->mockLdap->shouldReceive('startTls')->once()->andReturn(true);
+        $this->runFailedAuthLogin();
+    }
+
+    public function test_connection_fails_if_tls_fails()
+    {
+        config()->set(['services.ldap.start_tls' => true]);
+        $this->mockLdap->shouldReceive('startTls')->once()->andReturn(false);
+        $this->commonLdapMocks(1, 1, 0, 0, 0);
+        $this->post('/login', ['username' => 'timmyjenkins', 'password' => 'cattreedog']);
+        $this->assertResponseStatus(500);
+    }
+
     public function test_ldap_attributes_can_be_binary_decoded_if_marked()
     {
         config()->set(['services.ldap.id_attribute' => 'BIN;uid']);
@@ -640,12 +665,7 @@ class LdapTest extends BrowserKitTest
     {
         $log = $this->withTestLogger();
         config()->set(['logging.failed_login.message' => 'Failed login for %u']);
-
-        $this->commonLdapMocks(1, 1, 1, 1, 1);
-        $this->mockLdap->shouldReceive('searchAndGetEntries')->times(1)
-            ->andReturn(['count' => 0]);
-
-        $this->post('/login', ['username' => 'timmyjenkins', 'password' => 'cattreedog']);
+        $this->runFailedAuthLogin();
         $this->assertTrue($log->hasWarningThatContains('Failed login for timmyjenkins'));
     }
 }