Skip to content

Commit

Permalink
fix: * is not allowed in Seconds field of replication cron setting
Browse files Browse the repository at this point in the history
Signed-off-by: Shengwen Yu <[email protected]>
  • Loading branch information
Shengwen Yu committed Jul 12, 2023
1 parent c707106 commit 05b20a8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/controller/replication/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func (p *Policy) Validate() error {
return errors.New(nil).WithCode(errors.BadRequestCode).
WithMessage("invalid cron string for scheduled trigger: %s", p.Trigger.Settings.Cron)
}
cronParts := strings.Split(p.Trigger.Settings.Cron, " ")
if cronParts[0] == "*" {
return errors.New(nil).WithCode(errors.BadRequestCode).WithMessage("* is not allowed for the Seconds field of the cron setting")
}
default:
return errors.New(nil).WithCode(errors.BadRequestCode).
WithMessage("invalid trigger type")
Expand Down
31 changes: 30 additions & 1 deletion src/controller/replication/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func TestValidate(t *testing.T) {
err = policy.Validate()
assert.True(errors.IsErr(err, errors.BadRequestCode))

// pass
// invalid cron: * is not allowed for the Seconds field of the cron setting
policy = &Policy{
Name: "policy01",
SrcRegistry: &model.Registry{
Expand All @@ -226,5 +226,34 @@ func TestValidate(t *testing.T) {
},
}
err = policy.Validate()
assert.True(errors.IsErr(err, errors.BadRequestCode))

// pass
policy = &Policy{
Name: "policy01",
SrcRegistry: &model.Registry{
ID: 0,
},
DestRegistry: &model.Registry{
ID: 1,
},
Filters: []*model.Filter{
{
Type: model.FilterTypeResource,
Value: "image",
},
{
Type: model.FilterTypeName,
Value: "library/**",
},
},
Trigger: &model.Trigger{
Type: model.TriggerTypeScheduled,
Settings: &model.TriggerSettings{
Cron: "0 * * * * *",
},
},
}
err = policy.Validate()
assert.Nil(err)
}

0 comments on commit 05b20a8

Please sign in to comment.