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, "")] 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) } } }