Files
meshcore-analyzer/cmd/server/config_mode_test.go
T
n30nex a5b60ca594 test: make local validation independent of runner environment (#2160)
Fixes #2159. Related to #1995.

Standalone release tests failed when `GITHUB_REF_NAME` was absent and
could use an unrelated runner tag when it was present. Supply the
simulated tag explicitly; exercise the real release-notes step with both
missing and unrelated host values, including present and absent notes
files.

Two filesystem fixtures now report unsupported Windows capabilities
explicitly: POSIX permission bits, and symlink creation denied with
error 1314. Unix mode checks and all symlink safety assertions remain
intact; other symlink setup errors still fail. Production code and
workflows are unchanged. This is 29 added lines across three test files.

Validation: reproduced all three failures before fixing them; focused
regressions, the full standalone frontend suite, and native Go
server/ingestor suites pass. The POSIX permission and unprivileged
Windows symlink fixtures are explicitly skipped on this host and remain
enabled in Linux CI. The browser smoke suite passed 148 checks, with
three fixture-dependent skips and two pre-existing disabled cases. No
configuration or customizer changes.
2026-10-10 21:20:40 +02:00

45 lines
1.3 KiB
Go

package main
import (
"os"
"path/filepath"
"runtime"
"testing"
)
// SaveGeoFilter rewrites config.json through a temp file. The file holds the
// API key and broker passwords, so the rewrite must keep whatever mode the
// operator set rather than resetting it to 0644.
func TestSaveGeoFilterPreservesFileMode(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Windows does not support POSIX file permission bits")
}
dir := t.TempDir()
path := filepath.Join(dir, "config.json")
if err := os.WriteFile(path, []byte(`{"apiKey":"secret-key-that-is-long-enough"}`+"\n"), 0600); err != nil {
t.Fatal(err)
}
gf := &GeoFilterConfig{Polygon: [][2]float64{{0, 0}, {0, 1}, {1, 1}, {1, 0}}}
if err := SaveGeoFilter(dir, gf); err != nil {
t.Fatalf("SaveGeoFilter: %v", err)
}
fi, err := os.Stat(path)
if err != nil {
t.Fatal(err)
}
if got := fi.Mode().Perm(); got != 0600 {
t.Fatalf("config.json mode after save = %o, want 0600", got)
}
// Default stays 0644 for a file that was 0644.
if err := os.Chmod(path, 0644); err != nil {
t.Fatal(err)
}
if err := SaveGeoFilter(dir, nil); err != nil {
t.Fatalf("SaveGeoFilter(nil): %v", err)
}
fi, _ = os.Stat(path)
if got := fi.Mode().Perm(); got != 0644 {
t.Fatalf("config.json mode after save = %o, want 0644", got)
}
}