8000 Fix for issue 8761 · helm/helm@d46f7bc · GitHub
[go: up one dir, main page]

Skip to content

Commit d46f7bc

Browse files
committed
Fix for issue 8761
Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
1 parent b9566b8 commit d46f7bc

File tree

3 files changed

+112
-26
lines changed

3 files changed

+112
-26
lines changed

pkg/repo/index.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ type IndexFile struct {
8686

8787
// IndexValidation is used to validate the integrity of an index file
8888
type IndexValidation struct {
89+
// This is used ONLY for validation against chartmuseum's index files and
90+
// is discarded after validation.
91+
ServerInfo map[string]interface{} `yaml:"serverInfo,omitempty"`
8992
APIVersion string `yaml:"apiVersion"`
9093
Generated time.Time `yaml:"generated"`
9194
Entries map[string]interface{} `yaml:"entries"`

pkg/repo/index_test.go

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,31 @@ import (
3030
)
3131

3232
const (
33-
testfile = "testdata/local-index.yaml"
34-
unorderedTestfile = "testdata/local-index-unordered.yaml"
35-
testRepo = "test-repo"
33+
testfile = "testdata/local-index.yaml"
34+
chartmuseumtestfile = "testdata/chartmuseum-index.yaml"
35+
unorderedTestfile = "testdata/local-index-unordered.yaml"
36+
testRepo = "test-repo"
37+
indexWithDuplicates = `
38+
apiVersion: v1
39+
entries:
40+
nginx:
41+
- urls:
42+
- https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz
43+
name: nginx
44+
description: string
45+
version: 0.2.0
46+
home: https://github.com/something/else
47+
digest: "sha256:1234567890abcdef"
48+
nginx:
49+
- urls:
50+
- https://kubernetes-charts.storage.googleapis.com/alpine-1.0.0.tgz
51+
- http://storage2.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
52+
name: alpine
53+
description: string
54+
version: 1.0.0
55+
home: https://github.com/something
56+
digest: "sha256:1234567890abcdef"
57+
`
3658
)
3759

3860
func TestIndexFile(t *testing.T) {
@@ -79,15 +101,42 @@ func TestIndexFile(t *testing.T) {
79101
}
80102

81103
func TestLoadIndex(t *testing.T) {
82-
b, err := ioutil.ReadFile(testfile)
83-
if err != nil {
84-
t.Fatal(err)
104+
tests := []struct {
105+
Name string
106+
Filename string
107+
}{
108+
{
109+
Name: "regular index file",
110+
Filename: testfile,
111+
},
112+
{
113+
Name: "chartmuseum index file",
114+
Filename: chartmuseumtestfile,
115+
},
85116
}
86-
i, err := loadIndex(b)
87-
if err != nil {
88-
t.Fatal(err)
117+
118+
for _, tc := range tests {
119+
tc := tc
120+
t.Run(tc.Name, func(t *testing.T) {
121+
t.Parallel()
122+
b, err := ioutil.ReadFile(tc.Filename)
123+
if err != nil {
124+
t.Fatal(err)
125+
}
126+
i, err := loadIndex(b)
127+
if err != nil {
128+
t.Fatal(err)
129+
}
130+
verifyLocalIndex(t, i)
131+
})
132+
}
133+
}
134+
135+
// TestLoadIndex_Duplicates is a regression to make sure that we don't non-deterministically allow duplicate packages.
136+
func TestLoadIndex_Duplicates(t *testing.T) {
137+
if _, err := loadIndex([]byte(indexWithDuplicates)); err == nil {
138+
t.Errorf("Expected an error when duplicate entries are present")
89139
}
90-
verifyLocalIndex(t, i)
91140
}
92141

93142
func TestLoadIndexFile(t *testing.T) {
@@ -422,19 +471,3 @@ func TestIndexAdd(t *testing.T) {
422471
t.Errorf("Expected http://example.com/charts/deis-0.1.0.tgz, got %s", i.Entries["deis"][0].URLs[0])
423472
}
424473
}
425-
426-
const mockDuplicateIndex = `
427-
entries:
428-
foo: {}
429-
bar: {}
430-
baz: {}
431-
bar: {}
432-
`
433-
434-
func TestValidateIndex(t *testing.T) {
435-
expect := `key "bar" already set in map`
436-
err := validateIndex([]byte(mockDuplicateIndex))
437-
if strings.Contains(expect, err.Error()) {
438-
t.Errorf("Unexpected error: %s", err)
439-
}
440-
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
serverInfo:
2+
contextPath: /v1/helm
3+
apiVersion: v1
4+
entries:
5+
nginx:
6+
- urls:
7+
- https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz
8+
name: nginx
9+
description: string
10+
version: 0.2.0
11+
home: https://github.com/something/else
12+
digest: "sha256:1234567890abcdef"
13+
keywords:
14+
- popular
15+
- web server
16+
- proxy
17+
- urls:
18+
- https://kubernetes-charts.storage.googleapis.com/nginx-0.1.0.tgz
19+
name: nginx
20+
description: string
21+
version: 0.1.0
22+
home: https://github.com/something
23+
digest: "sha256:1234567890abcdef"
24+
keywords:
25+
- popular
26+
- web server
27+
- proxy
28+
alpine:
29+
- urls:
30+
- https://kubernetes-charts.storage.googleapis.com/alpine-1.0.0.tgz
31+
- http://storage2.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
32+
name: alpine
33+
description: string
34+
version: 1.0.0
35+
home: https://github.com/something
36+
keywords:
37+
- linux
38+
- alpine
39+
- small
40+
- sumtin
41+
digest: "sha256:1234567890abcdef"
42+
chartWithNoURL:
43+
- name: chartWithNoURL
44+
description: string
45+
version: 1.0.0
46+
home: https://github.com/something
47+
keywords:
48+
- small
49+
- sumtin
50+
digest: "sha256:1234567890abcdef"

0 commit comments

Comments
 (0)
0