gates / gates (push) Successful in 2m3s
The bind handler always read extra_args and the pairing answer always carried it; the Hosts page had no input, so --accept-small-disk could not reach a public-image install. One text input, a validator in the store (CleanApplianceExtraArgs), a 400 for a refused value. Tests TestR1398_* (4), 5 mutations red. Register: R-1035's 4-week read moved to 2026-11-26 (the operator's Search Console read; reason in the row). Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
81 lines
3.0 KiB
Go
81 lines
3.0 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
|
)
|
|
|
|
// R-1398 (release 4, 2026-11-19): the operator's bind form offers the extra installer flags the handler has always
|
|
// read, so `--accept-small-disk` can reach an install from the public image. Only plain --flag words pass.
|
|
|
|
func TestR1398_TheBindFormHasTheExtraArgsField(t *testing.T) {
|
|
s, st := newTestServer(t)
|
|
if err := st.SaveCustomerConfig(&store.CustomerConfig{CustomerID: "acme", CustomerName: "Acme", APIKey: "k", RetrievalPassword: "pw"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
seedAppliance(t, st, "uuid-field", "bc:24:11:98:10:0e")
|
|
html := renderHosts(t, s)
|
|
form := html[strings.Index(html, `/bind"`):]
|
|
form = form[:strings.Index(form, "</form>")]
|
|
if !strings.Contains(form, `name="extra_args"`) {
|
|
t.Fatalf("the bind form has no extra_args input:\n%s", form)
|
|
}
|
|
if !strings.Contains(form, "--accept-small-disk") {
|
|
t.Error("the field does not name the one flag it exists for")
|
|
}
|
|
}
|
|
|
|
func TestR1398_BindRefusesExtraArgsThatAreNotPlainFlags(t *testing.T) {
|
|
for _, bad := range []string{
|
|
"--cores 4", // a value
|
|
"--accept-small-disk;reboot", // a shell character
|
|
"-f", // one dash
|
|
"--Accept", // upper case
|
|
"--a=b", // an equals sign
|
|
"'--force'", // a quote
|
|
"--a --b --c --d --e --f --g --h --i", // too many words
|
|
} {
|
|
t.Run(bad, func(t *testing.T) {
|
|
s, st := newTestServer(t)
|
|
if err := st.SaveCustomerConfig(&store.CustomerConfig{CustomerID: "acme", APIKey: "k", RetrievalPassword: "pw"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
id := seedAppliance(t, st, "uuid-bad", "bc:24:11:98:10:0e")
|
|
form := url.Values{"customer_id": {"acme"}, "extra_args": {bad}}
|
|
req := httptest.NewRequest("POST", "/appliances/x/bind", strings.NewReader(form.Encode()))
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
rr := httptest.NewRecorder()
|
|
s.handleApplianceBind(rr, req, id)
|
|
if rr.Code != http.StatusBadRequest {
|
|
t.Fatalf("bind with %q = %d, want 400", bad, rr.Code)
|
|
}
|
|
if a, _ := st.GetAppliance(id); a.Status != store.ApplianceRegistered || a.ExtraArgs != "" {
|
|
t.Fatalf("a refused bind changed the appliance: %+v", a)
|
|
}
|
|
// The store refuses it too, for any other caller.
|
|
if err := st.BindAppliance(id, "acme", "appliance", bad); err == nil {
|
|
t.Fatalf("the store took %q", bad)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestR1398_BindTakesPlainFlagsAndEmpty(t *testing.T) {
|
|
for in, want := range map[string]string{
|
|
"": "",
|
|
" ": "",
|
|
"--accept-small-disk": "--accept-small-disk",
|
|
" --accept-small-disk\t--no-oob ": "--accept-small-disk --no-oob",
|
|
} {
|
|
got, err := store.CleanApplianceExtraArgs(in)
|
|
if err != nil || got != want {
|
|
t.Errorf("CleanApplianceExtraArgs(%q) = %q, %v; want %q", in, got, err, want)
|
|
}
|
|
}
|
|
}
|