server_session_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. hdr: &wire.Header{
  21. DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5},
  22. },
  23. }
  24. qsess.EXPECT().handlePacket(p)
  25. sess.handlePacket(p)
  26. })
  27. It("ignores delayed packets with mismatching versions", func() {
  28. qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
  29. // don't EXPECT any calls to handlePacket()
  30. p := &receivedPacket{
  31. hdr: &wire.Header{
  32. IsLongHeader: true,
  33. Version: protocol.VersionNumber(123),
  34. DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
  35. },
  36. }
  37. err := sess.handlePacketImpl(p)
  38. Expect(err).ToNot(HaveOccurred())
  39. })
  40. It("ignores packets with the wrong Long Header type", func() {
  41. qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
  42. p := &receivedPacket{
  43. hdr: &wire.Header{
  44. IsLongHeader: true,
  45. Type: protocol.PacketTypeRetry,
  46. Version: protocol.VersionNumber(100),
  47. DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
  48. },
  49. }
  50. err := sess.handlePacketImpl(p)
  51. Expect(err).To(MatchError("Received unsupported packet type: Retry"))
  52. })
  53. It("passes on Handshake packets", func() {
  54. p := &receivedPacket{
  55. hdr: &wire.Header{
  56. IsLongHeader: true,
  57. Type: protocol.PacketTypeHandshake,
  58. Version: protocol.VersionNumber(100),
  59. DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
  60. },
  61. }
  62. qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
  63. qsess.EXPECT().handlePacket(p)
  64. Expect(sess.handlePacketImpl(p)).To(Succeed())
  65. })
  66. It("has the right perspective", func() {
  67. Expect(sess.GetPerspective()).To(Equal(protocol.PerspectiveServer))
  68. })
  69. })