Skip to content

Commit

Permalink
change ldap timeout from duration to int (seconds)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommi2Day committed Apr 9, 2023
1 parent fe462b7 commit 5a8c9a1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dblib/tns_ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"testing"
"time"

"github.com/tommi2day/gomodules/ldaplib"
"github.com/tommi2day/gomodules/test"
Expand Down Expand Up @@ -52,6 +51,7 @@ DEFAULT_ADMIN_CONTEXT = "dc=oracle,dc=local"
DIRECTORY_SERVERS = (oid:1389:1636, ldap:389)
DIRECTORY_SERVER_TYPE = OID
`
const ldapTimeout = 20

func TestOracleLdap(t *testing.T) {
var err error
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestOracleLdap(t *testing.T) {

base := LdapBaseDn
server, sslport = getLdapHostAndPort(ldapContainer, "636/tcp")
lc = ldaplib.NewConfig(server, sslport, true, true, base, 20*time.Second)
lc = ldaplib.NewConfig(server, sslport, true, true, base, ldapTimeout)
context := ""

t.Run("Ldap Connect", func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions ldaplib/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ type LdapConfigType struct {
TLS bool
Insecure bool
BaseDN string
Timeout time.Duration
Timeout int // in second
Conn *ldap.Conn
}

// NewConfig defines common connection parameter
func NewConfig(server string, port int, tls bool, insecure bool, basedn string, timeout time.Duration) *LdapConfigType {
func NewConfig(server string, port int, tls bool, insecure bool, basedn string, timeout int) *LdapConfigType {
ldapConfig := LdapConfigType{}
if port == 0 {
if tls {
Expand Down Expand Up @@ -53,7 +53,7 @@ func (lc *LdapConfigType) Connect(bindDN string, bindPassword string) (err error
}

// set timeout
ldap.DefaultTimeout = lc.Timeout
ldap.DefaultTimeout = time.Duration(lc.Timeout) * time.Second

// You can also use IP instead of FQDN
if lc.Insecure {
Expand Down
3 changes: 1 addition & 2 deletions ldaplib/ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ldaplib
import (
"os"
"testing"
"time"

ldap "github.com/go-ldap/ldap/v3"
"github.com/stretchr/testify/assert"
Expand All @@ -20,7 +19,7 @@ const LdapConfigPassword = "config"
var port = 10389
var sslport = 10636
var lc *LdapConfigType
var timeout = 20 * time.Second
var timeout = 20

func TestLdapConfig(t *testing.T) {
t.Run("Ldap Config", func(t *testing.T) {
Expand Down

0 comments on commit 5a8c9a1

Please sign in to comment.