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

Fix: trust-all remained enabled always #905

Merged
merged 1 commit into from Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions consensus/crdt/config.go
Expand Up @@ -105,6 +105,10 @@ func (cfg *Config) LoadJSON(raw []byte) error {

func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
config.SetIfNotDefault(jcfg.ClusterName, &cfg.ClusterName)

// Whenever we parse JSON, TrustAll is false unless an '*' peer exists
cfg.TrustAll = false

for _, p := range jcfg.TrustedPeers {
if p == "*" {
cfg.TrustAll = true
Expand Down
14 changes: 12 additions & 2 deletions consensus/crdt/config_test.go
Expand Up @@ -18,8 +18,8 @@ func TestLoadJSON(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if cfg.TrustAll != DefaultTrustAll {
t.Error("expected TrustAll to be the default")
if cfg.TrustAll {
t.Error("TrustAll should not be enabled when peers in trusted peers")
}

cfg = &Config{}
Expand All @@ -36,6 +36,16 @@ func TestLoadJSON(t *testing.T) {
cfg = &Config{}
err = cfg.LoadJSON([]byte(`
{
"cluster_name": "test",
"trusted_peers": []
}`))
if cfg.TrustAll {
t.Error("TrustAll is only enabled with '*'")
}

cfg = &Config{}
err = cfg.LoadJSON([]byte(`
{
"cluster_name": "test",
"trusted_peers": ["QmUZ13osndQ5uL4tPWHXe3iBgBgq9gfewcBMSCAuMBsDJ6", "*"]
}`))
Expand Down