mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-30 14:40:15 +02:00
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:
@ -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 == "" {
|
||||||
|
@ -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,
|
||||||
|
Reference in New Issue
Block a user