Fix: trust-all remained enabled always

This commit is contained in:
Hector Sanjuan 2019-08-27 13:27:52 +02:00
parent 1cfea47696
commit 8ca0f5781c
2 changed files with 16 additions and 2 deletions

View File

@ -105,6 +105,10 @@ func (cfg *Config) LoadJSON(raw []byte) error {
func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error { func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
config.SetIfNotDefault(jcfg.ClusterName, &cfg.ClusterName) 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 { for _, p := range jcfg.TrustedPeers {
if p == "*" { if p == "*" {
cfg.TrustAll = true cfg.TrustAll = true

View File

@ -18,8 +18,8 @@ func TestLoadJSON(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if cfg.TrustAll != DefaultTrustAll { if cfg.TrustAll {
t.Error("expected TrustAll to be the default") t.Error("TrustAll should not be enabled when peers in trusted peers")
} }
cfg = &Config{} cfg = &Config{}
@ -36,6 +36,16 @@ func TestLoadJSON(t *testing.T) {
cfg = &Config{} cfg = &Config{}
err = cfg.LoadJSON([]byte(` 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", "cluster_name": "test",
"trusted_peers": ["QmUZ13osndQ5uL4tPWHXe3iBgBgq9gfewcBMSCAuMBsDJ6", "*"] "trusted_peers": ["QmUZ13osndQ5uL4tPWHXe3iBgBgq9gfewcBMSCAuMBsDJ6", "*"]
}`)) }`))