corrupt more ACKs in the MITM test

This commit is contained in:
Marten Seemann
2021-01-18 19:10:57 +08:00
parent 492429aed5
commit 70fe7be603

View File

@@ -215,19 +215,19 @@ var _ = Describe("MITM test", func() {
}) })
Context("corrupting packets", func() { Context("corrupting packets", func() {
const interval = 10 // corrupt every 10th packet (stochastically)
const idleTimeout = time.Second const idleTimeout = time.Second
var numCorrupted int32 var numCorrupted, numPackets int32
BeforeEach(func() { BeforeEach(func() {
numCorrupted = 0 numCorrupted = 0
numPackets = 0
serverConfig.MaxIdleTimeout = idleTimeout serverConfig.MaxIdleTimeout = idleTimeout
}) })
AfterEach(func() { AfterEach(func() {
num := atomic.LoadInt32(&numCorrupted) 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)) Expect(num).To(BeNumerically(">=", 1))
// If the packet containing the CONNECTION_CLOSE is corrupted, // If the packet containing the CONNECTION_CLOSE is corrupted,
// we have to wait for the session to time out. // 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() { 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 { dropCb := func(dir quicproxy.Direction, raw []byte) bool {
defer GinkgoRecover() defer GinkgoRecover()
if dir == quicproxy.DirectionIncoming && mrand.Intn(interval) == 0 { if dir == quicproxy.DirectionIncoming {
pos := mrand.Intn(len(raw)) atomic.AddInt32(&numPackets, 1)
raw[pos] = byte(mrand.Intn(256)) if mrand.Intn(interval) == 0 {
_, err := clientConn.WriteTo(raw, serverConn.LocalAddr()) pos := mrand.Intn(len(raw))
Expect(err).ToNot(HaveOccurred()) raw[pos] = byte(mrand.Intn(256))
atomic.AddInt32(&numCorrupted, 1) _, err := clientConn.WriteTo(raw, serverConn.LocalAddr())
return true Expect(err).ToNot(HaveOccurred())
atomic.AddInt32(&numCorrupted, 1)
return true
}
} }
return false return false
} }
@@ -251,15 +255,19 @@ var _ = Describe("MITM test", func() {
}) })
It("downloads a message when packet are corrupted towards the client", 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 { dropCb := func(dir quicproxy.Direction, raw []byte) bool {
defer GinkgoRecover() defer GinkgoRecover()
if dir == quicproxy.DirectionOutgoing && mrand.Intn(interval) == 0 { if dir == quicproxy.DirectionOutgoing {
pos := mrand.Intn(len(raw)) atomic.AddInt32(&numPackets, 1)
raw[pos] = byte(mrand.Intn(256)) if mrand.Intn(interval) == 0 {
_, err := serverConn.WriteTo(raw, clientConn.LocalAddr()) pos := mrand.Intn(len(raw))
Expect(err).ToNot(HaveOccurred()) raw[pos] = byte(mrand.Intn(256))
atomic.AddInt32(&numCorrupted, 1) _, err := serverConn.WriteTo(raw, clientConn.LocalAddr())
return true Expect(err).ToNot(HaveOccurred())
atomic.AddInt32(&numCorrupted, 1)
return true
}
} }
return false return false
} }