fix (ldap): support only updating the bind-dn and/or bind-password (#3511)
* fix (ldap): support only updating the bind-dn and/or bind-password * chore: changelog entry for PR #3511
This commit is contained in:
9 files changed
+211
-41
No files matched your search
@@ -127,16 +127,6 @@ func TestNewAuthMethod(t *testing.T) {
|
||||
wantErrCode: errors.InvalidParameter,
|
||||
wantErrContains: `https scheme in url "https://alice.com" is not either ldap or ldaps`,
|
||||
},
|
||||
{
|
||||
name: "opt-error",
|
||||
ctx: testCtx,
|
||||
scopeId: "global",
|
||||
urls: TestConvertToUrls(t, "ldaps://alice.com"),
|
||||
opts: []Option{WithBindCredential(testCtx, "dn", "")},
|
||||
wantErr: true,
|
||||
wantErrCode: errors.InvalidParameter,
|
||||
wantErrContains: "ldap.WithBindCredential: missing password",
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
||||
@@ -250,10 +250,6 @@ func WithBindCredential(ctx context.Context, dn, password string) Option {
|
||||
switch {
|
||||
case dn == "" && password == "":
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "missing both dn and password")
|
||||
case dn != "" && password == "":
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "missing password")
|
||||
case dn == "" && password != "":
|
||||
return errors.New(ctx, errors.InvalidParameter, op, "missing dn")
|
||||
}
|
||||
o.withBindDn = dn
|
||||
o.withBindPassword = password
|
||||
|
||||
@@ -184,18 +184,18 @@ func Test_getOpts(t *testing.T) {
|
||||
testOpts.withBindPassword = "password"
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithBindCredential-missing-dn", func(t *testing.T) {
|
||||
t.Run("WithBindCredential-only-password", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts, err := getOpts(WithBindCredential(testCtx, "", "password"))
|
||||
require.Error(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(opts.withBindDn)
|
||||
assert.Empty(opts.withBindPassword)
|
||||
assert.NotEmpty(opts.withBindPassword)
|
||||
})
|
||||
t.Run("WithBindCredential-missing-password", func(t *testing.T) {
|
||||
t.Run("WithBindCredential-only-dn", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts, err := getOpts(WithBindCredential(testCtx, "dn", ""))
|
||||
require.Error(t, err)
|
||||
assert.Empty(opts.withBindDn)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(opts.withBindDn)
|
||||
assert.Empty(opts.withBindPassword)
|
||||
})
|
||||
t.Run("WithBindCredential-missing-dn-and-password", func(t *testing.T) {
|
||||
|
||||
@@ -297,7 +297,7 @@ func (r *Repository) UpdateAuthMethod(ctx context.Context, am *AuthMethod, versi
|
||||
return nil, db.NoRowsAffected, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
if err := bc.encrypt(ctx, dbWrapper); err != nil {
|
||||
return nil, db.NoRowsAffected, errors.Wrap(ctx, err, op)
|
||||
return nil, db.NoRowsAffected, errors.Wrap(ctx, err, op, errors.WithMsg("error wrapping updated bind credential"))
|
||||
}
|
||||
addBindCred = bc
|
||||
}
|
||||
|
||||
@@ -494,6 +494,62 @@ func TestRepository_UpdateAuthMethod(t *testing.T) {
|
||||
return am
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update-just-binddn",
|
||||
ctx: testCtx,
|
||||
repo: testRepo,
|
||||
setup: func() *AuthMethod {
|
||||
return TestAuthMethod(t,
|
||||
testConn, databaseWrapper,
|
||||
org.PublicId,
|
||||
[]string{"ldaps://ldap1", "ldap://ldap2"},
|
||||
WithBindCredential(testCtx, "orig-bind-dn", "orig-bind-password"),
|
||||
)
|
||||
},
|
||||
updateWith: func(orig *AuthMethod) *AuthMethod {
|
||||
am := AllocAuthMethod()
|
||||
am.PublicId = orig.PublicId
|
||||
am.BindDn = "bind-dn"
|
||||
return &am
|
||||
},
|
||||
fieldMasks: []string{
|
||||
BindDnField,
|
||||
},
|
||||
version: 1,
|
||||
want: func(orig, updateWith *AuthMethod) *AuthMethod {
|
||||
am := orig.clone()
|
||||
am.BindDn = updateWith.BindDn
|
||||
return am
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update-just-bind-password",
|
||||
ctx: testCtx,
|
||||
repo: testRepo,
|
||||
setup: func() *AuthMethod {
|
||||
return TestAuthMethod(t,
|
||||
testConn, databaseWrapper,
|
||||
org.PublicId,
|
||||
[]string{"ldaps://ldap1", "ldap://ldap2"},
|
||||
WithBindCredential(testCtx, "orig-bind-dn", "orig-bind-password"),
|
||||
)
|
||||
},
|
||||
updateWith: func(orig *AuthMethod) *AuthMethod {
|
||||
am := AllocAuthMethod()
|
||||
am.PublicId = orig.PublicId
|
||||
am.BindPassword = "bind-password"
|
||||
return &am
|
||||
},
|
||||
fieldMasks: []string{
|
||||
BindPasswordField,
|
||||
},
|
||||
version: 1,
|
||||
want: func(orig, updateWith *AuthMethod) *AuthMethod {
|
||||
am := orig.clone()
|
||||
am.BindPassword = updateWith.BindPassword
|
||||
return am
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "missing-auth-method",
|
||||
ctx: testCtx,
|
||||
|
||||
Reference in new issue
Block a user