69 lines
2.6 KiB
Go
69 lines
2.6 KiB
Go
package main
|
|
|
|
// The tools never open the admin password (novox/hq ADR 0436 §12, ADR 0467 clause 4): only the admin process
|
|
// reads it, as its own account, brother-admin. The build seat runs every test under one account, so no
|
|
// permission test can show the split; this is the file-level proxy mesh-mail's secret_boundary_test.go uses
|
|
// instead: an AST check that the tools' files import no password-reading package and name no password file.
|
|
|
|
import (
|
|
"go/parser"
|
|
"go/token"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
const secretPackage = "brother/cmd/brother/internal/secret"
|
|
|
|
// toolFiles are the files the tools' bundle runs (the scanner's, the printer.status's and the printer.settings'
|
|
// ask), as opposed to the admin process's: adminproc.go, admin.go, pin.go and html.go.
|
|
var toolFiles = []string{"main.go", "printer.go", "scan.go", "settings.go", "ipp.go", "escl.go", "file.go", "crop.go", "pdf.go"}
|
|
|
|
// 1453: none of the tools' files imports the password-reading package or names the password's file.
|
|
func TestTheToolsNeverOpenTheAdminPassword(t *testing.T) {
|
|
for _, file := range toolFiles {
|
|
fset := token.NewFileSet()
|
|
f, err := parser.ParseFile(fset, file, nil, parser.ImportsOnly)
|
|
if err != nil {
|
|
t.Fatalf("%s: %v", file, err)
|
|
}
|
|
for _, imp := range f.Imports {
|
|
if strings.Trim(imp.Path.Value, `"`) == secretPackage {
|
|
t.Errorf("%s imports %s, which only the admin process may (ADR 0436 §12)", file, secretPackage)
|
|
}
|
|
}
|
|
src, err := os.ReadFile(file)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Contains(string(src), `Getenv("BROTHER_ADMIN_PASSWORD")`) {
|
|
t.Errorf("%s reads BROTHER_ADMIN_PASSWORD, the admin process's alone", file)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 1453: the admin process does read it through the package, and the package is the one place a password file is
|
|
// opened.
|
|
func TestTheAdminProcessReadsThePasswordThroughThePackage(t *testing.T) {
|
|
fset := token.NewFileSet()
|
|
f, err := parser.ParseFile(fset, "adminproc.go", nil, parser.ImportsOnly)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
found := false
|
|
for _, imp := range f.Imports {
|
|
if strings.Trim(imp.Path.Value, `"`) == secretPackage {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Errorf("adminproc.go does not import %s", secretPackage)
|
|
}
|
|
for _, file := range append(append([]string{}, toolFiles...), "admin.go", "adminproc.go", "pin.go", "html.go") {
|
|
src, _ := os.ReadFile(file)
|
|
if strings.Contains(string(src), "os.ReadFile") && file != "settings.go" && file != "file.go" && file != "escl.go" {
|
|
t.Errorf("%s reads a file: only settings.json (settings.go) and the scan folder's PDFs are read outside the secret package", file)
|
|
}
|
|
}
|
|
}
|