From 5a8c9a1418140c89042e56aea3638a79890c5caa Mon Sep 17 00:00:00 2001 From: Tommi2Day Date: Sun, 9 Apr 2023 21:32:40 +0200 Subject: [PATCH] change ldap timeout from duration to int (seconds) --- dblib/tns_ldap_test.go | 4 ++-- ldaplib/ldap.go | 6 +++--- ldaplib/ldap_test.go | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dblib/tns_ldap_test.go b/dblib/tns_ldap_test.go index 8008743..c3f4c9f 100644 --- a/dblib/tns_ldap_test.go +++ b/dblib/tns_ldap_test.go @@ -4,7 +4,6 @@ import ( "fmt" "os" "testing" - "time" "github.com/tommi2day/gomodules/ldaplib" "github.com/tommi2day/gomodules/test" @@ -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 @@ -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) { diff --git a/ldaplib/ldap.go b/ldaplib/ldap.go index e6a1b5d..2356bc9 100644 --- a/ldaplib/ldap.go +++ b/ldaplib/ldap.go @@ -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 { @@ -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 { diff --git a/ldaplib/ldap_test.go b/ldaplib/ldap_test.go index 33bcb7d..74c77ba 100644 --- a/ldaplib/ldap_test.go +++ b/ldaplib/ldap_test.go @@ -3,7 +3,6 @@ package ldaplib import ( "os" "testing" - "time" ldap "github.com/go-ldap/ldap/v3" "github.com/stretchr/testify/assert" @@ -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) {