diff --git a/checker/definition.go b/checker/definition.go index 7d26d4a..ecd4e6c 100644 --- a/checker/definition.go +++ b/checker/definition.go @@ -34,8 +34,8 @@ func Definition() *sdk.CheckerDefinition { Id: "mode", Type: "string", Label: "Mode", - Default: string(ModeBoth), - Choices: validModes, + Default: "both", + Choices: []string{"c2s", "s2s", "both"}, }, { Id: "timeout", diff --git a/checker/interactive.go b/checker/interactive.go index 561ee91..02c44b4 100644 --- a/checker/interactive.go +++ b/checker/interactive.go @@ -3,7 +3,6 @@ package checker import ( "errors" "net/http" - "slices" "strconv" "strings" @@ -24,8 +23,8 @@ func (p *xmppProvider) RenderForm() []sdk.CheckerOptionField { Id: "mode", Type: "string", Label: "Mode", - Default: string(ModeBoth), - Choices: validModes, + Default: "both", + Choices: []string{"c2s", "s2s", "both"}, }, { Id: "timeout", @@ -47,10 +46,12 @@ func (p *xmppProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error) { opts := sdk.CheckerOptions{"domain": domain} if mode := strings.TrimSpace(r.FormValue("mode")); mode != "" { - if !slices.Contains(validModes, mode) { + switch mode { + case "c2s", "s2s", "both": + opts["mode"] = mode + default: return nil, errors.New("mode must be one of: c2s, s2s, both") } - opts["mode"] = mode } if to := strings.TrimSpace(r.FormValue("timeout")); to != "" { diff --git a/checker/rule.go b/checker/rule.go index 3b0886c..8c5853a 100644 --- a/checker/rule.go +++ b/checker/rule.go @@ -3,7 +3,6 @@ package checker import ( "context" "fmt" - "slices" "strings" sdk "git.happydns.org/checker-sdk-go/checker" @@ -25,7 +24,7 @@ func (r *xmppRule) Description() string { func (r *xmppRule) ValidateOptions(opts sdk.CheckerOptions) error { if v, ok := opts["mode"]; ok { - if s, ok := v.(string); ok && s != "" && !slices.Contains(validModes, s) { + if s, ok := v.(string); ok && s != "" && s != "c2s" && s != "s2s" && s != "both" { return fmt.Errorf(`mode must be "c2s", "s2s", or "both"`) } } diff --git a/checker/tls_related_test.go b/checker/tls_related_test.go index dbd3a46..13e13c0 100644 --- a/checker/tls_related_test.go +++ b/checker/tls_related_test.go @@ -57,8 +57,7 @@ func TestRule_FoldsTLSCritIntoAggregate(t *testing.T) { }), }, } - states := (&xmppRule{}).Evaluate(context.Background(), obs, sdk.CheckerOptions{"domain": "example.com", "mode": "both"}) - state := states[0] + state := (&xmppRule{}).Evaluate(context.Background(), obs, sdk.CheckerOptions{"domain": "example.com", "mode": "both"}) if state.Status != sdk.StatusCrit { t.Fatalf("expected StatusCrit due to TLS chain invalid, got %s (%s)", state.Status, state.Message) } @@ -72,8 +71,7 @@ func TestRule_IgnoresUnrelatedTLSObs(t *testing.T) { xmpp: healthyXMPPData(), related: nil, } - states := (&xmppRule{}).Evaluate(context.Background(), obs, sdk.CheckerOptions{"domain": "example.com", "mode": "both"}) - state := states[0] + state := (&xmppRule{}).Evaluate(context.Background(), obs, sdk.CheckerOptions{"domain": "example.com", "mode": "both"}) if state.Status != sdk.StatusOK { t.Fatalf("expected StatusOK without related TLS issues, got %s (%s)", state.Status, state.Message) } diff --git a/checker/types.go b/checker/types.go index 94474b0..062717c 100644 --- a/checker/types.go +++ b/checker/types.go @@ -19,11 +19,8 @@ type XMPPMode string const ( ModeClient XMPPMode = "c2s" ModeServer XMPPMode = "s2s" - ModeBoth XMPPMode = "both" ) -var validModes = []string{string(ModeClient), string(ModeServer), string(ModeBoth)} - // XMPPData is the full observation stored per run. type XMPPData struct { Domain string `json:"domain"`