use an errors.As comparison to detect stateless resets in the session

This commit is contained in:
Marten Seemann 2020-07-10 11:13:36 +07:00
parent e7fa420e26
commit 1f676c2a6c
4 changed files with 29 additions and 9 deletions

View file

@ -242,10 +242,12 @@ var _ = Describe("Packet Handler Map", func() {
packet = append(packet, token[:]...)
destroyed := make(chan struct{})
packetHandler.EXPECT().destroy(gomock.Any()).Do(func(err error) {
defer GinkgoRecover()
Expect(err).To(HaveOccurred())
Expect(err).To(BeAssignableToTypeOf(&statelessResetErr{}))
var resetErr statelessResetErr
Expect(errors.As(err, &resetErr)).To(BeTrue())
Expect(err.Error()).To(ContainSubstring("received a stateless reset"))
Expect(*err.(*statelessResetErr).StatelessResetToken()).To(Equal(token))
Expect(resetErr.token).To(Equal(&token))
close(destroyed)
})
conn.dataToRead <- packet
@ -261,10 +263,12 @@ var _ = Describe("Packet Handler Map", func() {
packet = append(packet, token[:]...)
destroyed := make(chan struct{})
packetHandler.EXPECT().destroy(gomock.Any()).Do(func(err error) {
defer GinkgoRecover()
Expect(err).To(HaveOccurred())
Expect(err).To(BeAssignableToTypeOf(&statelessResetErr{}))
var resetErr statelessResetErr
Expect(errors.As(err, &resetErr)).To(BeTrue())
Expect(err.Error()).To(ContainSubstring("received a stateless reset"))
Expect(*err.(*statelessResetErr).StatelessResetToken()).To(Equal(token))
Expect(resetErr.token).To(Equal(&token))
close(destroyed)
})
conn.dataToRead <- packet