Validate the federation tester URI placeholder, escape the domain, set a client timeout, cap the response body, and ship CA certificates in the scratch image so HTTPS calls succeed. Sort hosts, connection reports, and errors when rendering so output is deterministic, and deduplicate TLS problems. Drop the deprecated aggregate Rule() and add tests for collection and rules.
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package checker
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sort"
|
|
|
|
sdk "git.happydns.org/checker-sdk-go/checker"
|
|
)
|
|
|
|
// connectionReachableRule checks that every federation endpoint returned
|
|
// by DNS accepted the TLS connection the tester attempted.
|
|
type connectionReachableRule struct{}
|
|
|
|
func (r *connectionReachableRule) Name() string { return "matrix.connection_reachable" }
|
|
func (r *connectionReachableRule) Description() string {
|
|
return "Checks that every discovered federation endpoint accepts an inbound connection."
|
|
}
|
|
|
|
func (r *connectionReachableRule) Evaluate(ctx context.Context, obs sdk.ObservationGetter, _ sdk.CheckerOptions) []sdk.CheckState {
|
|
data, errSt := loadMatrixData(ctx, obs)
|
|
if errSt != nil {
|
|
return []sdk.CheckState{*errSt}
|
|
}
|
|
|
|
if len(data.ConnectionErrors) == 0 && len(data.ConnectionReports) == 0 {
|
|
return []sdk.CheckState{unknownState("matrix.connection_reachable.unknown", "No endpoint was probed by the federation tester.")}
|
|
}
|
|
|
|
if len(data.ConnectionErrors) == 0 {
|
|
return []sdk.CheckState{passState("matrix.connection_reachable.ok", fmt.Sprintf("All %d endpoint(s) accepted the connection.", len(data.ConnectionReports)))}
|
|
}
|
|
|
|
addrs := make([]string, 0, len(data.ConnectionErrors))
|
|
for addr := range data.ConnectionErrors {
|
|
addrs = append(addrs, addr)
|
|
}
|
|
sort.Strings(addrs)
|
|
|
|
out := make([]sdk.CheckState, 0, len(addrs))
|
|
for _, addr := range addrs {
|
|
st := critState("matrix.connection_reachable.fail", data.ConnectionErrors[addr].Message)
|
|
st.Subject = addr
|
|
out = append(out, st)
|
|
}
|
|
return out
|
|
}
|