Files

44 lines
1.5 KiB
Go

// Command httpstub is a trivial local HTTP server used only by
// scripts/run-local-e2e.sh, standing in for two kinds of real internet
// resources so the offline end-to-end harness needs no real internet
// access:
// - "/" always returns 200 OK — stands in for the real outbound egress
// targets (hub.docker.com, github.com, packages.ubuntu.com).
// - "/ip" echoes the caller's remote address as plain text — stands in
// for the external IP-echo service the validator-agent's self-check
// queries in production (see internal/agentcore.detectPublicIP and
// config.SelfCheckCfg.IPEchoURLs). Because httpstub runs locally, this
// only produces a meaningful self-check signal in the harness because
// the "floating IP" under test is itself the loopback address the
// caller genuinely connects from — it is not a stand-in for OpenStack's
// SNAT behavior.
package main
import (
"flag"
"fmt"
"log"
"net"
"net/http"
)
func main() {
addr := flag.String("addr", ":9090", "address to listen on")
flag.Parse()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("stub ok\n"))
})
http.HandleFunc("/ip", func(w http.ResponseWriter, r *http.Request) {
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
host = r.RemoteAddr
}
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintln(w, host)
})
log.Printf("httpstub listening on %s", *addr)
log.Fatal(http.ListenAndServe(*addr, nil))
}