Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve errors when decoding tokens #838

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
. "github.com/onsi/gomega"

"github.com/mudler/edgevpn/pkg/blockchain"
"github.com/mudler/edgevpn/pkg/discovery"
"github.com/mudler/edgevpn/pkg/logger"
. "github.com/mudler/edgevpn/pkg/node"
)
Expand All @@ -33,11 +34,17 @@ var _ = Describe("Node", func() {

l := Logger(logger.New(log.LevelFatal))

Context("Configuration", func() {
Context("Node configuration validation", func() {
It("fails if is not valid", func() {
_, err := New(FromBase64(true, true, " ", nil, nil), WithStore(&blockchain.MemoryStore{}), l)
_, err := New(FromBase64(true, true, " ", &discovery.DHT{}, &discovery.MDNS{}), WithStore(&blockchain.MemoryStore{}), l)
Expect(err).To(HaveOccurred())

_, err = New(FromBase64(true, true, token, nil, nil), WithStore(&blockchain.MemoryStore{}), l)
Expect(err).To(HaveOccurred())
})

It("passes if when valid", func() {
_, err := New(FromBase64(true, true, token, &discovery.DHT{}, &discovery.MDNS{}), WithStore(&blockchain.MemoryStore{}), l)
Expect(err).ToNot(HaveOccurred())
})
})
Expand Down
14 changes: 7 additions & 7 deletions pkg/node/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ func (y YAMLConnectionConfig) YAML() string {
return string(bytesData)
}

func (y YAMLConnectionConfig) copy(mdns, dht bool, cfg *Config, d *discovery.DHT, m *discovery.MDNS) {
func (y YAMLConnectionConfig) copy(mdns, dht bool, cfg *Config, d *discovery.DHT, m *discovery.MDNS) error {
if d == nil {
d = discovery.NewDHT()
return errors.New("DHT is nil")
}
if m == nil {
m = &discovery.MDNS{}
return errors.New("MDNS is nil")
}

d.RefreshDiscoveryTime = cfg.DiscoveryInterval
Expand All @@ -301,6 +301,8 @@ func (y YAMLConnectionConfig) copy(mdns, dht bool, cfg *Config, d *discovery.DHT
}
cfg.SealKeyLength = y.OTP.Crypto.Length
cfg.MaxMessageSize = y.MaxMessageSize

return nil
}

const defaultKeyLength = 43
Expand Down Expand Up @@ -357,8 +359,7 @@ func FromYaml(enablemDNS, enableDHT bool, path string, d *discovery.DHT, m *disc
return errors.Wrap(err, "parsing yaml")
}

t.copy(enablemDNS, enableDHT, cfg, d, m)
return nil
return t.copy(enablemDNS, enableDHT, cfg, d, m)
}
}

Expand All @@ -376,7 +377,6 @@ func FromBase64(enablemDNS, enableDHT bool, bb string, d *discovery.DHT, m *disc
if err := yaml.Unmarshal(configDec, &t); err != nil {
return errors.Wrap(err, "parsing yaml")
}
t.copy(enablemDNS, enableDHT, cfg, d, m)
return nil
return t.copy(enablemDNS, enableDHT, cfg, d, m)
}
}
Loading