Skip to content

Commit

Permalink
Merge pull request #905 from ipfs/fix/trust-all
Browse files Browse the repository at this point in the history
Fix: trust-all remained enabled always
  • Loading branch information
hsanjuan committed Aug 28, 2019
2 parents 1cfea47 + 8ca0f57 commit a958d81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit a958d81

Please sign in to comment.