forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_session_test.go
76 lines (67 loc) · 2.15 KB
/
server_session_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package quic
import (
"github.com/boisjacques/qed/internal/protocol"
"github.com/boisjacques/qed/internal/utils"
"github.com/boisjacques/qed/internal/wire"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Server Session", func() {
var (
qsess *MockQuicSession
sess *serverSession
)
BeforeEach(func() {
qsess = NewMockQuicSession(mockCtrl)
sess = newServerSession(qsess, &Config{}, utils.DefaultLogger).(*serverSession)
})
It("handles packets", func() {
p := &receivedPacket{
header: &wire.Header{DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5}},
}
qsess.EXPECT().handlePacket(p)
sess.handlePacket(p)
})
It("ignores delayed packets with mismatching versions", func() {
qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
// don't EXPECT any calls to handlePacket()
p := &receivedPacket{
header: &wire.Header{
IsLongHeader: true,
Version: protocol.VersionNumber(123),
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
},
}
err := sess.handlePacketImpl(p)
Expect(err).ToNot(HaveOccurred())
})
It("ignores packets with the wrong Long Header type", func() {
qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
p := &receivedPacket{
header: &wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeRetry,
Version: protocol.VersionNumber(100),
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
},
}
err := sess.handlePacketImpl(p)
Expect(err).To(MatchError("Received unsupported packet type: Retry"))
})
It("passes on Handshake packets", func() {
p := &receivedPacket{
header: &wire.Header{
IsLongHeader: true,
Type: protocol.PacketTypeHandshake,
Version: protocol.VersionNumber(100),
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
},
}
qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
qsess.EXPECT().handlePacket(p)
Expect(sess.handlePacketImpl(p)).To(Succeed())
})
It("has the right perspective", func() {
Expect(sess.GetPerspective()).To(Equal(protocol.PerspectiveServer))
})
})