Skip to content

Commit 95b2ef8

Browse files
Added one more integration test
1 parent ae8e0da commit 95b2ef8

File tree

3 files changed

+14
-59
lines changed

3 files changed

+14
-59
lines changed

internal/commands/scan_test.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,61 +2732,3 @@ a*cation-jira.yml`))
27322732
gitIgnoreFilter, _ := getGitignorePatterns("", zipPath)
27332733
assert.Assert(t, len(gitIgnoreFilter) > 0, "Expected patterns from .gitignore file")
27342734
}
2735-
2736-
func TestGetGitignorePatterns_ZipPath_GitIgnore_PermissionDenied(t *testing.T) {
2737-
dir := t.TempDir()
2738-
zipPath := filepath.Join(dir, "example.zip")
2739-
2740-
// Create the zip file
2741-
zipFile, err := os.Create(zipPath)
2742-
if err != nil {
2743-
t.Fatalf("Failed to create zip file: %v", err)
2744-
}
2745-
defer func(zipFile *os.File) {
2746-
err := zipFile.Close()
2747-
if err != nil {
2748-
t.Fatalf("Failed to close zip file: %v", err)
2749-
}
2750-
}(zipFile)
2751-
2752-
// Create a zip writer
2753-
zipWriter := zip.NewWriter(zipFile)
2754-
2755-
// Set up a header with 0000 permission for .gitignore
2756-
header := &zip.FileHeader{
2757-
Name: "example/.gitignore",
2758-
Method: zip.Deflate,
2759-
}
2760-
header.SetMode(0) // UNIX permission 0000 — no access for anyone
2761-
2762-
// Add a file to the zip archive
2763-
fileInZip, err := zipWriter.CreateHeader(header)
2764-
if err != nil {
2765-
t.Fatalf("Failed to add file to zip: %v", err)
2766-
}
2767-
2768-
// Write content to the file in the zip archive
2769-
_, err = fileInZip.Write([]byte(`src
2770-
src/
2771-
**/vullib
2772-
**/admin/
2773-
vulnerability/**
2774-
application-jira.yml
2775-
*.yml
2776-
LoginController[0-1].java
2777-
LoginController[!0-3].java
2778-
LoginController[01].java
2779-
LoginController[!456].java
2780-
?pplication-jira.yml
2781-
a*cation-jira.yml`))
2782-
if err != nil {
2783-
t.Fatalf("Failed to write data to zip: %v", err)
2784-
}
2785-
err = zipWriter.Close()
2786-
if err != nil {
2787-
return
2788-
}
2789-
2790-
_, err = getGitignorePatterns("", zipPath)
2791-
assert.ErrorContains(t, err, "permission denied")
2792-
}
13 KB
Binary file not shown.

test/integration/scan_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,7 @@ func TestCreateScan_SbomScanForNotExistingFile(t *testing.T) {
25452545

25462546
}
25472547

2548-
func TestCreateScanFilterGitIgnoreFile(t *testing.T) {
2548+
func TestCreateScanFilterGitIgnoreFile_GitIgnoreNotFound(t *testing.T) {
25492549
args := []string{
25502550
"scan", "create",
25512551
flag(params.ProjectName), getProjectNameForScanTests(),
@@ -2557,3 +2557,16 @@ func TestCreateScanFilterGitIgnoreFile(t *testing.T) {
25572557
err, _ := executeCommand(t, args...)
25582558
assert.ErrorContains(t, err, ".gitignore not found in zip")
25592559
}
2560+
2561+
func TestCreateScanFilterGitIgnoreFile_GitIgnoreExist(t *testing.T) {
2562+
args := []string{
2563+
"scan", "create",
2564+
flag(params.ProjectName), getProjectNameForScanTests(),
2565+
flag(params.BranchFlag), "dummy_branch",
2566+
flag(params.SourcesFlag), "sources-gitignore.zip",
2567+
flag(params.GitIgnoreFileFilterFlag),
2568+
}
2569+
2570+
err, _ := executeCommand(t, args...)
2571+
assert.NilError(t, err, "Scan creation with gitignore filter should pass without error")
2572+
}

0 commit comments

Comments
 (0)