Skip to content

Commit

Permalink
Add ExpansionTemplate name length validation in code
Browse files Browse the repository at this point in the history
Signed-off-by: davis-haba <davishaba@google.com>
  • Loading branch information
davis-haba committed Oct 17, 2023
1 parent 2569748 commit d8654c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/expansion/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func ValidateTemplate(template *expansionunversioned.ExpansionTemplate) error {
if k == "" {
return fmt.Errorf("ExpansionTemplate has empty name field")
}
if len(k) > 64 {
return fmt.Errorf("ExpansionTemplate name must be less than 64 characters")
}
if template.Spec.TemplateSource == "" {
return fmt.Errorf("ExpansionTemplate %s has empty source field", k)
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/expansion/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,24 @@ func TestValidateTemplate(t *testing.T) {
}),
errFn: matchErr("empty name"),
},
{
name: "name too long",
temp: *fixtures.NewTemplate(&fixtures.TemplateData{
Name: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
Apply: []match.ApplyTo{{
Groups: []string{"apps"},
Kinds: []string{"Deployment"},
Versions: []string{"v1"},
}},
Source: "spec.template",
GenGVK: expansionunversioned.GeneratedGVK{
Group: "",
Version: "v1",
Kind: "Pod",
},
}),
errFn: matchErr("less than 64"),
},
{
name: "missing source",
temp: *fixtures.NewTemplate(&fixtures.TemplateData{
Expand Down

0 comments on commit d8654c5

Please sign in to comment.