Skip to content

Commit

Permalink
refactor and fix comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Amarnath <ashish.amarnath@broadcom.com>
  • Loading branch information
ashish-amarnath committed Sep 19, 2024
1 parent 65b93f0 commit ab2c2e3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/upstreamldap/upstreamldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,25 +330,25 @@ func (p *Provider) dialTLS(ctx context.Context, addr endpointaddr.HostPort) (Con
return conn, nil
}

// dialTLS is a default implementation of the Dialer, used when Dialer is nil and ConnectionProtocol is StartTLS.
// dialStartTLS is a default implementation of the Dialer, used when Dialer is nil and ConnectionProtocol is StartTLS.
// Unfortunately, the go-ldap library does not seem to support dialing with a context.Context,
// so we implement it ourselves, heavily inspired by ldap.DialURL.
func (p *Provider) dialStartTLS(ctx context.Context, addr endpointaddr.HostPort) (Conn, error) {
tlsConfig, err := p.tlsConfig()
if err != nil {
return nil, ldap.NewError(ldap.ErrorNetwork, err)
}

// Unfortunately, this seems to be required for StartTLS, even though it is not needed for regular TLS.
tlsConfig.ServerName = addr.Host

// start with a plaintext tcp connection which will then be upgraded to
// and LDAP connection over TLS.
c, err := netDialer().DialContext(ctx, "tcp", addr.Endpoint())
if err != nil {
return nil, ldap.NewError(ldap.ErrorNetwork, err)
}

conn := ldap.NewConn(c, false)
conn.Start()
tlsConfig, err := p.tlsConfig()
if err != nil {
return nil, ldap.NewError(ldap.ErrorNetwork, err)
}
// Unfortunately, this seems to be required for StartTLS, even though it is not needed for regular TLS.
tlsConfig.ServerName = addr.Host

Check warning on line 351 in internal/upstreamldap/upstreamldap.go

View check run for this annotation

Codecov / codecov/patch

internal/upstreamldap/upstreamldap.go#L351

Added line #L351 was not covered by tests
err = conn.StartTLS(tlsConfig)
if err != nil {
return nil, err
Expand Down

0 comments on commit ab2c2e3

Please sign in to comment.