- Avoid research checkout shadowing logo/script lookup - Strengthen packaging/CERT tests for multihash rules
313 lines
8.5 KiB
Go
313 lines
8.5 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/VeraeLLC/PrintToVeraeTimeStamp/internal/job"
|
|
)
|
|
|
|
func TestFindRepoFileMenubarAssets(t *testing.T) {
|
|
switch runtime.GOOS {
|
|
case "darwin":
|
|
p, err := findRepoFile("platform", "macos", "menubar", "run-menubar.sh")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if filepath.Base(p) != "run-menubar.sh" {
|
|
t.Fatal(p)
|
|
}
|
|
if _, err := findRepoFile("platform", "macos", "menubar", "verae-menubar.swift"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := findRepoFile("platform", "macos", "menubar", "build-menubar-app.sh"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := findRepoFile("platform", "macos", "menubar", "com.verae.timestamping.menubar.plist"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
case "windows":
|
|
if _, err := findRepoFile("platform", "windows", "scripts", "verae-tray.ps1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := findRepoFile("platform", "windows", "scripts", "install-tray-startup.ps1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := findRepoFile("platform", "windows", "scripts", "build-tray-startmenu.ps1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
default:
|
|
// Scripts still exist in the tree for packaging even on Linux CI.
|
|
if _, err := findRepoFile("platform", "windows", "scripts", "verae-tray.ps1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := findRepoFile("platform", "windows", "scripts", "install-tray-startup.ps1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := findRepoFile("platform", "windows", "scripts", "build-tray-startmenu.ps1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := findRepoFile("platform", "macos", "menubar", "verae-menubar.swift"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := findRepoFile("platform", "macos", "menubar", "build-menubar-app.sh"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMenubarPlistBody(t *testing.T) {
|
|
body := menubarPlistBody("/tmp/run-menubar.sh", "/tmp/logs", "127.0.0.1:8631")
|
|
for _, want := range []string{
|
|
menubarLaunchLabel,
|
|
"/tmp/run-menubar.sh",
|
|
"/tmp/logs/verae-menubar.launchd.out.log",
|
|
"<string>127.0.0.1:8631</string>",
|
|
"<key>KeepAlive</key>",
|
|
"<key>RunAtLoad</key>",
|
|
} {
|
|
if !strings.Contains(body, want) {
|
|
t.Fatalf("plist missing %q\n%s", want, body)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestReplaceEnvString(t *testing.T) {
|
|
in := `<key>VERAE_IPP_ADDR</key>
|
|
<string>127.0.0.1:8631</string>`
|
|
out := replaceEnvString(in, "VERAE_IPP_ADDR", "127.0.0.1:9999")
|
|
if !strings.Contains(out, "<string>127.0.0.1:9999</string>") {
|
|
t.Fatal(out)
|
|
}
|
|
if strings.Contains(out, "8631") {
|
|
t.Fatal(out)
|
|
}
|
|
}
|
|
|
|
func TestMenubarSupportDir(t *testing.T) {
|
|
p := menubarSupportDir("/Users/test")
|
|
want := filepath.Join("/Users/test", "Library", "Application Support", "Verae", "menubar")
|
|
if p != want {
|
|
t.Fatalf("got %q want %q", p, want)
|
|
}
|
|
}
|
|
|
|
func TestCopyFile(t *testing.T) {
|
|
dir := t.TempDir()
|
|
src := filepath.Join(dir, "a.txt")
|
|
dst := filepath.Join(dir, "b.txt")
|
|
if err := os.WriteFile(src, []byte("hello-menubar"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := copyFile(src, dst); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := os.ReadFile(dst)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(b) != "hello-menubar" {
|
|
t.Fatal(string(b))
|
|
}
|
|
}
|
|
|
|
func TestWindowsStartupShortcutPathShape(t *testing.T) {
|
|
p := windowsStartupShortcutPath()
|
|
if !strings.HasSuffix(p, winStartupLnkName) {
|
|
t.Fatal(p)
|
|
}
|
|
if !strings.Contains(strings.ToLower(p), "startup") {
|
|
t.Fatal(p)
|
|
}
|
|
}
|
|
|
|
func TestLocateScriptsPreferRepo(t *testing.T) {
|
|
// On every OS the packaging scripts should resolve from the go.mod tree.
|
|
if _, err := findRepoFile("platform", "windows", "scripts", "install-tray-startup.ps1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := findRepoFile("platform", "windows", "scripts", "build-tray-startmenu.ps1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := findRepoFile("platform", "macos", "menubar", "run-menubar.sh"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestBuildTrayStartmenuScriptDocumentsWiXFree(t *testing.T) {
|
|
p, err := findRepoFile("platform", "windows", "scripts", "build-tray-startmenu.ps1")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := os.ReadFile(p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body := string(b)
|
|
for _, want := range []string{
|
|
"Start Menu",
|
|
"Verae Tray",
|
|
"install-tray-startup.ps1",
|
|
"WiX",
|
|
"WScript.Shell",
|
|
"-Uninstall",
|
|
} {
|
|
if !strings.Contains(body, want) {
|
|
t.Fatalf("build-tray-startmenu.ps1 missing %q", want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMenubarAppBuilderHasNotarizationPointer(t *testing.T) {
|
|
p, err := findRepoFile("platform", "macos", "menubar", "build-menubar-app.sh")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := os.ReadFile(p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body := string(b)
|
|
for _, want := range []string{
|
|
"LSUIElement",
|
|
"ai.verae.timestamping.menubar",
|
|
"entitlements.plist",
|
|
"notarize",
|
|
"PkgInfo",
|
|
"HelperVersion",
|
|
"packaging-metadata.txt",
|
|
} {
|
|
if !strings.Contains(body, want) {
|
|
t.Fatalf("build-menubar-app.sh missing %q", want)
|
|
}
|
|
}
|
|
readme, err := findRepoFile("platform", "macos", "menubar", "README.txt")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rb, err := os.ReadFile(readme)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rbody := string(rb)
|
|
for _, want := range []string{
|
|
"notarytool",
|
|
"stapler",
|
|
"Developer ID Application",
|
|
"codesign",
|
|
} {
|
|
if !strings.Contains(rbody, want) {
|
|
t.Fatalf("menubar README.txt missing notarization step %q", want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRepoRootHintPrefersGoModTree(t *testing.T) {
|
|
// Residual packaging: no machine-specific research absolute path; go.mod tree wins.
|
|
root := repoRootHint()
|
|
if root == "" || root == "." {
|
|
// cwd may already be the module; still require go.mod via findRepoFile.
|
|
} else {
|
|
if !fileExists(filepath.Join(root, "go.mod")) {
|
|
t.Fatalf("repoRootHint %q missing go.mod", root)
|
|
}
|
|
if !fileExists(filepath.Join(root, "internal", "job", "job.go")) {
|
|
t.Fatalf("repoRootHint %q missing internal/job/job.go", root)
|
|
}
|
|
}
|
|
jobPath, err := findRepoFile("internal", "job", "job.go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
b, err := os.ReadFile(jobPath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(b), `const HelperVersion = "`+job.HelperVersion+`"`) {
|
|
t.Fatalf("resolved job.go must declare HelperVersion=%s at %s", job.HelperVersion, jobPath)
|
|
}
|
|
// Source must not hardcode a sibling research checkout path.
|
|
mainPath, err := findRepoFile("cmd", "verae-print", "main.go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mb, err := os.ReadFile(mainPath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Contains(string(mb), "/Users/marchon/research/PrintToVeraeTimeStamp") {
|
|
t.Fatal("main.go must not hardcode research absolute path (use go.mod walk)")
|
|
}
|
|
}
|
|
|
|
func TestPackagingMetadataVersionStamp(t *testing.T) {
|
|
// A4: tray/menubar install scripts + READMEs stamp HelperVersion.
|
|
// job.HelperVersion is the single source of truth.
|
|
helper := job.HelperVersion
|
|
if helper == "" {
|
|
t.Fatal("job.HelperVersion empty")
|
|
}
|
|
checks := []struct {
|
|
parts []string
|
|
want []string
|
|
}{
|
|
{
|
|
parts: []string{"platform", "macos", "menubar", "build-menubar-app.sh"},
|
|
want: []string{"HelperVersion", "CFBundleShortVersionString", "packaging-metadata.txt", helper},
|
|
},
|
|
{
|
|
parts: []string{"platform", "macos", "menubar", "README.txt"},
|
|
want: []string{"HelperVersion", "Package version", helper},
|
|
},
|
|
{
|
|
parts: []string{"platform", "windows", "scripts", "common.ps1"},
|
|
want: []string{"Get-VeraePackageVersion", "HelperVersion", helper},
|
|
},
|
|
{
|
|
parts: []string{"platform", "windows", "scripts", "install-tray-startup.ps1"},
|
|
want: []string{"PackageVersion", "HelperVersion", "no elevated MSI"},
|
|
},
|
|
{
|
|
parts: []string{"platform", "windows", "scripts", "build-tray-startmenu.ps1"},
|
|
want: []string{"PackageVersion", "HelperVersion", "no elevated MSI"},
|
|
},
|
|
{
|
|
parts: []string{"platform", "windows", "scripts", "verae-tray.ps1"},
|
|
want: []string{"PackageVersion", "HelperVersion"},
|
|
},
|
|
{
|
|
parts: []string{"platform", "windows", "README.txt"},
|
|
want: []string{"HelperVersion", "Package version", "no elevated MSI"},
|
|
},
|
|
{
|
|
parts: []string{"platform", "windows", "README-WINDOWS.txt"},
|
|
want: []string{"HelperVersion", "Package version"},
|
|
},
|
|
{
|
|
parts: []string{"platform", "smoke-packaging-metadata.sh"},
|
|
want: []string{"HelperVersion", "no elevated MSI", "A4"},
|
|
},
|
|
}
|
|
for _, c := range checks {
|
|
path, err := findRepoFile(c.parts...)
|
|
if err != nil {
|
|
t.Fatalf("%v: %v", c.parts, err)
|
|
}
|
|
b, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body := string(b)
|
|
for _, w := range c.want {
|
|
if !strings.Contains(body, w) {
|
|
t.Fatalf("%s missing %q", path, w)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|