From 941f557ccec66c9e4460f38b1de126a2de39aa88 Mon Sep 17 00:00:00 2001 From: Soyeon Park Date: Tue, 30 Jul 2024 13:17:43 +0900 Subject: [PATCH 1/8] test: add fuzz test to GetChartsPath function in handler Signed-off-by: Soyeon Park --- .../pkg/chaoshub/handler/handler_fuzz_test.go | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go diff --git a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go new file mode 100644 index 00000000000..8aaf6f15228 --- /dev/null +++ b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go @@ -0,0 +1,35 @@ +package handler + +import ( + fuzz "github.com/AdaLogics/go-fuzz-headers" + "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" + "testing" +) + +func FuzzGetChartsPath(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + fuzzConsumer := fuzz.NewConsumer(data) + + chartsInput := model.CloningInput{} + err := fuzzConsumer.GenerateStruct(&chartsInput) + if err != nil { + return + } + projectID, _ := fuzzConsumer.GetString() + isDefault, _ := fuzzConsumer.GetBool() + + result := GetChartsPath(chartsInput, projectID, isDefault) + + if isDefault { + expected := DefaultPath + "default/" + chartsInput.Name + "/faults/" + if result != expected { + t.Errorf("Expected %s, got %s", expected, result) + } + } else { + expected := DefaultPath + projectID + "/" + chartsInput.Name + "/faults/" + if result != expected { + t.Errorf("Expected %s, got %s", expected, result) + } + } + }) +} From 705337e67732e9663e2256ded5d498c2a2fc17d2 Mon Sep 17 00:00:00 2001 From: Soyeon Park Date: Wed, 14 Aug 2024 20:21:45 +0900 Subject: [PATCH 2/8] test: add fuzz test to FuzzReadExperimentFile function in handler * Removed the ./types.go example in unit test handler_test.go/TestReadExperimentFile because it returns a file does not exist error, not the file is not a yaml error that the test is intended to return. Signed-off-by: Soyeon Park --- .../pkg/chaoshub/handler/handler_fuzz_test.go | 65 +++++++++++++++++++ .../pkg/chaoshub/handler/handler_test.go | 5 -- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go index 8aaf6f15228..ac4ce1dfa63 100644 --- a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go +++ b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go @@ -3,7 +3,12 @@ package handler import ( fuzz "github.com/AdaLogics/go-fuzz-headers" "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" + "os" "testing" + "path/filepath" + "strings" + "encoding/json" + "fmt" ) func FuzzGetChartsPath(f *testing.F) { @@ -33,3 +38,63 @@ func FuzzGetChartsPath(f *testing.F) { } }) } + +func FuzzReadExperimentFile(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte, filename string) { + fuzzConsumer := fuzz.NewConsumer(data) + + // Create a temporary directory + tmpDir, err := os.MkdirTemp("", "*-fuzztest") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) // clean up + + // Ensure the filename is valid and unique + safeFilename := filepath.Clean(filepath.Base(filename)) + if isInvalidFilename(safeFilename) { + safeFilename = "test.yaml" + } + filePath := filepath.Join(tmpDir, safeFilename) + content := ChaosChart{} + err = fuzzConsumer.GenerateStruct(&content) + if err != nil { + return + } + fmt.Print(filePath) + jsonContent, _ := json.Marshal(content) + err = os.WriteFile(filePath, jsonContent, 0644) + if err != nil { + t.Fatal(err) + } + + _, err = ReadExperimentFile(filePath) + + if strings.HasSuffix(safeFilename, ".yaml") { + if err != nil && !isInvalidYAML(jsonContent) { + t.Errorf("UnExpected error for valid YAML, got error: %v", err) + } + if err == nil && isInvalidYAML(jsonContent) { + t.Errorf("Expected error for invalid YAML, got nil") + } + } + + _, err = ReadExperimentFile("./not_exist_file.yaml") + if err == nil { + t.Errorf("Expected error for file does not exist, got nil") + } + }) +} + +func isInvalidFilename(filename string) bool{ + return strings.IndexByte(filename, 0) != -1 || filename == "" || filename == "." || filename == ".." || filename == "/" || len(filename) > 255 +} + +func isInvalidYAML(data []byte) bool{ + for _, b := range data { + if b < 32 || b == 127 { + return true + } + } + return false +} \ No newline at end of file diff --git a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_test.go b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_test.go index ffcd2106ac3..1a30b1e012a 100644 --- a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_test.go +++ b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_test.go @@ -72,11 +72,6 @@ func TestReadExperimentFile(t *testing.T) { filePath: "./temp1.yaml", isError: true, }, - { - name: "failure: file is not a yaml", - filePath: "./types.go", - isError: true, - }, } for _, tc := range testcases { // when From 063550fbc363c3db36e6c1e5c3bebd875bf2b75a Mon Sep 17 00:00:00 2001 From: Soyeon Park Date: Wed, 14 Aug 2024 20:39:37 +0900 Subject: [PATCH 3/8] * test: Add the FuzzReadExperimentYAMLFile test in the handler_fuzz_test.go file Signed-off-by: Soyeon Park --- .../pkg/chaoshub/handler/handler_fuzz_test.go | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go index ac4ce1dfa63..39fb51760aa 100644 --- a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go +++ b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go @@ -8,7 +8,6 @@ import ( "path/filepath" "strings" "encoding/json" - "fmt" ) func FuzzGetChartsPath(f *testing.F) { @@ -61,7 +60,7 @@ func FuzzReadExperimentFile(f *testing.F) { if err != nil { return } - fmt.Print(filePath) + jsonContent, _ := json.Marshal(content) err = os.WriteFile(filePath, jsonContent, 0644) if err != nil { @@ -70,14 +69,12 @@ func FuzzReadExperimentFile(f *testing.F) { _, err = ReadExperimentFile(filePath) - if strings.HasSuffix(safeFilename, ".yaml") { - if err != nil && !isInvalidYAML(jsonContent) { - t.Errorf("UnExpected error for valid YAML, got error: %v", err) - } - if err == nil && isInvalidYAML(jsonContent) { - t.Errorf("Expected error for invalid YAML, got nil") - } + if err != nil && !isInvalidYAML(jsonContent) { + t.Errorf("UnExpected error for valid YAML, got error: %v", err) } + if err == nil && isInvalidYAML(jsonContent) { + t.Errorf("Expected error for invalid YAML, got nil") + } _, err = ReadExperimentFile("./not_exist_file.yaml") if err == nil { @@ -86,6 +83,48 @@ func FuzzReadExperimentFile(f *testing.F) { }) } +func FuzzReadExperimentYAMLFile(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte, filename string) { + fuzzConsumer := fuzz.NewConsumer(data) + + // Create a temporary directory + tmpDir, err := os.MkdirTemp("", "*-fuzztest") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) // clean up + + // Ensure the filename is valid and unique + safeFilename := filepath.Clean(filepath.Base(filename)) + if isInvalidFilename(safeFilename) { + safeFilename = "test.yaml" + } + filePath := filepath.Join(tmpDir, safeFilename) + content := ChaosChart{} + err = fuzzConsumer.GenerateStruct(&content) + if err != nil { + return + } + + jsonContent, _ := json.Marshal(content) + err = os.WriteFile(filePath, jsonContent, 0644) + if err != nil { + t.Fatal(err) + } + + _, err = ReadExperimentYAMLFile(filePath) + + if err != nil { + t.Errorf("UnExpected error for valid YAML, got error: %v", err) + } + + _, err = ReadExperimentFile("./not_exist_file.yaml") + if err == nil { + t.Errorf("Expected error for file does not exist, got nil") + } + }) +} + func isInvalidFilename(filename string) bool{ return strings.IndexByte(filename, 0) != -1 || filename == "" || filename == "." || filename == ".." || filename == "/" || len(filename) > 255 } @@ -97,4 +136,4 @@ func isInvalidYAML(data []byte) bool{ } } return false -} \ No newline at end of file +} From b0b7f5570532ba7ced85421fac712eba59e648a5 Mon Sep 17 00:00:00 2001 From: Soyeon Park Date: Wed, 14 Aug 2024 20:54:29 +0900 Subject: [PATCH 4/8] test: add fuzz test to FuzzIsFileExisting function in handler Signed-off-by: Soyeon Park --- .../pkg/chaoshub/handler/handler_fuzz_test.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go index 39fb51760aa..a1f3a706d5d 100644 --- a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go +++ b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go @@ -125,6 +125,35 @@ func FuzzReadExperimentYAMLFile(f *testing.F) { }) } +func FuzzIsFileExisting(f *testing.F) { + f.Fuzz(func(t *testing.T, filename string) { + // Create a temporary directory + tmpDir, err := os.MkdirTemp("", "*-fuzztest") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) // clean up + + // Ensure the filename is valid and unique + safeFilename := filepath.Clean(filepath.Base(filename)) + if isInvalidFilename(safeFilename) { + safeFilename = "test.yaml" + } + filePath := filepath.Join(tmpDir, safeFilename) + _, _ = os.Create(filePath) + + result, err := IsFileExisting(filePath) + if !result { + t.Errorf("Expected true for existing file, got false") + } + + result, err = IsFileExisting("./not_exist_file.yaml") + if result { + t.Errorf("Expected false for not existing file, got true") + } + }) +} + func isInvalidFilename(filename string) bool{ return strings.IndexByte(filename, 0) != -1 || filename == "" || filename == "." || filename == ".." || filename == "/" || len(filename) > 255 } From a01afab07222077a7dfe2242df4eed9dd97b95d6 Mon Sep 17 00:00:00 2001 From: Soyeon Park Date: Sun, 1 Sep 2024 12:39:01 +0900 Subject: [PATCH 5/8] test: add fuzz test to FuzzGetExperimentData, FuzzUnzipRemoteHub function in handler Signed-off-by: Soyeon Park --- .../pkg/chaoshub/handler/handler_fuzz_test.go | 332 ++++++++++++------ 1 file changed, 228 insertions(+), 104 deletions(-) diff --git a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go index a1f3a706d5d..ee381485dfc 100644 --- a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go +++ b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go @@ -1,13 +1,17 @@ package handler import ( + "archive/zip" + "encoding/json" fuzz "github.com/AdaLogics/go-fuzz-headers" + "github.com/google/uuid" "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" "os" - "testing" + "bytes" + "io/ioutil" "path/filepath" "strings" - "encoding/json" + "testing" ) func FuzzGetChartsPath(f *testing.F) { @@ -39,130 +43,250 @@ func FuzzGetChartsPath(f *testing.F) { } func FuzzReadExperimentFile(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte, filename string) { - fuzzConsumer := fuzz.NewConsumer(data) - - // Create a temporary directory - tmpDir, err := os.MkdirTemp("", "*-fuzztest") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpDir) // clean up - - // Ensure the filename is valid and unique - safeFilename := filepath.Clean(filepath.Base(filename)) - if isInvalidFilename(safeFilename) { - safeFilename = "test.yaml" - } - filePath := filepath.Join(tmpDir, safeFilename) - content := ChaosChart{} - err = fuzzConsumer.GenerateStruct(&content) - if err != nil { - return - } - - jsonContent, _ := json.Marshal(content) - err = os.WriteFile(filePath, jsonContent, 0644) - if err != nil { - t.Fatal(err) - } - - _, err = ReadExperimentFile(filePath) - - if err != nil && !isInvalidYAML(jsonContent) { - t.Errorf("UnExpected error for valid YAML, got error: %v", err) - } + f.Fuzz(func(t *testing.T, data []byte, filename string) { + fuzzConsumer := fuzz.NewConsumer(data) + + // Create a temporary directory + tmpDir, err := os.MkdirTemp("", "*-fuzztest") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) // clean up + + // Ensure the filename is valid and unique + safeFilename := filepath.Clean(filepath.Base(filename)) + if isInvalidFilename(safeFilename) { + safeFilename = "test.yaml" + } + filePath := filepath.Join(tmpDir, safeFilename) + content := ChaosChart{} + err = fuzzConsumer.GenerateStruct(&content) + if err != nil { + return + } + + jsonContent, _ := json.Marshal(content) + err = os.WriteFile(filePath, jsonContent, 0644) + if err != nil { + t.Fatal(err) + } + + _, err = ReadExperimentFile(filePath) + + if err != nil && !isInvalidYAML(jsonContent) { + t.Errorf("UnExpected error for valid YAML, got error: %v", err) + } if err == nil && isInvalidYAML(jsonContent) { t.Errorf("Expected error for invalid YAML, got nil") } - _, err = ReadExperimentFile("./not_exist_file.yaml") - if err == nil { - t.Errorf("Expected error for file does not exist, got nil") - } - }) + _, err = ReadExperimentFile("./not_exist_file.yaml") + if err == nil { + t.Errorf("Expected error for file does not exist, got nil") + } + }) +} + +func FuzzGetExperimentData(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte, filename string) { + fuzzConsumer := fuzz.NewConsumer(data) + + // Create a temporary directory + tmpDir, err := os.MkdirTemp("", "*-fuzztest") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) // clean up + + // Ensure the filename is valid and unique + safeFilename := filepath.Clean(filepath.Base(filename)) + if isInvalidFilename(safeFilename) { + safeFilename = "test.yaml" + } + filePath := filepath.Join(tmpDir, safeFilename) + content := ChaosChart{} + err = fuzzConsumer.GenerateStruct(&content) + if err != nil { + return + } + + jsonContent, _ := json.Marshal(content) + err = os.WriteFile(filePath, jsonContent, 0644) + if err != nil { + t.Fatal(err) + } + + _, err = GetExperimentData(filePath) + + if err != nil && (!isInvalidYAML(jsonContent) || json.Valid(jsonContent)) { + t.Errorf("UnExpected error for valid YAML, got error: %v", err) + } + if err == nil && isInvalidYAML(jsonContent) { + t.Errorf("Expected error for invalid YAML, got nil") + } + + _, err = ReadExperimentFile("./not_exist_file.yaml") + if err == nil { + t.Errorf("Expected error for file does not exist, got nil") + } + }) } func FuzzReadExperimentYAMLFile(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte, filename string) { + f.Fuzz(func(t *testing.T, data []byte, filename string) { fuzzConsumer := fuzz.NewConsumer(data) - // Create a temporary directory - tmpDir, err := os.MkdirTemp("", "*-fuzztest") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpDir) // clean up - - // Ensure the filename is valid and unique - safeFilename := filepath.Clean(filepath.Base(filename)) - if isInvalidFilename(safeFilename) { - safeFilename = "test.yaml" - } - filePath := filepath.Join(tmpDir, safeFilename) - content := ChaosChart{} - err = fuzzConsumer.GenerateStruct(&content) - if err != nil { - return - } - - jsonContent, _ := json.Marshal(content) - err = os.WriteFile(filePath, jsonContent, 0644) - if err != nil { - t.Fatal(err) - } + // Create a temporary directory + tmpDir, err := os.MkdirTemp("", "*-fuzztest") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) // clean up + + // Ensure the filename is valid and unique + safeFilename := filepath.Clean(filepath.Base(filename)) + if isInvalidFilename(safeFilename) { + safeFilename = "test.yaml" + } + filePath := filepath.Join(tmpDir, safeFilename) + content := ChaosChart{} + err = fuzzConsumer.GenerateStruct(&content) + if err != nil { + return + } + + jsonContent, _ := json.Marshal(content) + err = os.WriteFile(filePath, jsonContent, 0644) + if err != nil { + t.Fatal(err) + } _, err = ReadExperimentYAMLFile(filePath) if err != nil { - t.Errorf("UnExpected error for valid YAML, got error: %v", err) - } - - _, err = ReadExperimentFile("./not_exist_file.yaml") - if err == nil { - t.Errorf("Expected error for file does not exist, got nil") - } + t.Errorf("UnExpected error for valid YAML, got error: %v", err) + } + + _, err = ReadExperimentFile("./not_exist_file.yaml") + if err == nil { + t.Errorf("Expected error for file does not exist, got nil") + } + }) +} + +func FuzzUnzipRemoteHub(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte, filename string, projectID string) { + // Create a temporary directory + tmpDir, err := os.MkdirTemp("", "*-fuzztest") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) // clean up + + // Ensure the filename is valid and unique + safeFilename := filepath.Clean(filepath.Base(filename)) + if isInvalidFilename(safeFilename) { + safeFilename = "test.zip" + } + if !strings.HasSuffix(safeFilename, ".zip") { + safeFilename += ".zip" + } + if isInvalidFilename(projectID) { + projectID = uuid.New().String() + } + + filePath := filepath.Join(tmpDir, safeFilename) + // Create a valid zip file + err = createValidZipFile(filePath, data) + if err != nil { + t.Fatal(err) + } + + err = UnzipRemoteHub(filePath, projectID) + + if err != nil { + t.Errorf("UnExpected error for valid zip, got error: %v", err) + } + + // Test with non-existent file + err = UnzipRemoteHub("./not_exist_file.zip", projectID) + if err == nil { + t.Errorf("Expected error for file does not exist, got nil") + } + + // Test with non-zip file + nonZipPath := filepath.Join(tmpDir, "no_zip") + err = os.WriteFile(nonZipPath, []byte("not a zip file"), 0644) + if err != nil { + t.Fatal(err) + } + err = UnzipRemoteHub(nonZipPath, projectID) + if err == nil { + t.Errorf("Expected error for no zip, got nil") + } }) } func FuzzIsFileExisting(f *testing.F) { - f.Fuzz(func(t *testing.T, filename string) { - // Create a temporary directory - tmpDir, err := os.MkdirTemp("", "*-fuzztest") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpDir) // clean up - - // Ensure the filename is valid and unique - safeFilename := filepath.Clean(filepath.Base(filename)) - if isInvalidFilename(safeFilename) { - safeFilename = "test.yaml" - } - filePath := filepath.Join(tmpDir, safeFilename) - _, _ = os.Create(filePath) - - result, err := IsFileExisting(filePath) - if !result { - t.Errorf("Expected true for existing file, got false") - } - - result, err = IsFileExisting("./not_exist_file.yaml") - if result { - t.Errorf("Expected false for not existing file, got true") - } + f.Fuzz(func(t *testing.T, filename string) { + // Create a temporary directory + tmpDir, err := os.MkdirTemp("", "*-fuzztest") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) // clean up + + // Ensure the filename is valid and unique + safeFilename := filepath.Clean(filepath.Base(filename)) + if isInvalidFilename(safeFilename) { + safeFilename = "test.yaml" + } + filePath := filepath.Join(tmpDir, safeFilename) + _, _ = os.Create(filePath) + + result, err := IsFileExisting(filePath) + if !result { + t.Errorf("Expected true for existing file, got false") + } + + result, err = IsFileExisting("./not_exist_file.yaml") + if result { + t.Errorf("Expected false for not existing file, got true") + } }) } -func isInvalidFilename(filename string) bool{ +func isInvalidFilename(filename string) bool { return strings.IndexByte(filename, 0) != -1 || filename == "" || filename == "." || filename == ".." || filename == "/" || len(filename) > 255 } -func isInvalidYAML(data []byte) bool{ +func isInvalidYAML(data []byte) bool { for _, b := range data { - if b < 32 || b == 127 { - return true - } - } - return false + if b < 32 || b == 127 { + return true + } + } + return false } + +func createValidZipFile(filename string, data []byte) error { + zipFile, err := os.Create(filename) + if err != nil { + return err + } + defer zipFile.Close() + + zipWriter := zip.NewWriter(zipFile) + defer zipWriter.Close() + + f, err := zipWriter.Create("test.txt") + if err != nil { + return err + } + _, err = f.Write(data) + if err != nil { + return err + } + + return nil +} \ No newline at end of file From fb0db414ceee9d4fd092fa85b4c0307661f587dc Mon Sep 17 00:00:00 2001 From: Soyeon Park Date: Sun, 1 Sep 2024 15:29:23 +0900 Subject: [PATCH 6/8] refactor: remove unused imported library Signed-off-by: Soyeon Park --- .../graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go index ee381485dfc..e60a5f06efe 100644 --- a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go +++ b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go @@ -7,8 +7,6 @@ import ( "github.com/google/uuid" "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" "os" - "bytes" - "io/ioutil" "path/filepath" "strings" "testing" From 580ee0150d0b0862b55a3c89456fd31d33b12559 Mon Sep 17 00:00:00 2001 From: Soyeon Park Date: Sun, 1 Sep 2024 16:07:57 +0900 Subject: [PATCH 7/8] fix: check yaml: control characters are not allowed Signed-off-by: Soyeon Park --- .../graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go index e60a5f06efe..48d5c661485 100644 --- a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go +++ b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go @@ -116,7 +116,7 @@ func FuzzGetExperimentData(f *testing.F) { _, err = GetExperimentData(filePath) - if err != nil && (!isInvalidYAML(jsonContent) || json.Valid(jsonContent)) { + if err != nil && !isInvalidYAML(jsonContent) && json.Valid(jsonContent) { t.Errorf("UnExpected error for valid YAML, got error: %v", err) } if err == nil && isInvalidYAML(jsonContent) { From 9c5ba83562063c5d59c10538ba8ba6c2b17129dd Mon Sep 17 00:00:00 2001 From: Soyeon Park Date: Sun, 1 Sep 2024 16:54:57 +0900 Subject: [PATCH 8/8] refactor: save goimport order Signed-off-by: Soyeon Park --- .../server/pkg/chaoshub/handler/handler_fuzz_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go index 48d5c661485..5a83fe5c04b 100644 --- a/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go +++ b/chaoscenter/graphql/server/pkg/chaoshub/handler/handler_fuzz_test.go @@ -3,13 +3,14 @@ package handler import ( "archive/zip" "encoding/json" - fuzz "github.com/AdaLogics/go-fuzz-headers" - "github.com/google/uuid" - "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" "os" "path/filepath" "strings" "testing" + + fuzz "github.com/AdaLogics/go-fuzz-headers" + "github.com/google/uuid" + "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" ) func FuzzGetChartsPath(f *testing.F) { @@ -115,7 +116,7 @@ func FuzzGetExperimentData(f *testing.F) { } _, err = GetExperimentData(filePath) - + if err != nil && !isInvalidYAML(jsonContent) && json.Valid(jsonContent) { t.Errorf("UnExpected error for valid YAML, got error: %v", err) } @@ -287,4 +288,4 @@ func createValidZipFile(filename string, data []byte) error { } return nil -} \ No newline at end of file +}