forked from karmada-io/karmada
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
operator: add CRDs archive verification to enhance file system robust…
…ness Signed-off-by: zhzhuang-zju <m17799853869@163.com>
- Loading branch information
1 parent
dcdabc9
commit a809285
Showing
3 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
Copyright 2024 The Karmada Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tasks | ||
|
||
import ( | ||
"archive/tar" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCheckOperatorCrdsTar(t *testing.T) { | ||
testItems := []struct { | ||
name string | ||
header *tar.Header | ||
expectedErr error | ||
}{ | ||
{ | ||
name: "unclean file dir 'crds/../'", | ||
header: &tar.Header{ | ||
Name: "crds/../", | ||
Typeflag: tar.TypeDir, | ||
}, | ||
expectedErr: fmt.Errorf("the given file contains unclean file dir: %s", "crds/../"), | ||
}, | ||
{ | ||
name: "unclean file dir 'crds/..'", | ||
header: &tar.Header{ | ||
Name: "crds/..", | ||
Typeflag: tar.TypeDir, | ||
}, | ||
expectedErr: fmt.Errorf("the given file contains unclean file dir: %s", "crds/.."), | ||
}, | ||
{ | ||
name: "unexpected file dir '../crds'", | ||
header: &tar.Header{ | ||
Name: "../crds", | ||
Typeflag: tar.TypeDir, | ||
}, | ||
expectedErr: fmt.Errorf("the given file contains unexpected file dir: %s", "../crds"), | ||
}, | ||
{ | ||
name: "unexpected file dir '..'", | ||
header: &tar.Header{ | ||
Name: "..", | ||
Typeflag: tar.TypeDir, | ||
}, | ||
expectedErr: fmt.Errorf("the given file contains unexpected file dir: %s", ".."), | ||
}, | ||
{ | ||
name: "expected file dir 'crds/'", | ||
header: &tar.Header{ | ||
Name: "crds/", | ||
Typeflag: tar.TypeDir, | ||
}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
name: "expected file dir 'crds'", | ||
header: &tar.Header{ | ||
Name: "crds", | ||
Typeflag: tar.TypeDir, | ||
}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
name: "unclean file path 'crds/../a.yaml'", | ||
header: &tar.Header{ | ||
Name: "crds/../a.yaml", | ||
Typeflag: tar.TypeReg, | ||
}, | ||
expectedErr: fmt.Errorf("the given file contains unclean file path: %s", "crds/../a.yaml"), | ||
}, | ||
{ | ||
name: "unexpected file path '../crds/a.yaml'", | ||
header: &tar.Header{ | ||
Name: "../crds/a.yaml", | ||
Typeflag: tar.TypeReg, | ||
}, | ||
expectedErr: fmt.Errorf("the given file contains unexpected file path: %s", "../crds/a.yaml"), | ||
}, | ||
{ | ||
name: "unexpected file path '../a.yaml'", | ||
header: &tar.Header{ | ||
Name: "../a.yaml", | ||
Typeflag: tar.TypeReg, | ||
}, | ||
expectedErr: fmt.Errorf("the given file contains unexpected file path: %s", "../a.yaml"), | ||
}, | ||
{ | ||
name: "expected file path 'crds/a.yaml'", | ||
header: &tar.Header{ | ||
Name: "crds/a.yaml", | ||
Typeflag: tar.TypeReg, | ||
}, | ||
expectedErr: nil, | ||
}, | ||
} | ||
for _, item := range testItems { | ||
assert.Equal(t, item.expectedErr, checkOperatorCrdsTar(item.header)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters