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

@@ -790,7 +790,7 @@ func TestAuthenticate_Ldap(t *testing.T) {
require.NoError(t, err)
testAm := ldap.TestAuthMethod(t, testConn, orgDbWrapper, o.PublicId,
[]string{fmt.Sprintf("ldaps://127.0.0.1:%d", td.Port())},
[]string{fmt.Sprintf("ldaps://%s:%d", td.Host(), td.Port())},
ldap.WithCertificates(testCtx, tdCerts...),
ldap.WithDiscoverDn(testCtx),
ldap.WithEnableGroups(testCtx),
+23
View File
@@ -50,6 +50,7 @@ const (
DefaultProjectId = "p_1234567890"
DefaultTestPasswordAuthMethodId = "ampw_1234567890"
DefaultTestOidcAuthMethodId = "amoidc_1234567890"
DefaultTestLdapAuthMethodId = globals.LdapAuthMethodPrefix + "_1234567890"
DefaultTestLoginName = "admin"
DefaultTestUnprivilegedLoginName = "user"
DefaultTestPassword = "passpass"
@@ -355,6 +356,9 @@ type TestControllerOpts struct {
// DefaultOidcAuthMethodId is the default OIDC method ID to use, if set.
DefaultOidcAuthMethodId string
// DefaultLdapAuthMethodId is the default LDAP method ID to use, if set.
DefaultLdapAuthMethodId string
// DefaultLoginName is the login name used when creating the default admin account.
DefaultLoginName string
@@ -376,6 +380,10 @@ type TestControllerOpts struct {
// OIDC listener. Useful for e.g. unix listener tests.
DisableOidcAuthMethodCreation bool
// DisableLdapAuthMethodCreation can be set true to disable the built-in
// ldap listener. Useful for e.g. unix listener tests.
DisableLdapAuthMethodCreation bool
// DisableScopesCreation can be set true to disable creating scopes
// automatically.
DisableScopesCreation bool
@@ -564,6 +572,11 @@ func TestControllerConfig(t testing.TB, ctx context.Context, tc *TestController,
} else {
tc.b.DevOidcAuthMethodId = DefaultTestOidcAuthMethodId
}
if opts.DefaultLdapAuthMethodId != "" {
tc.b.DevLdapAuthMethodId = opts.DefaultLdapAuthMethodId
} else {
tc.b.DevLdapAuthMethodId = DefaultTestLdapAuthMethodId
}
if opts.DefaultLoginName != "" {
tc.b.DevLoginName = opts.DefaultLoginName
} else {
@@ -643,6 +656,7 @@ func TestControllerConfig(t testing.TB, ctx context.Context, tc *TestController,
suffix := opts.InitialResourcesSuffix
tc.b.DevPasswordAuthMethodId = "ampw_" + suffix
tc.b.DevOidcAuthMethodId = "amoidc_" + suffix
tc.b.DevLdapAuthMethodId = globals.LdapAuthMethodPrefix + "_" + suffix
tc.b.DevHostCatalogId = "hcst_" + suffix
tc.b.DevHostId = "hst_" + suffix
tc.b.DevHostSetId = "hsst_" + suffix
@@ -714,6 +728,11 @@ func TestControllerConfig(t testing.TB, ctx context.Context, tc *TestController,
t.Fatal(err)
}
}
if !opts.DisableLdapAuthMethodCreation {
if err := tc.b.CreateDevLdapAuthMethod(ctx); err != nil {
t.Fatal(err)
}
}
if !opts.DisableScopesCreation {
if _, _, err := tc.b.CreateInitialScopes(ctx); err != nil {
t.Fatal(err)
@@ -740,6 +759,9 @@ func TestControllerConfig(t testing.TB, ctx context.Context, tc *TestController,
if opts.DisableOidcAuthMethodCreation {
createOpts = append(createOpts, base.WithSkipOidcAuthMethodCreation())
}
if opts.DisableOidcAuthMethodCreation {
createOpts = append(createOpts, base.WithSkipLdapAuthMethodCreation())
}
if !opts.DisableDatabaseTemplate {
createOpts = append(createOpts, base.WithDatabaseTemplate("boundary_template"))
}
@@ -764,6 +786,7 @@ func (tc *TestController) AddClusterControllerMember(t testing.TB, opts *TestCon
DatabaseUrl: tc.c.conf.DatabaseUrl,
DefaultPasswordAuthMethodId: tc.c.conf.DevPasswordAuthMethodId,
DefaultOidcAuthMethodId: tc.c.conf.DevOidcAuthMethodId,
DefaultLdapAuthMethodId: tc.c.conf.DevLdapAuthMethodId,
RootKms: tc.c.conf.RootKms,
WorkerAuthKms: tc.c.conf.WorkerAuthKms,
DownstreamWorkerAuthKms: tc.c.conf.DownstreamWorkerAuthKms,
@@ -5,11 +5,16 @@ package controller
import (
"bytes"
"context"
"io"
"os"
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/ldap"
"github.com/hashicorp/boundary/internal/db"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_TestController(t *testing.T) {
@@ -65,4 +70,19 @@ func Test_TestController(t *testing.T) {
defer tc.Shutdown()
}))
})
t.Run("set-default-ldap-auth-method-id", func(t *testing.T) {
t.Parallel()
assert, require := assert.New(t), require.New(t)
testCtx := context.Background()
testLdapAuthMethodId := globals.LdapAuthMethodPrefix + "_0123456789"
tc := NewTestController(t, &TestControllerOpts{DefaultLdapAuthMethodId: testLdapAuthMethodId})
defer tc.Shutdown()
testRw := db.New(tc.DbConn())
testLdapRepo, err := ldap.NewRepository(testCtx, testRw, testRw, tc.c.kms)
require.NoError(err)
got, err := testLdapRepo.LookupAuthMethod(testCtx, testLdapAuthMethodId)
require.NoError(err)
assert.Equal(testLdapAuthMethodId, got.GetPublicId())
})
}