-
Notifications
You must be signed in to change notification settings - Fork 11
/
connection_integration_test.go
94 lines (73 loc) · 1.92 KB
/
connection_integration_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package yagnats
import (
"crypto/x509"
"os/exec"
. "gopkg.in/check.v1"
)
type TLSSuite struct {
Client *Client
NatsConn NATSConn
NatsCmd *exec.Cmd
}
var _ = Suite(&TLSSuite{})
func (t *TLSSuite) SetUpSuite(c *C) {
t.NatsCmd = startNatsTLS(4555)
waitUntilNatsUp(4555)
}
func (t *TLSSuite) TearDownSuite(c *C) {
stopCmd(t.NatsCmd)
}
func (t *TLSSuite) TestNewTLSConnection(c *C) {
client := NewClient()
roots := x509.NewCertPool()
ok := roots.AppendCertsFromPEM(ValidCA)
c.Assert(ok, Equals, true)
err := client.Connect(&ConnectionInfo{Addr: "127.0.0.1:4555",
Username: "nats",
Password: "nats",
TLSInfo: &ConnectionTLSInfo{
CertPool: roots,
},
})
c.Assert(err, IsNil)
t.Client = client
pingSuccess := client.Ping()
c.Assert(pingSuccess, Equals, true)
}
func (t *TLSSuite) TestNewTLSConnectionWithWrongCA(c *C) {
client := NewClient()
roots := x509.NewCertPool()
ok := roots.AppendCertsFromPEM(InvalidCA)
c.Assert(ok, Equals, true)
err := client.Connect(&ConnectionInfo{Addr: "127.0.0.1:4555",
Username: "nats",
Password: "nats",
TLSInfo: &ConnectionTLSInfo{
CertPool: roots,
},
})
c.Assert(err, NotNil)
c.Assert(err.Error(), Matches, "^x509: certificate signed by unknown authority.*$")
}
func (t *TLSSuite) TestNewTLSConnectionWithEmptyCertPool(c *C) {
client := NewClient()
err := client.Connect(&ConnectionInfo{Addr: "127.0.0.1:4555",
Username: "nats",
Password: "nats",
TLSInfo: &ConnectionTLSInfo{
CertPool: x509.NewCertPool(),
},
})
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "x509: certificate signed by unknown authority")
}
func (t *TLSSuite) TestNewTLSConnectionWithNoCertPool(c *C) {
client := NewClient()
err := client.Connect(&ConnectionInfo{Addr: "127.0.0.1:4555",
Username: "nats",
Password: "nats",
TLSInfo: &ConnectionTLSInfo{},
})
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "x509: certificate signed by unknown authority")
}