| index a54ee8611..aa01d7e67 100644 |
| --- a/internal/host/haplacement_root_linux_test.go |
| +++ b/internal/host/haplacement_root_linux_test.go |
| @@ -34,6 +34,7 @@ import ( |
| "testing" |
| "time" |
| |
| + "golang.org/x/crypto/acme/autocert" |
| "golang.org/x/sys/unix" |
| |
| "github.com/carlosframework/platform/internal/activator" |
| @@ -236,6 +237,7 @@ func TestColdPlacementRootAgent(t *testing.T) { |
| })) |
| defer admin.Close() |
| lifecycleCheck(t, "admin address", os.WriteFile(filepath.Join(data, "cold-root-admin"), []byte(admin.URL), 0600)) |
| + coldRootSeedCertificates(t, store, autocert.DirCache(filepath.Join(data, "acme"))) |
| edge.RunWithActivatorReady([]string{"--registry", filepath.Join(data, "registry.db"), "--https", os.Getenv("COLD_ROOT_HTTPS"), "--http", "127.0.0.1:0"}, svc, nil, func(e *edge.Edge) { |
| activeEdge = e |
| e.EnableUsage(meter) |
| @@ -304,7 +306,7 @@ func TestColdPlacementRootRunner(t *testing.T) { |
| f := newColdRootHarness(t, "normal") |
| model, client, ctl, ingress := f.model, f.client, f.ctl, f.ingress |
| |
| - response, err := coldRootGET(client) |
| + response, err := coldRootGET(t, client) |
| lifecycleCheck(t, "non-choice request", err) |
| body, err := io.ReadAll(response.Body) |
| response.Body.Close() |
| @@ -368,7 +370,7 @@ func TestColdPlacementRootRunner(t *testing.T) { |
| readyUntil := time.Now().Add(2 * time.Minute) |
| var recovered bool |
| for time.Now().Before(readyUntil) { |
| - response, e := coldRootGET(client) |
| + response, e := coldRootGET(t, client) |
| if e == nil { |
| raw, _ := io.ReadAll(response.Body) |
| response.Body.Close() |
| @@ -440,6 +442,28 @@ func coldRootCertificate(t *testing.T, store release.Store, caFile string) { |
| lifecycleCheck(t, "sibling certificate publication", err) |
| } |
| |
| +func TestColdPlacementFixtureCertificateCache(t *testing.T) { |
| + store := release.NewDirStore(t.TempDir()) |
| + caFile := filepath.Join(t.TempDir(), "ca.pem") |
| + coldRootCertificate(t, store, caFile) |
| + cache := autocert.DirCache(t.TempDir()) |
| + coldRootSeedCertificates(t, store, cache) |
| + trust, err := os.ReadFile(caFile) |
| + lifecycleCheck(t, "fixture trust", err) |
| + roots := x509.NewCertPool() |
| + if !roots.AppendCertsFromPEM(trust) { |
| + t.Fatal("invalid fixture trust") |
| + } |
| + for _, host := range []string{lifecycleHost, lifecycleSibling} { |
| + raw, err := cache.Get(t.Context(), host) |
| + lifecycleCheck(t, "seeded cache", err) |
| + cert, err := tls.X509KeyPair(raw, raw) |
| + lifecycleCheck(t, "seeded key pair", err) |
| + _, err = cert.Leaf.Verify(x509.VerifyOptions{Roots: roots, DNSName: host}) |
| + lifecycleCheck(t, "trusted fixture identity", err) |
| + } |
| +} |
| + |
| func coldRootReadStats(t *testing.T, data string) coldRootStats { |
| raw, err := os.ReadFile(filepath.Join(data, "cold-root-admin")) |
| lifecycleCheck(t, "stats address", err) |
| @@ -453,12 +477,34 @@ func coldRootReadStats(t *testing.T, data string) coldRootStats { |
| return stats |
| } |
| |
| -func coldRootGET(client *http.Client) (*http.Response, error) { |
| +func coldRootSeedCertificates(t *testing.T, store release.Store, cache autocert.Cache) { |
| + t.Helper() |
| + for _, host := range []string{lifecycleHost, lifecycleSibling} { |
| + raw, _, err := store.Get(t.Context(), "control/certs/"+host) |
| + lifecycleCheck(t, "fixture certificate", err) |
| + lifecycleCheck(t, "seed edge certificate cache", cache.Put(t.Context(), host, raw)) |
| + } |
| +} |
| + |
| +func coldRootAuthorize(t *testing.T, req *http.Request) { |
| + t.Helper() |
| + reg, err := registry.Open("/data/registry.db") |
| + lifecycleCheck(t, "gate registry", err) |
| + defer reg.Close() |
| + route, err := reg.Get(req.URL.Hostname()) |
| + lifecycleCheck(t, "gate route", err) |
| + if route == nil || route.Gate == "" { |
| + t.Fatal("fixture route has no gate") |
| + } |
| + req.AddCookie(&http.Cookie{Name: gate.CookieName, Value: gate.Mint(route.Host, route.Gate, time.Now().Add(time.Hour))}) |
| +} |
| + |
| +func coldRootGET(t *testing.T, client *http.Client) (*http.Response, error) { |
| req, err := http.NewRequest("GET", "https://"+lifecycleHost+"/", nil) |
| if err != nil { |
| return nil, err |
| } |
| - req.SetBasicAuth("", "cold-root-password") |
| + coldRootAuthorize(t, req) |
| return client.Do(req) |
| } |
| |
| @@ -735,6 +781,12 @@ func newColdRootHarness(t *testing.T, mode string) *coldRootHarness { |
| lifecycleCheck(t, "fixture daemon reload", err) |
| coldRootProbeFixtures(t, uid, gid) |
| coldRootPrepareView(t, store, mode) |
| + lifecycleCheck(t, "fault publication owner", filepath.Walk(lifecycleHome+"/deployment/control", func(path string, _ os.FileInfo, err error) error { |
| + if err != nil { |
| + return err |
| + } |
| + return os.Chown(path, uid, gid) |
| + })) |
| if mode == "switch-off" { |
| env["CARLOS_REGION_HA"] = "0" |
| } |