Skip to content

Commit b2b7a01

Browse files
committed
go/config: Allow only clients and observers to use remote storage
1 parent 8b92f56 commit b2b7a01

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

go/config/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ func (c *Config) Validate() error {
8787
return fmt.Errorf("unknown node mode: %s", c.Mode)
8888
}
8989

90+
if !c.Consensus.LocalStorage {
91+
if c.Consensus.Validator {
92+
return fmt.Errorf("local storage not available in specified mode")
93+
}
94+
switch c.Mode {
95+
case ModeClient, ModeObserver:
96+
default:
97+
return fmt.Errorf("local storage not available in specified mode")
98+
}
99+
}
100+
90101
if err = c.Common.Validate(); err != nil {
91102
return fmt.Errorf("common: %w", err)
92103
}

go/config/config_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package config
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestRemoteStorageValidation(t *testing.T) {
10+
for _, tc := range []struct {
11+
name string
12+
mode NodeMode
13+
validator bool
14+
mustErr bool
15+
}{
16+
{name: "client", mode: ModeClient},
17+
{name: "observer", mode: ModeObserver},
18+
{name: "validator", mode: ModeValidator, mustErr: true},
19+
{name: "compute", mode: ModeCompute, mustErr: true},
20+
{name: "keymanager", mode: ModeKeyManager, mustErr: true},
21+
{name: "seed", mode: ModeSeed, mustErr: true},
22+
{name: "archive", mode: ModeArchive, mustErr: true},
23+
{name: "consensus validator and observer", mode: ModeObserver, validator: true, mustErr: true},
24+
} {
25+
t.Run(tc.name, func(t *testing.T) {
26+
cfg := DefaultConfig()
27+
cfg.Mode = tc.mode
28+
cfg.Consensus.LocalStorage = false
29+
cfg.Consensus.Validator = tc.validator
30+
31+
err := cfg.Validate()
32+
if tc.mustErr {
33+
require.ErrorContains(t, err, "local storage not available in specified mode")
34+
} else {
35+
require.NoError(t, err)
36+
}
37+
})
38+
}
39+
}

0 commit comments

Comments
 (0)