Managed Groups OIDC Repo (#1254)
This commit is contained in:
1 parent
15bd1a5245
commit
7da892a054
17 files changed
+1660
-45
No files matched your search
@@ -119,8 +119,10 @@ func (b *Server) CreateDevDatabase(ctx context.Context, opt ...Option) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := b.CreateDevOidcAuthMethod(ctx); err != nil {
|
||||
return err
|
||||
if !opts.withSkipOidcAuthMethodCreation {
|
||||
if err := b.CreateDevOidcAuthMethod(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if opts.withSkipScopesCreation {
|
||||
@@ -225,7 +227,7 @@ func (b *Server) CreateDevOidcAuthMethod(ctx context.Context) error {
|
||||
// re-use it. This is a sort of hacky way to get around the chicken and egg
|
||||
// of the auth method needing to know the discovery URL and the test
|
||||
// provider needing to know the callback URL.
|
||||
l, err := net.Listen("tcp", fmt.Sprintf("%s:0", b.DevOidcSetup.hostAddr))
|
||||
l, err := net.Listen("tcp", net.JoinHostPort(b.DevOidcSetup.hostAddr, "0"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error finding port for oidc test provider: %w", err)
|
||||
}
|
||||
@@ -233,7 +235,7 @@ func (b *Server) CreateDevOidcAuthMethod(ctx context.Context) error {
|
||||
if err := l.Close(); err != nil {
|
||||
return fmt.Errorf("error closing initial test port: %w", err)
|
||||
}
|
||||
b.DevOidcSetup.callbackUrl, err = url.Parse(fmt.Sprintf("http://%s:%s", b.DevOidcSetup.hostAddr, b.DevOidcSetup.callbackPort))
|
||||
b.DevOidcSetup.callbackUrl, err = url.Parse(fmt.Sprintf("http://%s", net.JoinHostPort(b.DevOidcSetup.hostAddr, b.DevOidcSetup.callbackPort)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing oidc test provider callback url: %w", err)
|
||||
}
|
||||
|
||||
+19
-10
@@ -14,15 +14,16 @@ type Option func(*Options)
|
||||
|
||||
// Options - how Options are represented.
|
||||
type Options struct {
|
||||
withNoTokenScope bool
|
||||
withNoTokenValue bool
|
||||
withSkipDatabaseDestruction bool
|
||||
withSkipAuthMethodCreation bool
|
||||
withSkipScopesCreation bool
|
||||
withSkipHostResourcesCreation bool
|
||||
withSkipTargetCreation bool
|
||||
withContainerImage string
|
||||
withDialect string
|
||||
withNoTokenScope bool
|
||||
withNoTokenValue bool
|
||||
withSkipDatabaseDestruction bool
|
||||
withSkipAuthMethodCreation bool
|
||||
withSkipOidcAuthMethodCreation bool
|
||||
withSkipScopesCreation bool
|
||||
withSkipHostResourcesCreation bool
|
||||
withSkipTargetCreation bool
|
||||
withContainerImage string
|
||||
withDialect string
|
||||
}
|
||||
|
||||
func getDefaultOptions() Options {
|
||||
@@ -57,7 +58,7 @@ func WithNoTokenValue() Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithSkipAuthMethodCreation tells the command not to instantiate an auth
|
||||
// WithSkipAuthMethodCreation tells the command not to instantiate any auth
|
||||
// method on first run.
|
||||
func WithSkipAuthMethodCreation() Option {
|
||||
return func(o *Options) {
|
||||
@@ -65,6 +66,14 @@ func WithSkipAuthMethodCreation() Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithSkipOidcAuthMethodCreation tells the command not to instantiate an OIDC auth
|
||||
// method on first run, useful in some tests.
|
||||
func WithSkipOidcAuthMethodCreation() Option {
|
||||
return func(o *Options) {
|
||||
o.withSkipOidcAuthMethodCreation = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithSkipScopesCreation tells the command not to instantiate scopes on first
|
||||
// run.
|
||||
func WithSkipScopesCreation() Option {
|
||||
|
||||
@@ -36,8 +36,7 @@ func testServerCommand(t *testing.T, controllerKey string) *Command {
|
||||
require.NoError(err)
|
||||
require.NoError(cmd.SetupKMSes(cmd.UI, parsedKmsConfig))
|
||||
|
||||
opts := base.WithContainerImage("postgres")
|
||||
err = cmd.CreateDevDatabase(cmd.Context, opts)
|
||||
err = cmd.CreateDevDatabase(cmd.Context, base.WithContainerImage("postgres"), base.WithSkipOidcAuthMethodCreation())
|
||||
if err != nil {
|
||||
if cmd.DevDatabaseCleanupFunc != nil {
|
||||
require.NoError(cmd.DevDatabaseCleanupFunc())
|
||||
|
||||
Reference in new issue
Block a user