Skip to content

Commit af13b0d

Browse files
committedJul 14, 2024·
adds tests for handling of Helm index with broken chart versions #13176
Signed-off-by: ricardo.bartels@telekom.de <ricardo.bartels@telekom.de>
1 parent 154b477 commit af13b0d

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
 

‎pkg/repo/index_test.go

+74
Original file line numberDiff line numberDiff line change
@@ -644,3 +644,77 @@ func TestIgnoreSkippableChartValidationError(t *testing.T) {
644644
})
645645
}
646646
}
647+
648+
var indexWithDuplicatesInChartDeps = `
649+
apiVersion: v1
650+
entries:
651+
nginx:
652+
- urls:
653+
- https://charts.helm.sh/stable/alpine-1.0.0.tgz
654+
- http://storage2.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
655+
name: alpine
656+
description: string
657+
home: https://github.com/something
658+
digest: "sha256:1234567890abcdef"
659+
- urls:
660+
- https://charts.helm.sh/stable/nginx-0.2.0.tgz
661+
name: nginx
662+
description: string
663+
version: 0.2.0
664+
home: https://github.com/something/else
665+
digest: "sha256:1234567890abcdef"
666+
`
667+
var indexWithDuplicatesInLastChartDeps = `
668+
apiVersion: v1
669+
entries:
670+
nginx:
671+
- urls:
672+
- https://charts.helm.sh/stable/nginx-0.2.0.tgz
673+
name: nginx
674+
description: string
675+
version: 0.2.0
676+
home: https://github.com/something/else
677+
digest: "sha256:1234567890abcdef"
678+
- urls:
679+
- https://charts.helm.sh/stable/alpine-1.0.0.tgz
680+
- http://storage2.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
681+
name: alpine
682+
description: string
683+
home: https://github.com/something
684+
digest: "sha256:111"
685+
`
686+
687+
func TestLoadIndex_DuplicateChartDeps(t *testing.T) {
688+
tests := []struct {
689+
source string
690+
data string
691+
}{
692+
{
693+
source: "indexWithDuplicatesInChartDeps",
694+
data: indexWithDuplicatesInChartDeps,
695+
},
696+
{
697+
source: "indexWithDuplicatesInLastChartDeps",
698+
data: indexWithDuplicatesInLastChartDeps,
699+
},
700+
}
701+
for _, tc := range tests {
702+
t.Run(tc.source, func(t *testing.T) {
703+
idx, err := loadIndex([]byte(tc.data), tc.source)
704+
if err != nil {
705+
t.Fatalf("unexpected error: %s", err)
706+
}
707+
cvs := idx.Entries["nginx"]
708+
if cvs == nil {
709+
if err != nil {
710+
t.Error("expected one chart version not to be filtered out")
711+
}
712+
}
713+
for _, v := range cvs {
714+
if v.Name == "alpine" {
715+
t.Error("malformed version was not filtered out")
716+
}
717+
}
718+
})
719+
}
720+
}

0 commit comments

Comments
 (0)
Please sign in to comment.