Compare commits

...

No commits in common. "bda66e47ebbcd735e5341ad401ff7f0f4ef8117c" and "bed251bb7f96b42f35442b10f07582887809e5eb" have entirely different histories.

5 changed files with 16 additions and 11 deletions

View file

@ -34,8 +34,8 @@ func Definition() *sdk.CheckerDefinition {
Id: "mode", Id: "mode",
Type: "string", Type: "string",
Label: "Mode", Label: "Mode",
Default: "both", Default: string(ModeBoth),
Choices: []string{"c2s", "s2s", "both"}, Choices: validModes,
}, },
{ {
Id: "timeout", Id: "timeout",

View file

@ -3,6 +3,7 @@ package checker
import ( import (
"errors" "errors"
"net/http" "net/http"
"slices"
"strconv" "strconv"
"strings" "strings"
@ -23,8 +24,8 @@ func (p *xmppProvider) RenderForm() []sdk.CheckerOptionField {
Id: "mode", Id: "mode",
Type: "string", Type: "string",
Label: "Mode", Label: "Mode",
Default: "both", Default: string(ModeBoth),
Choices: []string{"c2s", "s2s", "both"}, Choices: validModes,
}, },
{ {
Id: "timeout", Id: "timeout",
@ -46,12 +47,10 @@ func (p *xmppProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error) {
opts := sdk.CheckerOptions{"domain": domain} opts := sdk.CheckerOptions{"domain": domain}
if mode := strings.TrimSpace(r.FormValue("mode")); mode != "" { if mode := strings.TrimSpace(r.FormValue("mode")); mode != "" {
switch mode { if !slices.Contains(validModes, mode) {
case "c2s", "s2s", "both":
opts["mode"] = mode
default:
return nil, errors.New("mode must be one of: c2s, s2s, both") return nil, errors.New("mode must be one of: c2s, s2s, both")
} }
opts["mode"] = mode
} }
if to := strings.TrimSpace(r.FormValue("timeout")); to != "" { if to := strings.TrimSpace(r.FormValue("timeout")); to != "" {

View file

@ -3,6 +3,7 @@ package checker
import ( import (
"context" "context"
"fmt" "fmt"
"slices"
"strings" "strings"
sdk "git.happydns.org/checker-sdk-go/checker" sdk "git.happydns.org/checker-sdk-go/checker"
@ -24,7 +25,7 @@ func (r *xmppRule) Description() string {
func (r *xmppRule) ValidateOptions(opts sdk.CheckerOptions) error { func (r *xmppRule) ValidateOptions(opts sdk.CheckerOptions) error {
if v, ok := opts["mode"]; ok { if v, ok := opts["mode"]; ok {
if s, ok := v.(string); ok && s != "" && s != "c2s" && s != "s2s" && s != "both" { if s, ok := v.(string); ok && s != "" && !slices.Contains(validModes, s) {
return fmt.Errorf(`mode must be "c2s", "s2s", or "both"`) return fmt.Errorf(`mode must be "c2s", "s2s", or "both"`)
} }
} }

View file

@ -57,7 +57,8 @@ func TestRule_FoldsTLSCritIntoAggregate(t *testing.T) {
}), }),
}, },
} }
state := (&xmppRule{}).Evaluate(context.Background(), obs, sdk.CheckerOptions{"domain": "example.com", "mode": "both"}) states := (&xmppRule{}).Evaluate(context.Background(), obs, sdk.CheckerOptions{"domain": "example.com", "mode": "both"})
state := states[0]
if state.Status != sdk.StatusCrit { if state.Status != sdk.StatusCrit {
t.Fatalf("expected StatusCrit due to TLS chain invalid, got %s (%s)", state.Status, state.Message) t.Fatalf("expected StatusCrit due to TLS chain invalid, got %s (%s)", state.Status, state.Message)
} }
@ -71,7 +72,8 @@ func TestRule_IgnoresUnrelatedTLSObs(t *testing.T) {
xmpp: healthyXMPPData(), xmpp: healthyXMPPData(),
related: nil, related: nil,
} }
state := (&xmppRule{}).Evaluate(context.Background(), obs, sdk.CheckerOptions{"domain": "example.com", "mode": "both"}) states := (&xmppRule{}).Evaluate(context.Background(), obs, sdk.CheckerOptions{"domain": "example.com", "mode": "both"})
state := states[0]
if state.Status != sdk.StatusOK { if state.Status != sdk.StatusOK {
t.Fatalf("expected StatusOK without related TLS issues, got %s (%s)", state.Status, state.Message) t.Fatalf("expected StatusOK without related TLS issues, got %s (%s)", state.Status, state.Message)
} }

View file

@ -19,8 +19,11 @@ type XMPPMode string
const ( const (
ModeClient XMPPMode = "c2s" ModeClient XMPPMode = "c2s"
ModeServer XMPPMode = "s2s" ModeServer XMPPMode = "s2s"
ModeBoth XMPPMode = "both"
) )
var validModes = []string{string(ModeClient), string(ModeServer), string(ModeBoth)}
// XMPPData is the full observation stored per run. // XMPPData is the full observation stored per run.
type XMPPData struct { type XMPPData struct {
Domain string `json:"domain"` Domain string `json:"domain"`