33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package engine
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"os/exec"
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
// SEC-02: the catalog, the engine and the knowledge index never run a
|
||
|
|
// program or open a network connection; the CLI may (doctor checks).
|
||
|
|
// core/secretref links os/exec for resolving secret:// through yaseva;
|
||
|
|
// the engine only uses its Validate, so os/exec is checked on the
|
||
|
|
// packages' own imports, network packages on all dependencies.
|
||
|
|
func TestNoExecOrNetwork(t *testing.T) {
|
||
|
|
for _, pkg := range []string{"../catalog", "../engine", "../knowledge", "../ref"} {
|
||
|
|
own, err := exec.Command("go", "list", "-f", "{{join .Imports \" \"}}", pkg).Output()
|
||
|
|
if err != nil {
|
||
|
|
t.Skip("go list not available")
|
||
|
|
}
|
||
|
|
for _, dep := range strings.Fields(string(own)) {
|
||
|
|
if dep == "os/exec" || dep == "syscall" || dep == "plugin" || dep == "unsafe" {
|
||
|
|
t.Errorf("%s imports %s", pkg, dep)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
all, _ := exec.Command("go", "list", "-deps", "-f", "{{.ImportPath}}", pkg).Output()
|
||
|
|
for _, dep := range strings.Fields(string(all)) {
|
||
|
|
switch dep {
|
||
|
|
case "net/http", "net/rpc", "net/smtp", "crypto/tls":
|
||
|
|
t.Errorf("%s depends on %s", pkg, dep)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|