fix(git): add a minimum interval validation BE-12220 (#1144)

pull/12845/head
andres-portainer 2025-09-04 15:11:12 -03:00 committed by GitHub
parent 2ba348551d
commit f8ae5368bf
2 changed files with 18 additions and 4 deletions

View File

@ -21,10 +21,14 @@ func ValidateAutoUpdateSettings(autoUpdate *portainer.AutoUpdateSettings) error
return httperrors.NewInvalidPayloadError("invalid Webhook format") return httperrors.NewInvalidPayloadError("invalid Webhook format")
} }
if autoUpdate.Interval != "" { if autoUpdate.Interval == "" {
if _, err := time.ParseDuration(autoUpdate.Interval); err != nil { return nil
return httperrors.NewInvalidPayloadError("invalid Interval format") }
}
if d, err := time.ParseDuration(autoUpdate.Interval); err != nil {
return httperrors.NewInvalidPayloadError("invalid Interval format")
} else if d < time.Minute {
return httperrors.NewInvalidPayloadError("interval must be at least 1 minute")
} }
return nil return nil

View File

@ -23,6 +23,16 @@ func Test_ValidateAutoUpdate(t *testing.T) {
value: &portainer.AutoUpdateSettings{Interval: "1dd2hh3mm"}, value: &portainer.AutoUpdateSettings{Interval: "1dd2hh3mm"},
wantErr: true, wantErr: true,
}, },
{
name: "short interval value",
value: &portainer.AutoUpdateSettings{Interval: "1s"},
wantErr: true,
},
{
name: "valid webhook without interval",
value: &portainer.AutoUpdateSettings{Webhook: "8dce8c2f-9ca1-482b-ad20-271e86536ada"},
wantErr: false,
},
{ {
name: "valid auto update", name: "valid auto update",
value: &portainer.AutoUpdateSettings{ value: &portainer.AutoUpdateSettings{