fix: protect shared rules across delivery and recovery (#560)

This commit is contained in:
sagit
2026-09-29 14:05:49 +08:00
committed by GitHub
parent 129fa0aa4c
commit c952d2fb3a
49 changed files with 5053 additions and 643 deletions
@@ -1,10 +1,14 @@
package service
import (
"bytes"
"context"
"errors"
"github.com/go-gost/x/config"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"testing"
"time"
@@ -148,3 +152,31 @@ func TestPostJSONWithFallbackRemembersDetectedURL(t *testing.T) {
t.Fatalf("expected remembered http url first, got %s", calls[0])
}
}
func TestConfigReportDoesNotPersistStaleRuntime(t *testing.T) {
previous, path := config.Global(), config.PersistPath()
defer config.Set(previous)
defer config.SetPersistPath(path)
config.Set(&config.Config{Services: []*config.ServiceConfig{{Name: "old-runtime"}}})
filename := filepath.Join(t.TempDir(), "gost.json")
candidate := []byte(`{"services":[{"name":"new-on-disk"}]}`)
if err := os.WriteFile(filename, candidate, 0600); err != nil {
t.Fatal(err)
}
config.SetPersistPath(filename)
config.EnablePersist()
report, err := getConfigData()
if err != nil {
t.Fatal(err)
}
if !bytes.Contains(report, []byte("old-runtime")) {
t.Fatalf("unexpected report: %s", report)
}
saved, err := os.ReadFile(filename)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(saved, candidate) {
t.Fatalf("report overwrote candidate config: %s", saved)
}
}