Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/artifacts-summary.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .github/workflows/ci-doctor.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .github/workflows/dev.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .github/workflows/tidy.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pkg/workflow/threat_detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (c *Compiler) buildThreatDetectionSteps(data *WorkflowData, mainJobName str
steps = append(steps, c.buildCustomThreatDetectionSteps(data.SafeOutputs.ThreatDetection.Steps)...)
}

// Step 4: Upload detection log artifact
steps = append(steps, c.buildUploadDetectionLogStep()...)

return steps
}

Expand Down Expand Up @@ -401,3 +404,16 @@ func (c *Compiler) buildCustomThreatDetectionSteps(steps []any) []string {
}
return result
}

// buildUploadDetectionLogStep creates the step to upload the detection log
func (c *Compiler) buildUploadDetectionLogStep() []string {
return []string{
" - name: Upload threat detection log\n",
" if: always()\n",
" uses: actions/upload-artifact@v4\n",
" with:\n",
" name: threat-detection.log\n",
" path: /tmp/threat-detection/detection.log\n",
" if-no-files-found: ignore\n",
}
}
70 changes: 70 additions & 0 deletions pkg/workflow/threat_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,73 @@ func TestBuildEngineStepsWithThreatDetectionEngine(t *testing.T) {
})
}
}

func TestBuildUploadDetectionLogStep(t *testing.T) {
compiler := NewCompiler(false, "", "test")

// Test that upload detection log step is created with correct properties
steps := compiler.buildUploadDetectionLogStep()

if len(steps) == 0 {
t.Fatal("Expected non-empty steps for upload detection log")
}

// Join all steps into a single string for easier verification
stepsString := strings.Join(steps, "")

// Verify key components of the upload step
expectedComponents := []string{
"name: Upload threat detection log",
"if: always()",
"uses: actions/upload-artifact@v4",
"name: threat-detection.log",
"path: /tmp/threat-detection/detection.log",
"if-no-files-found: ignore",
}

for _, expected := range expectedComponents {
if !strings.Contains(stepsString, expected) {
t.Errorf("Expected upload detection log step to contain %q, but it was not found.\nGenerated steps:\n%s", expected, stepsString)
}
}
}

func TestThreatDetectionStepsIncludeUpload(t *testing.T) {
compiler := NewCompiler(false, "", "test")

data := &WorkflowData{
SafeOutputs: &SafeOutputsConfig{
ThreatDetection: &ThreatDetectionConfig{
Enabled: true,
},
},
}

steps := compiler.buildThreatDetectionSteps(data, "agent")

if len(steps) == 0 {
t.Fatal("Expected non-empty steps")
}

// Join all steps into a single string for easier verification
stepsString := strings.Join(steps, "")

// Verify that the upload detection log step is included
if !strings.Contains(stepsString, "Upload threat detection log") {
t.Error("Expected threat detection steps to include upload detection log step")
}

if !strings.Contains(stepsString, "threat-detection.log") {
t.Error("Expected threat detection steps to include threat-detection.log artifact name")
}

// Verify it uses the always() condition
if !strings.Contains(stepsString, "if: always()") {
t.Error("Expected upload step to have 'if: always()' condition")
}

// Verify it ignores missing files
if !strings.Contains(stepsString, "if-no-files-found: ignore") {
t.Error("Expected upload step to have 'if-no-files-found: ignore'")
}
}