Skip to content

Commit 759ca0d

Browse files
authored
Merge pull request #38 from estroz/bugfix/error-on-invalid-bundle-file
pkg/manifests: `loadBundle` returns an error if a subdir or hidden file is found
2 parents 413e581 + 8798ba8 commit 759ca0d

File tree

8 files changed

+119
-1
lines changed

8 files changed

+119
-1
lines changed

pkg/manifests/bundleloader.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,18 @@ func loadBundle(csvName string, dir string) (*Bundle, error) {
111111
Name: csvName,
112112
}
113113
for _, f := range files {
114+
path := filepath.Join(dir, f.Name())
115+
114116
if f.IsDir() {
117+
errs = append(errs, fmt.Errorf("bundle manifests dir contains directory: %s", path))
115118
continue
116119
}
117120

118121
if strings.HasPrefix(f.Name(), ".") {
122+
errs = append(errs, fmt.Errorf("bundle manifests dir has hidden file: %s", path))
119123
continue
120124
}
121125

122-
path := filepath.Join(dir, f.Name())
123126
fileReader, err := os.Open(path)
124127
if err != nil {
125128
errs = append(errs, fmt.Errorf("unable to load file %s: %s", path, err))

pkg/manifests/directory_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ func TestGetPackage(t *testing.T) {
2929
require.Equal(t, 2, len(bundles[1].V1beta1CRDs))
3030
require.Equal(t, 1, len(bundles[1].V1CRDs))
3131
}
32+
33+
func TestLoadBundle(t *testing.T) {
34+
var err error
35+
36+
_, err = loadBundle("test-operator.v0.0.1", "./testdata/invalid_bundle_with_subdir")
37+
require.EqualError(t, err, "bundle manifests dir contains directory: testdata/invalid_bundle_with_subdir/foo")
38+
_, err = loadBundle("test-operator.v0.0.1", "./testdata/invalid_bundle_with_hidden")
39+
require.EqualError(t, err, "bundle manifests dir has hidden file: testdata/invalid_bundle_with_hidden/.hidden")
40+
}

pkg/manifests/testdata/invalid_bundle_with_hidden/.hidden

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: operators.coreos.com/v1alpha1
2+
kind: ClusterServiceVersion
3+
metadata:
4+
annotations:
5+
capabilities: Basic Install
6+
name: test-operator.v0.0.1
7+
namespace: placeholder
8+
spec:
9+
apiservicedefinitions: {}
10+
customresourcedefinitions:
11+
owned:
12+
- description: Test is the Schema for the tests API
13+
kind: Test
14+
name: tests.test.example.com
15+
version: v1alpha1
16+
installModes:
17+
- supported: true
18+
type: OwnNamespace
19+
- supported: true
20+
type: SingleNamespace
21+
- supported: false
22+
type: MultiNamespace
23+
- supported: true
24+
type: AllNamespaces
25+
keywords:
26+
- test-operator
27+
links:
28+
- name: Test Operator
29+
url: https://test-operator.domain
30+
maintainers:
31+
32+
name: Maintainer Name
33+
maturity: alpha
34+
provider:
35+
name: Provider Name
36+
url: https://your.domain
37+
version: 0.0.1
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: tests.test.example.com
5+
spec:
6+
group: test.example.com
7+
names:
8+
kind: Test
9+
listKind: TestList
10+
plural: tests
11+
singular: test
12+
scope: Namespaced
13+
versions:
14+
- name: v1alpha1
15+
served: true
16+
storage: true

pkg/manifests/testdata/invalid_bundle_with_subdir/foo/.keep

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: operators.coreos.com/v1alpha1
2+
kind: ClusterServiceVersion
3+
metadata:
4+
annotations:
5+
capabilities: Basic Install
6+
name: test-operator.v0.0.1
7+
namespace: placeholder
8+
spec:
9+
apiservicedefinitions: {}
10+
customresourcedefinitions:
11+
owned:
12+
- description: Test is the Schema for the tests API
13+
kind: Test
14+
name: tests.test.example.com
15+
version: v1alpha1
16+
installModes:
17+
- supported: true
18+
type: OwnNamespace
19+
- supported: true
20+
type: SingleNamespace
21+
- supported: false
22+
type: MultiNamespace
23+
- supported: true
24+
type: AllNamespaces
25+
keywords:
26+
- test-operator
27+
links:
28+
- name: Test Operator
29+
url: https://test-operator.domain
30+
maintainers:
31+
32+
name: Maintainer Name
33+
maturity: alpha
34+
provider:
35+
name: Provider Name
36+
url: https://your.domain
37+
version: 0.0.1
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: tests.test.example.com
5+
spec:
6+
group: test.example.com
7+
names:
8+
kind: Test
9+
listKind: TestList
10+
plural: tests
11+
singular: test
12+
scope: Namespaced
13+
versions:
14+
- name: v1alpha1
15+
served: true
16+
storage: true

0 commit comments

Comments
 (0)