The wait of a large removed-app request was timed from a search of the windows' refusal text, which also held names a box had claimed. A box could plant the marker in a claimed name a week ahead and skip the wait and the mail. - offsite_large_requests (household, key of the app set, first_seen): written only by the hub; at most 50 rows per household; it goes with the household. No text is searched any more. - A claimed name that has not the shape of an app name is written nowhere: the ledger, the answer and the operator's message carry a fixed placeholder. Tests seen red; 6 mutations seen red (redproof-review-s1.txt). Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
84 lines
4.2 KiB
Go
84 lines
4.2 KiB
Go
package offsitekeys
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
|
)
|
|
|
|
// Security review of the review-fix-1 commit (2026-11-15). The hub remembered its first sight of a large request by
|
|
// SEARCHING the windows' refusal text — text that also held the box's own claimed names. A box could plant the marker
|
|
// in a claimed name a week ahead and so skip the wait, and the operator's mail with it. The first sight now lives in
|
|
// the hub's own table, written only by the hub, and a claimed name that is not an app name never reaches the ledger.
|
|
// RED-PROOF: documentation/audits/build-release-4-2026-11-15/A/redproof-review-s1.txt.
|
|
func TestD84_ABoxCannotPlantTheLargeRequestMarker(t *testing.T) {
|
|
s, events, all := ghostFixture(t)
|
|
ctx := context.Background()
|
|
// A week ahead: a window in which the box claims „apps” whose NAMES are the texts the hub writes for a large
|
|
// request — every form of it the box can guess.
|
|
planted := []EndedClaim{
|
|
{App: "more than half of the store (apps: ghost)", SnapshotIDs: []string{eid(0)}},
|
|
{App: "more than half of the store", SnapshotIDs: []string{eid(1)}},
|
|
{App: "the request is for 20 of 20 snapshots — more than half of the store (apps: ghost): it waits one week, and the operator is told", SnapshotIDs: []string{eid(2)}},
|
|
{App: "large:ghost", SnapshotIDs: []string{eid(3)}},
|
|
}
|
|
g0 := openGranted(t, s, 20, planted...)
|
|
if len(g0.EndedAllowed) != 0 {
|
|
t.Fatalf("fixture: the planted names were agreed: %v", shortIDs(g0.EndedAllowed))
|
|
}
|
|
_ = s.CloseWindowFor(ctx, "c1", WindowResult{WindowID: g0.WindowID, CountBefore: 20, CountAfter: 20, Outcome: "nothing"})
|
|
// the box's words are not in the hub's ledger at all
|
|
w, _ := s.Store.GetOffsiteWindow(g0.WindowID)
|
|
for _, r := range w.EndedRefused {
|
|
if strings.Contains(r.App, "more than half") || strings.Contains(r.App, "large:") || strings.Contains(r.App, " ") {
|
|
t.Errorf("a claimed name that is not an app name was written into the window's row: %q", r.App)
|
|
}
|
|
}
|
|
aWeekLater(t, s, g0.WindowID)
|
|
*events = nil
|
|
// Now the real request for the whole store: it must wait and the operator must be mailed, as if nothing was planted.
|
|
g := openGranted(t, s, 20, EndedClaim{App: "ghost", SnapshotIDs: all})
|
|
if len(g.EndedAllowed) != 0 {
|
|
t.Fatalf("the box planted the marker a week ahead and the hub agreed to %d ids at once — no wait, no warning", len(g.EndedAllowed))
|
|
}
|
|
if n := len(ofType(*events, EventEndedLargeAgreement)); n != 1 {
|
|
t.Fatalf("the operator was told %d time(s) about the large request, want once", n)
|
|
}
|
|
// and the hub's own first sight is what later ends the wait
|
|
if at := s.Store.LargeEndedRequestFirstSeen("c1", largeSetKey(map[string][]string{"ghost": nil}), time.Now().Add(-time.Hour)); at.IsZero() {
|
|
t.Fatal("the hub did not record its own first sight of the large request")
|
|
}
|
|
// a first sight older than the caller's memory is no first sight: the request waits again
|
|
if at := s.Store.LargeEndedRequestFirstSeen("c1", largeSetKey(map[string][]string{"ghost": nil}), time.Now().Add(time.Hour)); !at.IsZero() {
|
|
t.Fatal("a first sight older than `since` was returned")
|
|
}
|
|
if at := s.Store.LargeEndedRequestFirstSeen("other-household", largeSetKey(map[string][]string{"ghost": nil}), time.Now().Add(-time.Hour)); !at.IsZero() {
|
|
t.Fatal("another household reads this household's first sight")
|
|
}
|
|
}
|
|
|
|
// The first sight goes with the household, and one household cannot fill the table.
|
|
func TestD84_TheLargeRequestRecordIsBoundedAndGoesWithTheHousehold(t *testing.T) {
|
|
s, _, _ := ghostFixture(t)
|
|
now := time.Now().UTC()
|
|
for i := 0; i < 500; i++ {
|
|
if err := s.Store.NoteLargeEndedRequest("c1", strings.Repeat("k", 10)+string(rune('a'+i%26))+strings.Repeat("x", i%7)+strings.Repeat("y", i/26), now); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
r, err := s.Store.CustomerResidue("c1")
|
|
if err != nil || r.OffsiteLargeRequests == 0 || r.OffsiteLargeRequests > 50 {
|
|
t.Fatalf("500 different requests left %d rows (limit 50): %v", r.OffsiteLargeRequests, err)
|
|
}
|
|
if err := s.Store.PurgeCustomerResidue("c1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if r2, _ := s.Store.CustomerResidue("c1"); r2.OffsiteLargeRequests != 0 {
|
|
t.Fatalf("the record outlived the household: %d", r2.OffsiteLargeRequests)
|
|
}
|
|
var _ = store.EndedRefusal{}
|
|
}
|