Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
Added config limitation filter test
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Jun 25, 2016
1 parent df9176f commit 2074e33
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions tests/AdldapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,43 @@ public function test_auth_fails_when_user_not_found()
$this->assertFalse(Auth::attempt(['email' => '[email protected]', 'password' => '12345']));
}

public function test_credentials_key_does_not_exist()
public function test_config_limitation_filter()
{
$this->assertFalse(Auth::attempt(['non-existent-key' => '[email protected]', 'password' => '12345']));
$filter = '(cn=John Doe)';

$expectedFilter = '(&(cn=John Doe)(objectclass=\70\65\72\73\6f\6e)(objectcategory=\70\65\72\73\6f\6e)(mail=\6a\64\6f\65\40\65\6d\61\69\6c\2e\63\6f\6d))';

$this->app['config']->set('adldap_auth.limitation_filter', $filter);

$user = $this->getMockUser([
'cn' => '',
'mail' => '[email protected]',
'samaccountname' => 'jdoe',
]);

$connection = $this->getMockConnection();

$connection->expects($this->exactly(1))->method('isBound')->willReturn(true);

$connection->expects($this->exactly(1))->method('search')->with(
$this->equalTo(''),
$this->equalTo($expectedFilter),
$this->equalTo([])
)->willReturn('resource');

$connection->expects($this->exactly(1))->method('getEntries')->willReturn([
'count' => 1,
$user->getAttributes(),
]);

$connection->expects($this->exactly(2))->method('bind')
->with($this->logicalOr(
$this->equalTo('jdoe'),
$this->equalTo('admin')
))
->willReturn(true);

$this->assertTrue(Auth::attempt(['email' => '[email protected]', 'password' => 'password']));
}

public function test_config_callback_attribute_handler()
Expand Down

0 comments on commit 2074e33

Please sign in to comment.