Skip to content

Commit

Permalink
Merge pull request #870 from mysteriumnetwork/empty-consumer-config-b…
Browse files Browse the repository at this point in the history
…ackport

OpenVPN not fail on empty consumer config
  • Loading branch information
zolia authored Apr 9, 2019
2 parents 3b73e07 + d929d76 commit 7f59138
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
14 changes: 9 additions & 5 deletions services/openvpn/service/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,16 @@ func (m *Manager) ProvideConfig(config json.RawMessage) (session.ServiceConfigur
log.Info(logPrefix, "Config provider not initialized")
return nil, nil, errors.New("Config provider not initialized")
}
var c openvpn_service.ConsumerConfig
error := json.Unmarshal(config, &c)
if error != nil {
return nil, nil, errors.Wrap(error, "parsing consumer config failed")

if config != nil && len(config) > 0 { // Older clients do not send any config, but we should keep back compatibility and not fail in this case.
var c openvpn_service.ConsumerConfig
err := json.Unmarshal(config, &c)
if err != nil {
return nil, nil, errors.Wrap(err, "parsing consumer config failed")
}
m.consumerConfig = c
}
m.consumerConfig = c

return m.vpnServiceConfigProvider.ProvideConfig(config)
}

Expand Down
20 changes: 20 additions & 0 deletions services/openvpn/service/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package service

import (
"encoding/json"
"testing"

"github.com/mysteriumnetwork/node/session"
"github.com/stretchr/testify/assert"
)

Expand All @@ -28,3 +30,21 @@ func TestManager_StopNotPanic(t *testing.T) {
err := m.Stop()
assert.NoError(t, err)
}

func TestManager_ProvideConfigNotFailOnEmptyConfig(t *testing.T) {
m := Manager{vpnServiceConfigProvider: &mockConfigProvider{}}
_, _, err := m.ProvideConfig([]byte(""))
assert.NoError(t, err)
}

func TestManager_ProvideConfigNotFailOnNilConfig(t *testing.T) {
m := Manager{vpnServiceConfigProvider: &mockConfigProvider{}}
_, _, err := m.ProvideConfig(nil)
assert.NoError(t, err)
}

type mockConfigProvider struct{}

func (cp *mockConfigProvider) ProvideConfig(consumerKey json.RawMessage) (session.ServiceConfiguration, session.DestroyCallback, error) {
return nil, nil, nil
}

0 comments on commit 7f59138

Please sign in to comment.