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",
Type: "string",
Label: "Mode",
Default: "both",
Choices: []string{"c2s", "s2s", "both"},
Default: string(ModeBoth),
Choices: validModes,
},
{
Id: "timeout",

View file

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

View file

@ -3,6 +3,7 @@ package checker
import (
"context"
"fmt"
"slices"
"strings"
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 {
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"`)
}
}

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 {
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(),
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 {
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 (
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"`