Skip to content

Commit

Permalink
Fix pre-shared key not persistent (netbirdio#1011)
Browse files Browse the repository at this point in the history
* update pre-shared key if new key is not empty

* add unit test for empty pre-shared key
  • Loading branch information
bcmmbaga authored and surik committed Aug 14, 2023
1 parent 8d36b71 commit 0cae433
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 6 additions & 4 deletions client/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
17 changes: 16 additions & 1 deletion client/internal/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0cae433

Please sign in to comment.