forked from quic-go/quic-go
corrupt more ACKs in the MITM test
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user