feature (boundary dev): add support for dev ldap auth method (#3192)

This commit is contained in:
Jim authored and GitHub committed 2023-04-28 11:35:54 -04:00
1 parent 9a050ec15a
commit 667ea285be
19 files changed
+345 -14

No files matched your search

@@ -123,6 +123,7 @@ func TestRecursiveListingDifferentOutputFields(t *testing.T) {
tc := controller.NewTestController(t, &controller.TestControllerOpts{
// Disable this to avoid having to deal with sorting them in the test
DisableOidcAuthMethodCreation: true,
DisableLdapAuthMethodCreation: true,
})
defer tc.Shutdown()
+10
View File
@@ -45,6 +45,7 @@ type options struct {
withAccountAttributeMap map[string]AccountToAttribute
withMemberOfGroups string
withUrls []string
withPublicId string
}
// Option - how options are passed as args
@@ -363,3 +364,12 @@ func WithMemberOfGroups(ctx context.Context, groupName ...string) Option {
return nil
}
}
// WithPublicId provides an option for passing a public id to the operation
func WithPublicId(ctx context.Context, publicId string) Option {
const op = "ldap.WithPublicId"
return func(o *options) error {
o.withPublicId = publicId
return nil
}
}
+9
View File
@@ -315,4 +315,13 @@ func Test_getOpts(t *testing.T) {
testOpts.withMemberOfGroups = "[\"test\"]"
assert.Equal(opts, testOpts)
})
t.Run("WithPublicId", func(t *testing.T) {
assert := assert.New(t)
opts, err := getOpts(WithPublicId(testCtx, "test"))
require.NoError(t, err)
testOpts := getDefaultOptions()
assert.NotEqual(opts, testOpts)
testOpts.withPublicId = "test"
assert.Equal(opts, testOpts)
})
}
@@ -6,7 +6,9 @@ package ldap
import (
"context"
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/kms"
@@ -21,7 +23,7 @@ import (
// The AuthMethod's public id and version must be empty (zero values).
//
// All options are ignored.
func (r *Repository) CreateAuthMethod(ctx context.Context, am *AuthMethod, _ ...Option) (*AuthMethod, error) {
func (r *Repository) CreateAuthMethod(ctx context.Context, am *AuthMethod, opt ...Option) (*AuthMethod, error) {
const op = "ldap.(Repository).CreateAuthMethod"
switch {
case am == nil:
@@ -38,11 +40,22 @@ func (r *Repository) CreateAuthMethod(ctx context.Context, am *AuthMethod, _ ...
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing urls (there must be at least one)")
}
var err error
am.PublicId, err = newAuthMethodId(ctx)
opts, err := getOpts(opt...)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
}
am.PublicId = opts.withPublicId
if am.PublicId == "" {
id, err := newAuthMethodId(ctx)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
}
am.PublicId = id
} else {
if !strings.HasPrefix(am.PublicId, globals.LdapAuthMethodPrefix+"_") {
return nil, errors.New(ctx, errors.InvalidParameter, op, "wrong auth method id prefix")
}
}
cv, err := am.convertValueObjects(ctx)
if err != nil {
@@ -54,7 +54,7 @@ func TestRepository_authenticate(t *testing.T) {
require.NoError(t, err)
testAm := TestAuthMethod(t, testConn, orgDbWrapper, org.PublicId,
[]string{fmt.Sprintf("ldaps://127.0.0.1:%d", td.Port())},
[]string{fmt.Sprintf("ldaps://%s:%d", td.Host(), td.Port())},
WithCertificates(testCtx, tdCerts...),
WithDiscoverDn(testCtx),
WithEnableGroups(testCtx),
@@ -238,7 +238,7 @@ func TestRepository_authenticate(t *testing.T) {
t.Run("use-token-groups", func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
amWithTokenGroups := TestAuthMethod(t, testConn, orgDbWrapper, org.PublicId,
[]string{fmt.Sprintf("ldaps://127.0.0.1:%d", td.Port())},
[]string{fmt.Sprintf("ldaps://%s:%d", td.Host(), td.Port())},
WithCertificates(testCtx, tdCerts...),
WithDiscoverDn(testCtx),
WithEnableGroups(testCtx),
@@ -270,7 +270,7 @@ func TestRepository_authenticate(t *testing.T) {
assert, require := assert.New(t), require.New(t)
amWithNoCerts := TestAuthMethod(t, testConn, orgDbWrapper, org.PublicId,
[]string{fmt.Sprintf("ldaps://127.0.0.1:%d", td.Port())},
[]string{fmt.Sprintf("ldaps://%s:%d", td.Host(), td.Port())},
WithDiscoverDn(testCtx),
WithEnableGroups(testCtx),
WithUserDn(testCtx, testdirectory.DefaultUserDN),
@@ -62,7 +62,7 @@ func TestAuthenticate(t *testing.T) {
td.SetGroups(groups...)
testPrimaryAuthMethod := TestAuthMethod(t, testConn, orgDbWrapper, org.PublicId,
[]string{fmt.Sprintf("ldaps://127.0.0.1:%d", td.Port())},
[]string{fmt.Sprintf("ldaps://%s:%d", td.Host(), td.Port())},
WithCertificates(testCtx, tdCerts...),
WithDiscoverDn(testCtx),
WithEnableGroups(testCtx),
@@ -72,7 +72,7 @@ func TestAuthenticate(t *testing.T) {
iam.TestSetPrimaryAuthMethod(t, iamRepo, org, testPrimaryAuthMethod.PublicId)
testNotPrimaryAuthMethod := TestAuthMethod(t, testConn, orgDbWrapper, org.PublicId,
[]string{fmt.Sprintf("ldaps://127.0.0.1:%d", td.Port())},
[]string{fmt.Sprintf("ldaps://%s:%d", td.Host(), td.Port())},
WithCertificates(testCtx, tdCerts...),
WithDiscoverDn(testCtx),
WithEnableGroups(testCtx),