fix(config): reject unsupported proxy modes

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 11:30:27 +00:00
parent 9e906d11f9
commit b63e7562de
3 changed files with 46 additions and 2 deletions

View file

@ -43,6 +43,11 @@ func (c *Config) Validate() error {
if len(c.Pools) == 0 {
return errors.New("pool list is empty")
}
switch c.Mode {
case "nicehash", "simple":
default:
return errors.New("unsupported mode")
}
for _, poolConfig := range c.Pools {
if poolConfig.Enabled && strings.TrimSpace(poolConfig.URL) == "" {

39
config_runtime_test.go Normal file
View file

@ -0,0 +1,39 @@
package proxy
import "testing"
func TestConfig_Validate_Good(t *testing.T) {
cfg := &Config{
Mode: "nicehash",
Bind: []BindAddr{{Host: "127.0.0.1", Port: 3333}},
Pools: []PoolConfig{{URL: "pool-a:3333", Enabled: true}},
}
if errorValue := cfg.Validate(); errorValue != nil {
t.Fatalf("expected valid config, got %v", errorValue)
}
}
func TestConfig_Validate_Bad(t *testing.T) {
cfg := &Config{
Mode: "noop",
Bind: []BindAddr{{Host: "127.0.0.1", Port: 3333}},
Pools: []PoolConfig{{URL: "pool-a:3333", Enabled: true}},
}
if errorValue := cfg.Validate(); errorValue == nil {
t.Fatal("expected unsupported mode to fail validation")
}
}
func TestConfig_Validate_Ugly(t *testing.T) {
cfg := &Config{
Mode: "simple",
Bind: []BindAddr{{Host: "127.0.0.1", Port: 3333}},
Pools: []PoolConfig{{Enabled: true}},
}
if errorValue := cfg.Validate(); errorValue == nil {
t.Fatal("expected empty enabled pool URL to fail validation")
}
}

View file

@ -4,7 +4,7 @@ import "testing"
func TestProxy_Reload_Good(t *testing.T) {
cfg := &Config{
Mode: "noop",
Mode: "nicehash",
Bind: []BindAddr{{Host: "127.0.0.1", Port: 3333}},
Pools: []PoolConfig{{URL: "pool-a:3333", Enabled: true}},
CustomDiff: 100,
@ -41,7 +41,7 @@ func TestProxy_Reload_Good(t *testing.T) {
func TestProxy_CurrentMiners_Good(t *testing.T) {
cfg := &Config{
Mode: "noop",
Mode: "nicehash",
Bind: []BindAddr{{Host: "127.0.0.1", Port: 3333}},
Pools: []PoolConfig{{URL: "pool-a:3333", Enabled: true}},
Workers: WorkersDisabled,