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

Commit 2074e33

Browse files
committed
Added config limitation filter test
1 parent df9176f commit 2074e33

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

tests/AdldapTest.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,43 @@ public function test_auth_fails_when_user_not_found()
131131
$this->assertFalse(Auth::attempt(['email' => '[email protected]', 'password' => '12345']));
132132
}
133133

134-
public function test_credentials_key_does_not_exist()
134+
public function test_config_limitation_filter()
135135
{
136-
$this->assertFalse(Auth::attempt(['non-existent-key' => '[email protected]', 'password' => '12345']));
136+
$filter = '(cn=John Doe)';
137+
138+
$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))';
139+
140+
$this->app['config']->set('adldap_auth.limitation_filter', $filter);
141+
142+
$user = $this->getMockUser([
143+
'cn' => '',
144+
'mail' => '[email protected]',
145+
'samaccountname' => 'jdoe',
146+
]);
147+
148+
$connection = $this->getMockConnection();
149+
150+
$connection->expects($this->exactly(1))->method('isBound')->willReturn(true);
151+
152+
$connection->expects($this->exactly(1))->method('search')->with(
153+
$this->equalTo(''),
154+
$this->equalTo($expectedFilter),
155+
$this->equalTo([])
156+
)->willReturn('resource');
157+
158+
$connection->expects($this->exactly(1))->method('getEntries')->willReturn([
159+
'count' => 1,
160+
$user->getAttributes(),
161+
]);
162+
163+
$connection->expects($this->exactly(2))->method('bind')
164+
->with($this->logicalOr(
165+
$this->equalTo('jdoe'),
166+
$this->equalTo('admin')
167+
))
168+
->willReturn(true);
169+
170+
$this->assertTrue(Auth::attempt(['email' => '[email protected]', 'password' => 'password']));
137171
}
138172

139173
public function test_config_callback_attribute_handler()

0 commit comments

Comments
 (0)