Skip to content
Open
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
3 changes: 3 additions & 0 deletions internal/nix/nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ func IsExitErrorInsecurePackage(err error, pkgNameOrEmpty, installableOrEmpty st
if strings.Contains(string(exitErr.Stderr), "is marked as insecure") {
packageRegex := regexp.MustCompile(`Package ([^ ]+)`)
packageMatch := packageRegex.FindStringSubmatch(string(exitErr.Stderr))
if len(packageMatch) < 2 {
return false, nil
}

knownVulnerabilities := []string{}
if installableOrEmpty != "" {
Expand Down
20 changes: 20 additions & 0 deletions internal/nix/nix_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nix

import (
"os/exec"
"testing"
)

Expand Down Expand Up @@ -68,3 +69,22 @@ func TestParseInsecurePackagesFromExitError(t *testing.T) {
t.Errorf("Expected package 'python-2.7.18.7', got %s", packages[0])
}
}

func TestIsExitErrorInsecurePackageMissingPackageName(t *testing.T) {
// Simulate an exit error whose stderr contains "is marked as insecure"
// but lacks the expected "Package <name>" prefix. This defends against
// a panic when the regex match is empty in CI/build environments.
cmd := exec.Command("sh", "-c", `echo "error: something is marked as insecure, refusing to evaluate." >&2; exit 1`)
err := cmd.Run()
if err == nil {
t.Fatal("expected a command error")
}
Comment on lines +77 to +81

insecure, errOut := IsExitErrorInsecurePackage(err, "", "")
if insecure {
t.Error("expected insecure=false when package name is missing")
}
if errOut != nil {
t.Errorf("expected nil error, got %v", errOut)
}
}