package wire_test import ( "amadan.net/oficina/equipo/internal/wire" "strings" "testing" ) func TestInjectionProtocolDowngrade(t *testing.T) { if wire.ProtocolInjectionDefences != 28 || wire.ProtocolCurrent != 38 { t.Fatal("injection guarantees require protocol 28") } for version, want := range map[int]int{26: 26, 27: 27, 28: 28, 29: 29, 30: 30, 31: 31, 32: 32, 33: 33, 34: 34, 35: 35, 36: 36, 37: 37, 38: 38, 99: 38} { if got := wire.Spoken(version); got != want { t.Fatalf("negotiated %d as %d, want %d", version, got, want) } } for _, tc := range []struct { kind string body any keys []string }{ {wire.FrameStep, wire.StepReport{BaseChecks: wire.ChecksFailed, BaseChecksSHA: strings.Repeat("a", 40), Change: &wire.ChangeFacts{GateFilesChanged: true, ReviewTruncated: true}}, []string{"base_checks", "base_checks_sha", "gate_files_changed", "review_truncated"}}, {wire.FrameDispatch, wire.DispatchCommand{PersonWords: []string{"Don't publish"}}, []string{"person_words"}}, } { f, err := wire.NewFrame("test", tc.kind, tc.body) if err != nil { t.Fatal(err) } for _, protocol := range []int{wire.Protocol27, wire.Protocol26, wire.Protocol21, wire.Protocol1} { old, err := wire.Encode(f, protocol) if err != nil { t.Fatal(err) } for _, key := range tc.keys { if strings.Contains(string(old.Data), key) { t.Fatalf("protocol %d retained %s: %s", protocol, key, old.Data) } } } current, err := wire.Encode(f, wire.ProtocolInjectionDefences) if err != nil { t.Fatal(err) } for _, key := range tc.keys { if !strings.Contains(string(current.Data), key) { t.Fatalf("current protocol lost %s", key) } } } }