Skip to content

Commit 924a073

Browse files
committed
Updated
1 parent 3ebb002 commit 924a073

File tree

3 files changed

+30
-44
lines changed

3 files changed

+30
-44
lines changed

pkg/ldap/manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ func (ldap *Manager) Host() string {
152152
// Return the user for the LDAP connection
153153
func (ldap *Manager) User() string {
154154
if types.IsIdentifier(ldap.user) {
155+
// If it's an identifier, then append the DN
155156
return fmt.Sprint("cn=", ldap.user, ",", ldap.dn)
156157
} else {
158+
// Assume it's a DN
157159
return ldap.user
158160
}
159161
}
@@ -247,7 +249,8 @@ func (manager *Manager) List(ctx context.Context, request schema.ObjectListReque
247249
if request.Filter != nil {
248250
filter = types.PtrString(request.Filter)
249251
}
250-
attrs := []string{"*"}
252+
// TODO
253+
attrs := []string{}
251254

252255
// Perform the search through paging, skipping the first N entries
253256
var list schema.ObjectList
@@ -276,8 +279,6 @@ func (manager *Manager) list(ctx context.Context, scope int, dn, filter string,
276279
controls = []ldap.Control{paging}
277280
}
278281

279-
fmt.Println("searching", dn, filter, attrs)
280-
281282
// Create the search request
282283
req := ldap.NewSearchRequest(
283284
dn,

pkg/ldap/manager_test.go

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,43 @@ import (
88
"time"
99

1010
// Packages
11-
12-
"github.com/mutablelogic/go-server/pkg/httpresponse"
11+
httpresponse "github.com/mutablelogic/go-server/pkg/httpresponse"
1312
ldap "github.com/mutablelogic/go-server/pkg/ldap"
1413
schema "github.com/mutablelogic/go-server/pkg/ldap/schema"
1514
assert "github.com/stretchr/testify/assert"
1615
)
1716

17+
const (
18+
User, Pass = "uid=admin,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org", "Secret123"
19+
URL = "ldaps://ipa.demo1.freeipa.org/"
20+
BaseDN = "dc=demo1,dc=freeipa,dc=org"
21+
)
22+
23+
var (
24+
opts = []ldap.Opt{}
25+
)
26+
1827
/////////////////////////////////////////////////////////////////////////////////
1928
// PUBLIC METHODS
2029

21-
func Test_Manager_001(t *testing.T) {
22-
assert := assert.New(t)
23-
30+
func TestMain(m *testing.M) {
2431
// Get opts
25-
opts := []ldap.Opt{}
2632
if url := os.Getenv("LDAP_URL"); url != "" {
27-
opts = append(opts, ldap.WithUrl(url))
28-
} else {
29-
t.Skip("Skipping test, LDAP_URL not set")
30-
}
31-
if dn := os.Getenv("LDAP_BASE_DN"); dn != "" {
32-
opts = append(opts, ldap.WithBaseDN(dn))
33+
opts = append(opts, ldap.WithUrl(url), ldap.WithUser(os.Getenv("LDAP_USER")), ldap.WithPassword(os.Getenv("LDAP_PASSWORD")))
34+
if dn := os.Getenv("LDAP_BASE_DN"); dn != "" {
35+
opts = append(opts, ldap.WithBaseDN(dn))
36+
}
3337
} else {
34-
t.Skip("Skipping test, LDAP_BASE_DN not set")
38+
opts = append(opts, ldap.WithUrl(URL), ldap.WithUser(User), ldap.WithPassword(Pass), ldap.WithBaseDN(BaseDN), ldap.WithSkipVerify())
3539
}
3640

41+
exitCode := m.Run()
42+
os.Exit(exitCode)
43+
}
44+
45+
func Test_Manager_001(t *testing.T) {
46+
assert := assert.New(t)
47+
3748
// Create a new queue manager
3849
manager, err := ldap.NewManager(opts...)
3950
if !assert.NoError(err) {
@@ -79,19 +90,6 @@ func Test_Manager_001(t *testing.T) {
7990
func Test_Manager_002(t *testing.T) {
8091
assert := assert.New(t)
8192

82-
// Get opts
83-
opts := []ldap.Opt{}
84-
if url := os.Getenv("LDAP_URL"); url != "" {
85-
opts = append(opts, ldap.WithUrl(url))
86-
} else {
87-
t.Skip("Skipping test, LDAP_URL not set")
88-
}
89-
if dn := os.Getenv("LDAP_BASE_DN"); dn != "" {
90-
opts = append(opts, ldap.WithBaseDN(dn))
91-
} else {
92-
t.Skip("Skipping test, LDAP_BASE_DN not set")
93-
}
94-
9593
// Create a new queue manager
9694
manager, err := ldap.NewManager(opts...)
9795
if !assert.NoError(err) {
@@ -126,19 +124,6 @@ func Test_Manager_002(t *testing.T) {
126124
func Test_Manager_003(t *testing.T) {
127125
assert := assert.New(t)
128126

129-
// Get opts
130-
opts := []ldap.Opt{}
131-
if url := os.Getenv("LDAP_URL"); url != "" {
132-
opts = append(opts, ldap.WithUrl(url))
133-
} else {
134-
t.Skip("Skipping test, LDAP_URL not set")
135-
}
136-
if dn := os.Getenv("LDAP_BASE_DN"); dn != "" {
137-
opts = append(opts, ldap.WithBaseDN(dn))
138-
} else {
139-
t.Skip("Skipping test, LDAP_BASE_DN not set")
140-
}
141-
142127
// Create a new queue manager
143128
manager, err := ldap.NewManager(opts...)
144129
if !assert.NoError(err) {

pkg/ldap/opt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ func WithPassword(v string) Opt {
102102
}
103103
}
104104

105-
func WithSkipVerify(v bool) Opt {
105+
func WithSkipVerify() Opt {
106106
return func(o *opt) error {
107-
o.skipverify = v
107+
o.skipverify = true
108108
return nil
109109
}
110110
}

0 commit comments

Comments
 (0)