mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-15 01:57:45 +02:00
zero/bootstrap: reset back to inmem databroker if connection string is empty (#4955)
This commit is contained in:
parent
9d0e727e4d
commit
7edd538be7
2 changed files with 72 additions and 1 deletions
|
@ -83,7 +83,10 @@ func (src *source) notifyListeners(ctx context.Context, cfg *config.Config) {
|
||||||
|
|
||||||
func applyBootstrapConfig(dst *config.Options, src *cluster_api.BootstrapConfig) {
|
func applyBootstrapConfig(dst *config.Options, src *cluster_api.BootstrapConfig) {
|
||||||
if src.DatabrokerStorageConnection != nil {
|
if src.DatabrokerStorageConnection != nil {
|
||||||
dst.DataBrokerStorageType = "postgres"
|
dst.DataBrokerStorageType = config.StoragePostgresName
|
||||||
dst.DataBrokerStorageConnectionString = *src.DatabrokerStorageConnection
|
dst.DataBrokerStorageConnectionString = *src.DatabrokerStorageConnection
|
||||||
|
} else {
|
||||||
|
dst.DataBrokerStorageType = config.StorageInMemoryName
|
||||||
|
dst.DataBrokerStorageConnectionString = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
68
internal/zero/bootstrap/source_test.go
Normal file
68
internal/zero/bootstrap/source_test.go
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
package bootstrap_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/pomerium/pomerium/config"
|
||||||
|
"github.com/pomerium/pomerium/internal/zero/bootstrap"
|
||||||
|
cluster_api "github.com/pomerium/pomerium/pkg/zero/cluster"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConfigChanges(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
secret := []byte("secret")
|
||||||
|
|
||||||
|
src, err := bootstrap.New(secret)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
ptr := func(s string) *string { return &s }
|
||||||
|
|
||||||
|
var listenerCalled bool
|
||||||
|
src.OnConfigChange(nil, func(_ context.Context, _ *config.Config) {
|
||||||
|
listenerCalled = true
|
||||||
|
})
|
||||||
|
|
||||||
|
for i, tc := range []struct {
|
||||||
|
bootstrap cluster_api.BootstrapConfig
|
||||||
|
expectChanged bool
|
||||||
|
expectDatabrokerType string
|
||||||
|
expectDatabrokerConnectionString string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
cluster_api.BootstrapConfig{},
|
||||||
|
false,
|
||||||
|
config.StorageInMemoryName,
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cluster_api.BootstrapConfig{
|
||||||
|
DatabrokerStorageConnection: ptr("postgres://"),
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
config.StoragePostgresName,
|
||||||
|
"postgres://",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cluster_api.BootstrapConfig{},
|
||||||
|
true,
|
||||||
|
config.StorageInMemoryName,
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(fmt.Sprintf("test-%d", i), func(t *testing.T) {
|
||||||
|
listenerCalled = false
|
||||||
|
changed := src.UpdateBootstrap(context.Background(), tc.bootstrap)
|
||||||
|
cfg := src.GetConfig()
|
||||||
|
assert.Equal(t, tc.expectChanged, changed, "changed")
|
||||||
|
assert.Equal(t, tc.expectChanged, listenerCalled, "listenerCalled")
|
||||||
|
assert.Equal(t, tc.expectDatabrokerType, cfg.Options.DataBrokerStorageType, "databroker type")
|
||||||
|
assert.Equal(t, tc.expectDatabrokerConnectionString, cfg.Options.DataBrokerStorageConnectionString, "databroker connection string")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue