Skip to content

Commit cd28b77

Browse files
committed
Add tests
1 parent f74d04e commit cd28b77

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

tests/Unit/Auth/GuardTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function test_sasl_bind()
232232
$this->assertTrue($ldap->isBound());
233233
}
234234

235-
public function test_tls_is_upgraded_once()
235+
public function test_tls_is_only_upgraded_once_on_subsequent_binds()
236236
{
237237
$ldap = (new LdapFake())->expect([
238238
LdapFake::operation('bind')->once()->with('admin', 'password')->andReturnResponse(),

tests/Unit/LdapTest.php

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,10 @@ public function test_can_change_passwords()
8888

8989
public function test_set_options()
9090
{
91-
$ldap = (new LdapFake())
92-
->expect([
93-
LdapFake::operation('setOption')->once()->with(1, 'value')->andReturnTrue(),
94-
LdapFake::operation('setOption')->once()->with(2, 'value')->andReturnTrue(),
95-
]);
91+
$ldap = (new LdapFake())->expect([
92+
LdapFake::operation('setOption')->once()->with(1, 'value')->andReturnTrue(),
93+
LdapFake::operation('setOption')->once()->with(2, 'value')->andReturnTrue(),
94+
]);
9695

9796
$ldap->setOptions([1 => 'value', 2 => 'value']);
9897
}
@@ -105,4 +104,50 @@ public function test_get_detailed_error_returns_null_when_error_number_is_zero()
105104

106105
$this->assertNull($ldap->getDetailedError());
107106
}
107+
108+
public function test_is_secure_after_binding_with_an_ssl_connection()
109+
{
110+
$ldap = (new LdapFake())->expect([
111+
LdapFake::operation('bind')->once()->andReturnResponse(),
112+
]);
113+
114+
$ldap->ssl();
115+
116+
$this->assertFalse($ldap->isSecure());
117+
118+
$ldap->bind('foo', 'bar');
119+
120+
$this->assertTrue($ldap->isSecure());
121+
}
122+
123+
public function test_is_secure_after_starting_tls()
124+
{
125+
$ldap = (new LdapFake())->expect([
126+
LdapFake::operation('startTLS')->once()->andReturnTrue(),
127+
]);
128+
129+
$this->assertFalse($ldap->isSecure());
130+
131+
$ldap->startTLS();
132+
133+
$this->assertTrue($ldap->isSecure());
134+
}
135+
136+
public function test_is_secure_after_starting_tls_but_failing_bind()
137+
{
138+
$ldap = (new LdapFake())->expect([
139+
LdapFake::operation('startTLS')->once()->andReturnTrue(),
140+
LdapFake::operation('bind')->once()->andReturnResponse(1),
141+
]);
142+
143+
$this->assertFalse($ldap->isSecure());
144+
145+
$ldap->startTLS();
146+
147+
$this->assertTrue($ldap->isSecure());
148+
149+
$ldap->bind('foo', 'bar');
150+
151+
$this->assertTrue($ldap->isSecure());
152+
}
108153
}

0 commit comments

Comments
 (0)