-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlive_test.go
More file actions
80 lines (61 loc) · 1.61 KB
/
live_test.go
File metadata and controls
80 lines (61 loc) · 1.61 KB
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
77
78
79
80
package toyls
import (
"flag"
"net"
"time"
"crypto/tls"
"crypto/x509"
. "gopkg.in/check.v1"
)
var live = flag.Bool("live", false, "Include live tests")
type LiveToySuite struct{}
var _ = Suite(&LiveToySuite{})
func (s *LiveToySuite) SetUpSuite(c *C) {
if !*live {
c.Skip("-live not provided")
}
}
func (s *LiveToySuite) TestHandshakeAndApplicationData(c *C) {
cert, err := tls.X509KeyPair([]byte(rsaCertPEM), []byte(rsaKeyPEM))
c.Assert(err, IsNil)
c.Assert(len(cert.Certificate), Equals, 1)
c.Assert(len(cert.Certificate[0]), Equals, 0x0392)
roots := x509.NewCertPool()
ok := roots.AppendCertsFromPEM([]byte(rsaCertPEM))
c.Assert(ok, Equals, true)
tlsConf := &tls.Config{
RootCAs: roots,
//Time: func() time.Time { return time.Unix(0, 0) },
}
l, err := net.Listen("tcp", ":12345")
c.Assert(err, IsNil)
go func() {
conn, err := l.Accept()
c.Assert(err, IsNil)
server := newServer()
server.handshaker.(*handshakeServer).Certificate = cert
server.rawConn = conn
reply := make([]byte, 12)
server.Read(reply)
c.Assert(reply, DeepEquals, []byte("hello server"))
server.Write([]byte("hello client"))
}()
conn, err := Dial("tcp", ":12345", tlsConf)
if err != nil {
panic("failed to connect: " + err.Error())
}
_, err = conn.Write([]byte("hello server"))
c.Assert(err, IsNil)
reply := make([]byte, 6)
conn.Read(reply)
c.Assert(reply, DeepEquals, []byte("hello "))
reply = make([]byte, 6)
conn.Read(reply)
c.Assert(reply, DeepEquals, []byte("client"))
defer func() {
c.Assert(recover(), NotNil)
}()
conn.SetReadDeadline(time.Now())
reply = make([]byte, 1)
conn.Read(reply)
}