Skip to content

Commit

Permalink
Fix the data dir for tests (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmb3 committed Oct 31, 2024
1 parent c1f368e commit 42c91a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6135,8 +6135,12 @@ func warnOnErr(ctx context.Context, err error, log *slog.Logger) {
// initAuthStorage initializes the storage backend for the auth service.
func (process *TeleportProcess) initAuthStorage() (backend.Backend, error) {
ctx := context.TODO()
process.logger.DebugContext(process.ExitContext(), "Initializing auth backend.", "backend", process.Config.Auth.StorageConfig.Type)
bc := process.Config.Auth.StorageConfig
process.logger.DebugContext(process.ExitContext(), "Initializing auth backend.",
"backend", process.Config.Auth.StorageConfig.Type,
"type", bc.Type,
"params", bc.Params,
)
bk, err := backend.New(ctx, bc.Type, bc.Params)
if err != nil {
return nil, trace.Wrap(err)
Expand Down
1 change: 1 addition & 0 deletions lib/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func TestDynamicClientReuse(t *testing.T) {
cfg.DiagnosticAddr = utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"}
cfg.SetAuthServerAddress(utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"})
cfg.Auth.Enabled = true
// cfg.Auth.StorageConfig.Params[defaults.BackendPath] = filepath.Join(cfg.DataDir, "backend")
cfg.Auth.ListenAddr = utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"}
cfg.Auth.SessionRecordingConfig.SetMode(types.RecordOff)
cfg.Proxy.Enabled = true
Expand Down
10 changes: 10 additions & 0 deletions lib/service/servicecfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,16 @@ func ValidateConfig(cfg *Config) error {

cfg.SSH.Namespace = types.ProcessNamespace(cfg.SSH.Namespace)

// If we've overridden the process's data dir, but left auth's backend
// pointing at the default data dir this is probably a test that forgot
// to customize the auth storage config. Fix it.
if cfg.Auth.Enabled && cfg.Auth.StorageConfig.Type == lite.GetName() {
storagePath := cfg.Auth.StorageConfig.Params.GetString(defaults.BackendPath)
if storagePath == filepath.Join(defaults.DataDir, defaults.BackendDir) && cfg.DataDir != defaults.DataDir {
cfg.Auth.StorageConfig.Params[defaults.BackendPath] = filepath.Join(cfg.DataDir, defaults.BackendDir)
}
}

return nil
}

Expand Down

0 comments on commit 42c91a5

Please sign in to comment.