diff --git a/client/internal/config.go b/client/internal/config.go index c8edcfb88..cd665016b 100644 --- a/client/internal/config.go +++ b/client/internal/config.go @@ -215,10 +215,12 @@ func update(input ConfigInput) (*Config, error) { } if input.PreSharedKey != nil && config.PreSharedKey != *input.PreSharedKey { - log.Infof("new pre-shared key provided, updated to %s (old value %s)", - *input.PreSharedKey, config.PreSharedKey) - config.PreSharedKey = *input.PreSharedKey - refresh = true + if *input.PreSharedKey != "" { + log.Infof("new pre-shared key provides, updated to %s (old value %s)", + *input.PreSharedKey, config.PreSharedKey) + config.PreSharedKey = *input.PreSharedKey + refresh = true + } } if config.SSHKey == "" { diff --git a/client/internal/config_test.go b/client/internal/config_test.go index d4c207aed..25e8f7b2e 100644 --- a/client/internal/config_test.go +++ b/client/internal/config_test.go @@ -63,7 +63,22 @@ func TestGetConfig(t *testing.T) { assert.Equal(t, config.ManagementURL.String(), managementURL) assert.Equal(t, config.PreSharedKey, preSharedKey) - // case 4: existing config, but new managementURL has been provided -> update config + // case 4: new empty pre-shared key config -> fetch it + newPreSharedKey := "" + config, err = UpdateOrCreateConfig(ConfigInput{ + ManagementURL: managementURL, + AdminURL: adminURL, + ConfigPath: path, + PreSharedKey: &newPreSharedKey, + }) + if err != nil { + return + } + + assert.Equal(t, config.ManagementURL.String(), managementURL) + assert.Equal(t, config.PreSharedKey, preSharedKey) + + // case 5: existing config, but new managementURL has been provided -> update config newManagementURL := "https://test.newManagement.url:33071" config, err = UpdateOrCreateConfig(ConfigInput{ ManagementURL: newManagementURL,