package api import ( "encoding/json" "net/http" "net/http/httptest" "strings" "testing" "gitea.dooplex.hu/admin/felhom-hub/internal/store" ) // Review of 2026-11-15, finding 5 — version skew. A hub that cannot read a window request must say so (400), never // decide a window on a count of 0; and it tells every box, in every answer, that it understands `ended` — a box sends // its end records only to a hub that said so. // RED-PROOF: documentation/audits/build-release-4-2026-11-15/A/redproof-review-5.txt. func TestD84_WindowOpen_ABodyTheHubCannotReadIs400(t *testing.T) { h, st, _ := newTestHandler(t) st.SaveCustomerConfig(&store.CustomerConfig{CustomerID: "c1", APIKey: "ckey", RetrievalPassword: "pp"}) f := &fakeKeySvc{} h.SetOffsiteKeyService(f) post := func(body string) *httptest.ResponseRecorder { req := httptest.NewRequest(http.MethodPost, "/api/v1/offsite/window-open/c1", strings.NewReader(body)) req.Header.Set("Authorization", "Bearer ckey") rr := httptest.NewRecorder() h.ServeHTTP(rr, req) return rr } for name, body := range map[string]string{ "cut in the middle (a read limit)": `{"count_before":20,"ended":[{"app":"vikunja","snapshot_ids":["aaaa","bb`, "not JSON": `count_before=20`, "a list, not an object": `[20]`, } { f.opened = 0 if rr := post(body); rr.Code != http.StatusBadRequest { t.Errorf("%s: HTTP %d, want 400 — the hub must not decide a window on a body it could not read", name, rr.Code) } if f.opened != 0 { t.Errorf("%s: the window service was asked although the body could not be read", name) } } // what every box has always sent still works — also the empty body of the oldest ones for _, body := range []string{`{"count_before":20}`, ``} { rr := post(body) if rr.Code != http.StatusOK { t.Errorf("body %q: HTTP %d, want 200", body, rr.Code) } // … and EVERY answer says that this hub understands ended apps — here a window that is NOT granted var ans map[string]any _ = json.Unmarshal(rr.Body.Bytes(), &ans) if ans["accepts_ended"] != true || ans["granted"] != false { t.Errorf("body %q: the answer %s does not say accepts_ended — a new box would never send its end records", body, rr.Body.String()) } } }