fix(maintenance): validate maintenance windows for external, DNS and SSH endpoints (#1804)

* fix(maintenance): validate maintenance windows for external, DNS and SSH endpoints

ExternalEndpoint.ValidateAndSetDefaults never called
maintenance.Config.ValidateAndSetDefaults, so the window's start time and
timezone were never parsed. IsUnderMaintenance then treated every window as
starting at midnight in the server's local timezone, so alerts were still
sent during the configured window.

Endpoint.ValidateAndSetDefaults had the same problem for DNS and SSH
endpoints, which returned before reaching the maintenance window loop. The
loop now runs before those early returns.

Fixes #1551

Made by an AI agent (Claude Code, model Claude Opus 5).

* test(api): assert external endpoint maintenance window suppresses alerting

Pushes a failing result for an external endpoint whose maintenance window
(Europe/Berlin) is currently active and checks that alerting is skipped,
exercising the same maintenance check CreateExternalEndpointResult uses.

---------

Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
Anand HegdeandTwiN authored and GitHub committed 2026-09-30 09:32:30 -04:00
1 parent ae605f2919
commit 884f64d8e6
5 files changed
+152 -5

No files matched your search

+27
View File
@@ -114,6 +114,33 @@ func TestExternalEndpoint_ValidateAndSetDefaults(t *testing.T) {
}
}
func TestExternalEndpoint_ValidateAndSetDefaultsWithMaintenanceWindow(t *testing.T) {
t.Run("invalid-maintenance-window", func(t *testing.T) {
externalEndpoint := &ExternalEndpoint{
Name: "test-endpoint",
Token: "valid-token",
MaintenanceWindows: []*maintenance.Config{{Start: "25:00", Duration: time.Hour}},
}
if err := externalEndpoint.ValidateAndSetDefaults(); err == nil {
t.Error("expected an error because the maintenance window has an invalid start, got none")
}
})
t.Run("under-maintenance", func(t *testing.T) {
window := newMaintenanceWindowThatStartedAMinuteAgo(t, "Europe/Berlin")
externalEndpoint := &ExternalEndpoint{
Name: "test-endpoint",
Token: "valid-token",
MaintenanceWindows: []*maintenance.Config{window},
}
if err := externalEndpoint.ValidateAndSetDefaults(); err != nil {
t.Fatal("did not expect an error, got", err)
}
if !externalEndpoint.MaintenanceWindows[0].IsUnderMaintenance() {
t.Errorf("expected external endpoint to be under maintenance (window starting at %s %s)", window.Start, window.Timezone)
}
})
}
func TestExternalEndpoint_IsEnabled(t *testing.T) {
tests := []struct {
name string