Skip to content

Commit

Permalink
add nil judge for dependency , maintainers validate and some testcase.
Browse files Browse the repository at this point in the history
Signed-off-by: wujunwei <wjw3323@live.com>
(cherry picked from commit a7a1117)
  • Loading branch information
wujunwei authored and mattfarina committed Oct 12, 2022
1 parent 4e07531 commit f22e260
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/chart/dependency.go
Expand Up @@ -53,6 +53,9 @@ type Dependency struct {
// the chart. This check must be done at load time before the dependency's charts are
// loaded.
func (d *Dependency) Validate() error {
if d == nil {
return ValidationError("the dependency's item can not be nil")
}
d.Name = sanitizeString(d.Name)
d.Version = sanitizeString(d.Version)
d.Repository = sanitizeString(d.Repository)
Expand Down
3 changes: 3 additions & 0 deletions pkg/chart/metadata.go
Expand Up @@ -34,6 +34,9 @@ type Maintainer struct {

// Validate checks valid data and sanitizes string characters.
func (m *Maintainer) Validate() error {
if m == nil {
return ValidationError("the maintainer's item can not be nil")
}
m.Name = sanitizeString(m.Name)
m.Email = sanitizeString(m.Email)
m.URL = sanitizeString(m.URL)
Expand Down
24 changes: 24 additions & 0 deletions pkg/chart/metadata_test.go
Expand Up @@ -72,6 +72,30 @@ func TestValidate(t *testing.T) {
},
ValidationError("dependency \"bad\" has disallowed characters in the alias"),
},
{
&Metadata{
Name: "test",
APIVersion: "v2",
Version: "1.0",
Type: "application",
Dependencies: []*Dependency{
nil,
},
},
ValidationError("the dependency's item can not be nil"),
},
{
&Metadata{
Name: "test",
APIVersion: "v2",
Version: "1.0",
Type: "application",
Maintainers: []*Maintainer{
nil,
},
},
ValidationError("the maintainer's item can not be nil"),
},
{
&Metadata{APIVersion: "v2", Name: "test", Version: "1.2.3.4"},
ValidationError("chart.metadata.version \"1.2.3.4\" is invalid"),
Expand Down

0 comments on commit f22e260

Please sign in to comment.