Made ldap auth use the 'dn' if a 'uid' is not present.
Fixes #56
Showing
3 changed files
with
28 additions
and
4 deletions
| ... | @@ -46,7 +46,7 @@ class LdapService | ... | @@ -46,7 +46,7 @@ class LdapService |
| 46 | 46 | ||
| 47 | $user = $users[0]; | 47 | $user = $users[0]; |
| 48 | return [ | 48 | return [ |
| 49 | - 'uid' => $user['uid'][0], | 49 | + 'uid' => (isset($user['uid'])) ? $user['uid'][0] : $user['dn'], |
| 50 | 'name' => $user['cn'][0], | 50 | 'name' => $user['cn'][0], |
| 51 | 'dn' => $user['dn'], | 51 | 'dn' => $user['dn'], |
| 52 | 'email' => (isset($user['mail'])) ? $user['mail'][0] : null | 52 | 'email' => (isset($user['mail'])) ? $user['mail'][0] : null | ... | ... |
| ... | @@ -28,4 +28,4 @@ class AddExternalAuthToUsers extends Migration | ... | @@ -28,4 +28,4 @@ class AddExternalAuthToUsers extends Migration |
| 28 | $table->dropColumn('external_auth_id'); | 28 | $table->dropColumn('external_auth_id'); |
| 29 | }); | 29 | }); |
| 30 | } | 30 | } |
| 31 | -} | 31 | +} |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -28,7 +28,7 @@ class LdapTest extends \TestCase | ... | @@ -28,7 +28,7 @@ class LdapTest extends \TestCase |
| 28 | ->andReturn(['count' => 1, 0 => [ | 28 | ->andReturn(['count' => 1, 0 => [ |
| 29 | 'uid' => [$this->mockUser->name], | 29 | 'uid' => [$this->mockUser->name], |
| 30 | 'cn' => [$this->mockUser->name], | 30 | 'cn' => [$this->mockUser->name], |
| 31 | - 'dn' => ['dc=test'.config('services.ldap.base_dn')] | 31 | + 'dn' => ['dc=test' . config('services.ldap.base_dn')] |
| 32 | ]]); | 32 | ]]); |
| 33 | $this->mockLdap->shouldReceive('bind')->times(6)->andReturn(true); | 33 | $this->mockLdap->shouldReceive('bind')->times(6)->andReturn(true); |
| 34 | 34 | ||
| ... | @@ -46,6 +46,30 @@ class LdapTest extends \TestCase | ... | @@ -46,6 +46,30 @@ class LdapTest extends \TestCase |
| 46 | ->seeInDatabase('users', ['email' => $this->mockUser->email, 'email_confirmed' => 1, 'external_auth_id' => $this->mockUser->name]); | 46 | ->seeInDatabase('users', ['email' => $this->mockUser->email, 'email_confirmed' => 1, 'external_auth_id' => $this->mockUser->name]); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | + public function test_login_works_when_no_uid_provided_by_ldap_server() | ||
| 50 | + { | ||
| 51 | + $this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId); | ||
| 52 | + $this->mockLdap->shouldReceive('setOption')->once(); | ||
| 53 | + $ldapDn = 'cn=test-user,dc=test' . config('services.ldap.base_dn'); | ||
| 54 | + $this->mockLdap->shouldReceive('searchAndGetEntries')->times(2) | ||
| 55 | + ->with($this->resourceId, config('services.ldap.base_dn'), Mockery::type('string'), Mockery::type('array')) | ||
| 56 | + ->andReturn(['count' => 1, 0 => [ | ||
| 57 | + 'cn' => [$this->mockUser->name], | ||
| 58 | + 'dn' => $ldapDn, | ||
| 59 | + 'mail' => [$this->mockUser->email] | ||
| 60 | + ]]); | ||
| 61 | + $this->mockLdap->shouldReceive('bind')->times(3)->andReturn(true); | ||
| 62 | + | ||
| 63 | + $this->visit('/login') | ||
| 64 | + ->see('Username') | ||
| 65 | + ->type($this->mockUser->name, '#username') | ||
| 66 | + ->type($this->mockUser->password, '#password') | ||
| 67 | + ->press('Sign In') | ||
| 68 | + ->seePageIs('/') | ||
| 69 | + ->see($this->mockUser->name) | ||
| 70 | + ->seeInDatabase('users', ['email' => $this->mockUser->email, 'email_confirmed' => 1, 'external_auth_id' => $ldapDn]); | ||
| 71 | + } | ||
| 72 | + | ||
| 49 | public function test_initial_incorrect_details() | 73 | public function test_initial_incorrect_details() |
| 50 | { | 74 | { |
| 51 | $this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId); | 75 | $this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId); |
| ... | @@ -55,7 +79,7 @@ class LdapTest extends \TestCase | ... | @@ -55,7 +79,7 @@ class LdapTest extends \TestCase |
| 55 | ->andReturn(['count' => 1, 0 => [ | 79 | ->andReturn(['count' => 1, 0 => [ |
| 56 | 'uid' => [$this->mockUser->name], | 80 | 'uid' => [$this->mockUser->name], |
| 57 | 'cn' => [$this->mockUser->name], | 81 | 'cn' => [$this->mockUser->name], |
| 58 | - 'dn' => ['dc=test'.config('services.ldap.base_dn')] | 82 | + 'dn' => ['dc=test' . config('services.ldap.base_dn')] |
| 59 | ]]); | 83 | ]]); |
| 60 | $this->mockLdap->shouldReceive('bind')->times(3)->andReturn(true, true, false); | 84 | $this->mockLdap->shouldReceive('bind')->times(3)->andReturn(true, true, false); |
| 61 | 85 | ... | ... |
-
Please register or sign in to post a comment