From 70fe7be6034828bff17a5f02abec22dfa28702cf Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 18 Jan 2021 19:10:57 +0800 Subject: [PATCH] corrupt more ACKs in the MITM test --- integrationtests/self/mitm_test.go | 42 ++++++++++++++++++------------ 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/integrationtests/self/mitm_test.go b/integrationtests/self/mitm_test.go index c260b69a..dd7ea54b 100644 --- a/integrationtests/self/mitm_test.go +++ b/integrationtests/self/mitm_test.go @@ -215,19 +215,19 @@ var _ = Describe("MITM test", func() { }) Context("corrupting packets", func() { - const interval = 10 // corrupt every 10th packet (stochastically) const idleTimeout = time.Second - var numCorrupted int32 + var numCorrupted, numPackets int32 BeforeEach(func() { numCorrupted = 0 + numPackets = 0 serverConfig.MaxIdleTimeout = idleTimeout }) AfterEach(func() { num := atomic.LoadInt32(&numCorrupted) - fmt.Fprintf(GinkgoWriter, "Corrupted %d packets.", num) + fmt.Fprintf(GinkgoWriter, "Corrupted %d of %d packets.", num, atomic.LoadInt32(&numPackets)) Expect(num).To(BeNumerically(">=", 1)) // If the packet containing the CONNECTION_CLOSE is corrupted, // we have to wait for the session to time out. @@ -235,15 +235,19 @@ var _ = Describe("MITM test", func() { }) It("downloads a message when packet are corrupted towards the server", func() { + const interval = 4 // corrupt every 4th packet (stochastically) dropCb := func(dir quicproxy.Direction, raw []byte) bool { defer GinkgoRecover() - if dir == quicproxy.DirectionIncoming && mrand.Intn(interval) == 0 { - pos := mrand.Intn(len(raw)) - raw[pos] = byte(mrand.Intn(256)) - _, err := clientConn.WriteTo(raw, serverConn.LocalAddr()) - Expect(err).ToNot(HaveOccurred()) - atomic.AddInt32(&numCorrupted, 1) - return true + if dir == quicproxy.DirectionIncoming { + atomic.AddInt32(&numPackets, 1) + if mrand.Intn(interval) == 0 { + pos := mrand.Intn(len(raw)) + raw[pos] = byte(mrand.Intn(256)) + _, err := clientConn.WriteTo(raw, serverConn.LocalAddr()) + Expect(err).ToNot(HaveOccurred()) + atomic.AddInt32(&numCorrupted, 1) + return true + } } return false } @@ -251,15 +255,19 @@ var _ = Describe("MITM test", func() { }) It("downloads a message when packet are corrupted towards the client", func() { + const interval = 10 // corrupt every 10th packet (stochastically) dropCb := func(dir quicproxy.Direction, raw []byte) bool { defer GinkgoRecover() - if dir == quicproxy.DirectionOutgoing && mrand.Intn(interval) == 0 { - pos := mrand.Intn(len(raw)) - raw[pos] = byte(mrand.Intn(256)) - _, err := serverConn.WriteTo(raw, clientConn.LocalAddr()) - Expect(err).ToNot(HaveOccurred()) - atomic.AddInt32(&numCorrupted, 1) - return true + if dir == quicproxy.DirectionOutgoing { + atomic.AddInt32(&numPackets, 1) + if mrand.Intn(interval) == 0 { + pos := mrand.Intn(len(raw)) + raw[pos] = byte(mrand.Intn(256)) + _, err := serverConn.WriteTo(raw, clientConn.LocalAddr()) + Expect(err).ToNot(HaveOccurred()) + atomic.AddInt32(&numCorrupted, 1) + return true + } } return false }