server_session_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package quic
  2. import (
  3. "github.com/lucas-clemente/quic-go/internal/protocol"
  4. "github.com/lucas-clemente/quic-go/internal/utils"
  5. "github.com/lucas-clemente/quic-go/internal/wire"
  6. . "github.com/onsi/ginkgo"
  7. . "github.com/onsi/gomega"
  8. )
  9. var _ = Describe("Server Session", func() {
  10. var (
  11. qsess *MockQuicSession
  12. sess *serverSession
  13. )
  14. BeforeEach(func() {
  15. qsess = NewMockQuicSession(mockCtrl)
  16. sess = newServerSession(qsess, &Config{}, utils.DefaultLogger).(*serverSession)
  17. })
  18. It("handles packets", func() {
  19. p := &receivedPacket{
  20. header: &wire.Header{DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5}},
  21. }
  22. qsess.EXPECT().handlePacket(p)
  23. sess.handlePacket(p)
  24. })
  25. It("ignores Public Resets", func() {
  26. p := &receivedPacket{
  27. header: &wire.Header{
  28. ResetFlag: true,
  29. DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
  30. },
  31. }
  32. err := sess.handlePacketImpl(p)
  33. Expect(err).To(MatchError("Received unexpected Public Reset for connection 0xdeadbeef"))
  34. })
  35. It("ignores delayed packets with mismatching versions, for gQUIC", func() {
  36. qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
  37. // don't EXPECT any calls to handlePacket()
  38. p := &receivedPacket{
  39. header: &wire.Header{
  40. VersionFlag: true,
  41. Version: protocol.VersionNumber(123),
  42. DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
  43. },
  44. }
  45. err := sess.handlePacketImpl(p)
  46. Expect(err).ToNot(HaveOccurred())
  47. })
  48. It("ignores delayed packets with mismatching versions, for IETF QUIC", func() {
  49. qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
  50. // don't EXPECT any calls to handlePacket()
  51. p := &receivedPacket{
  52. header: &wire.Header{
  53. IsLongHeader: true,
  54. Version: protocol.VersionNumber(123),
  55. DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
  56. },
  57. }
  58. err := sess.handlePacketImpl(p)
  59. Expect(err).ToNot(HaveOccurred())
  60. })
  61. It("ignores packets with the wrong Long Header type", func() {
  62. qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
  63. p := &receivedPacket{
  64. header: &wire.Header{
  65. IsLongHeader: true,
  66. Type: protocol.PacketTypeRetry,
  67. Version: protocol.VersionNumber(100),
  68. DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
  69. },
  70. }
  71. err := sess.handlePacketImpl(p)
  72. Expect(err).To(MatchError("Received unsupported packet type: Retry"))
  73. })
  74. It("passes on Handshake packets", func() {
  75. p := &receivedPacket{
  76. header: &wire.Header{
  77. IsLongHeader: true,
  78. Type: protocol.PacketTypeHandshake,
  79. Version: protocol.VersionNumber(100),
  80. DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
  81. },
  82. }
  83. qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
  84. qsess.EXPECT().handlePacket(p)
  85. Expect(sess.handlePacketImpl(p)).To(Succeed())
  86. })
  87. It("has the right perspective", func() {
  88. Expect(sess.GetPerspective()).To(Equal(protocol.PerspectiveServer))
  89. })
  90. })