Cover malformed fetch packets after startup · Entire
Cover malformed fetch packets after startup
8ba4146→main·
Soph·3mo ago·2 files·+121 added/-1 removed
Sessions
50ad337b37fcView transcript
Changes
2
docs
Mrewrite-issue-list.md+2/-1
internal/gitproto
Mfetch_test.go+119
444 unmodified lines
445
446
447
448
448
449
450
451
452
444 unmodified lines
- Injected temp-ref delete failure during batched cutover is now covered end-to-end, including successful recovery on retry.
- Injected checkpoint pack failure after partial batched progress is now covered end-to-end, including successful resume on retry.
- `fetchToStoreV2` now also has direct coverage for cancellation after response parsing has started.
- Some harder transport-interruption and malformed mid-stream failure paths still remain, but the remaining gap is narrower than the original list.
- V1 and v2 fetch paths now also have direct parser-level coverage for malformed sideband framing after a valid response prelude, both for returned streaming readers and for v2 fetch-to-store cleanup.
- Some harder transport-interruption and broader end-to-end cancellation paths still remain, but the remaining gap is narrower than the original list.
### 22. No benchmark coverage for the expensive paths
Mdocs/rewrite-issue-list.md+2/-1
629 unmodified lines
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
86 unmodified lines
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
629 unmodified lines
}
}
func TestFetchPackV1ReturnedReaderErrorsOnMalformedMidStreamPacket(t *testing.T) {
ep, err := transport.NewEndpoint("https://example.com/repo.git")
if err != nil {
t.Fatalf("parse endpoint: %v", err)
}
body := &trackingReadCloser{ReadCloser: io.NopCloser(bytes.NewBufferString("0008NAK\nzzzz"))}
conn := NewConn(ep, "source", nil, roundTripperFunc(func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Request: req,
Body: body,
}, nil
}))
adv := packp.NewAdvRefs()
_ = adv.Capabilities.Set(capability.Sideband64k)
desired := map[plumbing.ReferenceName]DesiredRef{
plumbing.NewBranchReferenceName("main"): {
SourceRef: plumbing.NewBranchReferenceName("main"),
TargetRef: plumbing.NewBranchReferenceName("main"),
SourceHash: plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
},
}
rc, err := fetchPackV1(context.Background(), conn, adv, desired, nil)
if err != nil {
t.Fatalf("fetchPackV1: %v", err)
}
_, err = io.ReadAll(rc)
if err == nil {
t.Fatal("expected malformed mid-stream sideband error")
}
if closeErr := rc.Close(); closeErr != nil {
t.Fatalf("close returned reader: %v", closeErr)
}
if !body.closed {
t.Fatal("expected returned reader close to close underlying body")
}
}
func TestFetchPackV2ClosesBodyOnDecodeError(t *testing.T) {
ep, err := transport.NewEndpoint("https://example.com/repo.git")
if err != nil {
t.Fatalf("parse endpoint: %v", err)
}
body := &trackingReadCloser{ReadCloser: io.NopCloser(bytes.NewBufferString(FormatPktLine("packfile\n") + "zzzz"))}
conn := NewConn(ep, "source", nil, roundTripperFunc(func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Request: req,
Body: body,
}, nil
}))
caps := &V2Capabilities{
Caps: map[string]string{
"fetch": "",
},
}
desired := map[plumbing.ReferenceName]DesiredRef{
plumbing.NewBranchReferenceName("main"): {
SourceRef: plumbing.NewBranchReferenceName("main"),
TargetRef: plumbing.NewBranchReferenceName("main"),
SourceHash: plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
},
}
rc, err := fetchPackV2(context.Background(), conn, caps, desired, nil)
if err != nil {
t.Fatalf("fetchPackV2: %v", err)
}
_, err = io.ReadAll(rc)
if err == nil {
t.Fatal("expected malformed mid-stream sideband error")
}
if closeErr := rc.Close(); closeErr != nil {
t.Fatalf("close returned reader: %v", closeErr)
}
if !body.closed {
t.Fatal("expected returned reader close to close underlying body")
}
}
func TestFetchToStoreV2ClosesBodyOnMalformedMidStreamPacket(t *testing.T) {
ep, err := transport.NewEndpoint("https://example.com/repo.git")
if err != nil {
t.Fatalf("parse endpoint: %v", err)
}
body := &trackingReadCloser{ReadCloser: io.NopCloser(bytes.NewBufferString(FormatPktLine("packfile\n") + "zzzz"))}
conn := NewConn(ep, "source", nil, roundTripperFunc(func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
Request: req,
Body: body,
}, nil
}))
err = fetchToStoreV2(context.Background(), memory.NewStorage(), conn, caps, desired, nil)
if err == nil {
t.Fatal("expected malformed mid-stream sideband error")
}
if !body.closed {
t.Fatal("expected response body to be closed on malformed mid-stream packet")
}
}
func TestBuildV1UploadPackBodyEmptyWantSet(t *testing.T) {
adv := packp.NewAdvRefs()
_, _, err := buildV1UploadPackBody(adv, nil, nil, false)