Skip to content

Commit 214f299

Browse files
acobaughjohnweldon
authored andcommitted
Add ldap.TLSConnectionState()
1 parent 22c061e commit 214f299

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

conn.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,17 @@ func (l *Conn) StartTLS(config *tls.Config) error {
295295
return nil
296296
}
297297

298+
// TLSConnectionState returns the client's TLS connection state.
299+
// The return values are their zero values if StartTLS did
300+
// not succeed.
301+
func (l *Conn) TLSConnectionState() (state tls.ConnectionState, ok bool) {
302+
tc, ok := l.conn.(*tls.Conn)
303+
if !ok {
304+
return
305+
}
306+
return tc.ConnectionState(), true
307+
}
308+
298309
func (l *Conn) sendMessage(packet *ber.Packet) (*messageContext, error) {
299310
return l.sendMessageWithFlags(packet, 0)
300311
}

ldap_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,30 @@ func TestStartTLS(t *testing.T) {
5656
fmt.Printf("TestStartTLS: finished...\n")
5757
}
5858

59+
func TestTLSConnectionState(t *testing.T) {
60+
fmt.Printf("TestTLSConnectionState: starting...\n")
61+
l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort))
62+
if err != nil {
63+
t.Errorf(err.Error())
64+
return
65+
}
66+
err = l.StartTLS(&tls.Config{InsecureSkipVerify: true})
67+
if err != nil {
68+
t.Errorf(err.Error())
69+
return
70+
}
71+
72+
cs, ok := l.TLSConnectionState()
73+
if !ok {
74+
t.Errorf("TLSConnectionState returned ok == false; want true")
75+
}
76+
if cs.Version == 0 || !cs.HandshakeComplete {
77+
t.Errorf("ConnectionState = %#v; expected Version != 0 and HandshakeComplete = true", cs)
78+
}
79+
80+
fmt.Printf("TestTLSConnectionState: finished...\n")
81+
}
82+
5983
func TestSearch(t *testing.T) {
6084
fmt.Printf("TestSearch: starting...\n")
6185
l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort))

0 commit comments

Comments
 (0)