Skip to content

Commit a4f9004

Browse files
CLOUDP-72727: Fix LDAPConfigurationsService.Save to pass LDAPConfiguration as input (#136)
2 parents 346af62 + 82ea2b6 commit a4f9004

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

mongodbatlas/ldap_configurations.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
)
88

99
const (
10-
ldapConfigurationPath = "groups/%s/userSecurity"
11-
ldapVerifyConfigurationPath = ldapConfigurationPath + "/ldap/verify"
10+
ldapConfigurationPath = "groups/%s/userSecurity"
11+
ldapConfigurationPathuserToDNMapping = ldapConfigurationPath + "/ldap/userToDNMapping"
12+
ldapVerifyConfigurationPath = ldapConfigurationPath + "/ldap/verify"
1213
)
1314

1415
// LDAPConfigurationsService is an interface of the LDAP Configuration
@@ -19,7 +20,7 @@ type LDAPConfigurationsService interface {
1920
Verify(context.Context, string, *LDAP) (*LDAPConfiguration, *Response, error)
2021
Get(context.Context, string) (*LDAPConfiguration, *Response, error)
2122
GetStatus(context.Context, string, string) (*LDAPConfiguration, *Response, error)
22-
Save(context.Context, string, *LDAP) (*LDAPConfiguration, *Response, error)
23+
Save(context.Context, string, *LDAPConfiguration) (*LDAPConfiguration, *Response, error)
2324
Delete(context.Context, string) (*LDAPConfiguration, *Response, error)
2425
}
2526

@@ -131,7 +132,7 @@ func (s *LDAPConfigurationsServiceOp) GetStatus(ctx context.Context, groupID, re
131132
// Save saves an LDAP configuration for a Atlas project.
132133
//
133134
// See more: https://docs.atlas.mongodb.com/reference/api/ldaps-configuration-save/
134-
func (s *LDAPConfigurationsServiceOp) Save(ctx context.Context, groupID string, configuration *LDAP) (*LDAPConfiguration, *Response, error) {
135+
func (s *LDAPConfigurationsServiceOp) Save(ctx context.Context, groupID string, configuration *LDAPConfiguration) (*LDAPConfiguration, *Response, error) {
135136
if groupID == "" {
136137
return nil, nil, NewArgError("groupID", "must be set")
137138
}
@@ -188,7 +189,7 @@ func (s *LDAPConfigurationsServiceOp) Delete(ctx context.Context, groupID string
188189
return nil, nil, NewArgError("groupID", "must be set")
189190
}
190191

191-
path := fmt.Sprintf(ldapConfigurationPath, groupID)
192+
path := fmt.Sprintf(ldapConfigurationPathuserToDNMapping, groupID)
192193

193194
req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil)
194195
if err != nil {

mongodbatlas/ldap_configurations_test.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ func TestLDAPConfigurations_Verify(t *testing.T) {
2828
}`)
2929
})
3030

31-
request := &LDAP{}
31+
request := &LDAP{
32+
Hostname: "atlas-ldaps-01.ldap.myteam.com",
33+
Port: 636,
34+
BindUsername: "CN=Administrator,CN=Users,DC=atlas-ldaps-01,DC=myteam,DC=com",
35+
BindPassword: "admin",
36+
}
3237
ldap, _, err := client.LDAPConfigurations.Verify(ctx, groupID, request)
3338
if err != nil {
3439
t.Fatalf("LDAPConfigurations.Verify returned error: %v", err)
@@ -133,7 +138,16 @@ func TestLDAPConfigurations_Save(t *testing.T) {
133138
}`)
134139
})
135140

136-
request := &LDAP{}
141+
request := &LDAPConfiguration{
142+
LDAP: &LDAP{
143+
AuthenticationEnabled: true,
144+
AuthorizationEnabled: true,
145+
Hostname: "atlas-ldaps-01.ldap.myteam.com",
146+
Port: 636,
147+
BindUsername: "CN=Administrator,CN=Users,DC=atlas-ldaps-01,DC=myteam,DC=com",
148+
BindPassword: "admin",
149+
},
150+
}
137151
ldap, _, err := client.LDAPConfigurations.Save(ctx, groupID, request)
138152
if err != nil {
139153
t.Fatalf("LDAPConfigurations.Save returned error: %v", err)
@@ -218,7 +232,7 @@ func TestLDAPConfigurations_Delete(t *testing.T) {
218232

219233
groupID := "535683b3794d371327b"
220234

221-
mux.HandleFunc(fmt.Sprintf("/groups/%s/userSecurity", groupID), func(w http.ResponseWriter, r *http.Request) {
235+
mux.HandleFunc(fmt.Sprintf("/groups/%s/userSecurity/ldap/userToDNMapping", groupID), func(w http.ResponseWriter, r *http.Request) {
222236
testMethod(t, r, http.MethodDelete)
223237
fmt.Fprint(w, `{
224238
"ldap" : {
@@ -227,11 +241,7 @@ func TestLDAPConfigurations_Delete(t *testing.T) {
227241
"authzQueryTemplate" : "{USER}?memberOf?base",
228242
"bindUsername" : "CN=Administrator,CN=Users,DC=atlas-ldaps-01,DC=myteam,DC=com",
229243
"hostname" : "atlas-ldaps-01.ldap.myteam.com",
230-
"port" : 636,
231-
"userToDNMapping" : [ {
232-
"match" : "(.*)",
233-
"substitution" : "CN={0},CN=Users,DC=atlas-ldaps-01,DC=myteam,DC=com"
234-
} ]
244+
"port" : 636
235245
}
236246
}`)
237247
})
@@ -248,13 +258,7 @@ func TestLDAPConfigurations_Delete(t *testing.T) {
248258
Hostname: "atlas-ldaps-01.ldap.myteam.com",
249259
Port: 636,
250260
BindUsername: "CN=Administrator,CN=Users,DC=atlas-ldaps-01,DC=myteam,DC=com",
251-
UserToDNMapping: []*UserToDNMapping{
252-
{
253-
Match: "(.*)",
254-
Substitution: "CN={0},CN=Users,DC=atlas-ldaps-01,DC=myteam,DC=com",
255-
},
256-
},
257-
AuthzQueryTemplate: "{USER}?memberOf?base",
261+
AuthzQueryTemplate: "{USER}?memberOf?base",
258262
},
259263
}
260264

0 commit comments

Comments
 (0)