Fix pre-shared key not persistent (#1011)

* update pre-shared key if new key is not empty

* add unit test for empty pre-shared key
This commit is contained in:
Bethuel Mmbaga
2023-07-13 11:49:15 +03:00
committed by GitHub
parent f40951cdf5
commit 5cb9a126f1
2 changed files with 22 additions and 5 deletions

View File

@ -215,10 +215,12 @@ func update(input ConfigInput) (*Config, error) {
} }
if input.PreSharedKey != nil && config.PreSharedKey != *input.PreSharedKey { if input.PreSharedKey != nil && config.PreSharedKey != *input.PreSharedKey {
log.Infof("new pre-shared key provided, updated to %s (old value %s)", if *input.PreSharedKey != "" {
*input.PreSharedKey, config.PreSharedKey) log.Infof("new pre-shared key provides, updated to %s (old value %s)",
config.PreSharedKey = *input.PreSharedKey *input.PreSharedKey, config.PreSharedKey)
refresh = true config.PreSharedKey = *input.PreSharedKey
refresh = true
}
} }
if config.SSHKey == "" { if config.SSHKey == "" {

View File

@ -63,7 +63,22 @@ func TestGetConfig(t *testing.T) {
assert.Equal(t, config.ManagementURL.String(), managementURL) assert.Equal(t, config.ManagementURL.String(), managementURL)
assert.Equal(t, config.PreSharedKey, preSharedKey) 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" newManagementURL := "https://test.newManagement.url:33071"
config, err = UpdateOrCreateConfig(ConfigInput{ config, err = UpdateOrCreateConfig(ConfigInput{
ManagementURL: newManagementURL, ManagementURL: newManagementURL,