2018-02-06 21:03:09 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/client/config"
|
|
|
|
"github.com/hashicorp/nomad/nomad"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2018-02-15 23:22:57 +00:00
|
|
|
sconfig "github.com/hashicorp/nomad/nomad/structs/config"
|
2018-02-06 21:03:09 +00:00
|
|
|
"github.com/hashicorp/nomad/testutil"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRpc_streamingRpcConn_badEndpoint(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
2019-12-04 00:15:11 +00:00
|
|
|
|
|
|
|
s1, cleanupS1 := nomad.TestServer(t, nil)
|
|
|
|
defer cleanupS1()
|
2018-02-06 21:03:09 +00:00
|
|
|
testutil.WaitForLeader(t, s1.RPC)
|
|
|
|
|
2019-12-04 00:15:11 +00:00
|
|
|
c, cleanupC := TestClient(t, func(c *config.Config) {
|
2018-02-06 21:03:09 +00:00
|
|
|
c.Servers = []string{s1.GetConfig().RPCAddr.String()}
|
|
|
|
})
|
2019-12-04 00:15:11 +00:00
|
|
|
defer cleanupC()
|
2018-02-06 21:03:09 +00:00
|
|
|
|
|
|
|
// Wait for the client to connect
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
node, err := s1.State().NodeByID(nil, c.NodeID())
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
if node == nil {
|
|
|
|
return false, errors.New("no node")
|
|
|
|
}
|
|
|
|
|
|
|
|
return node.Status == structs.NodeStatusReady, errors.New("wrong status")
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("should have a clients")
|
|
|
|
})
|
|
|
|
|
|
|
|
// Get the server
|
|
|
|
server := c.servers.FindServer()
|
|
|
|
require.NotNil(server)
|
|
|
|
|
|
|
|
conn, err := c.streamingRpcConn(server, "Bogus")
|
|
|
|
require.Nil(conn)
|
|
|
|
require.NotNil(err)
|
2018-02-15 23:22:57 +00:00
|
|
|
require.Contains(err.Error(), "Unknown rpc method: \"Bogus\"")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRpc_streamingRpcConn_badEndpoint_TLS(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
const (
|
|
|
|
cafile = "../helper/tlsutil/testdata/ca.pem"
|
|
|
|
foocert = "../helper/tlsutil/testdata/nomad-foo.pem"
|
|
|
|
fookey = "../helper/tlsutil/testdata/nomad-foo-key.pem"
|
|
|
|
)
|
|
|
|
|
2019-12-04 00:15:11 +00:00
|
|
|
s1, cleanupS1 := nomad.TestServer(t, func(c *nomad.Config) {
|
2018-02-15 23:22:57 +00:00
|
|
|
c.Region = "regionFoo"
|
|
|
|
c.BootstrapExpect = 1
|
|
|
|
c.TLSConfig = &sconfig.TLSConfig{
|
|
|
|
EnableHTTP: true,
|
|
|
|
EnableRPC: true,
|
|
|
|
VerifyServerHostname: true,
|
|
|
|
CAFile: cafile,
|
|
|
|
CertFile: foocert,
|
|
|
|
KeyFile: fookey,
|
|
|
|
}
|
|
|
|
})
|
2019-12-04 00:15:11 +00:00
|
|
|
defer cleanupS1()
|
2018-02-15 23:22:57 +00:00
|
|
|
testutil.WaitForLeader(t, s1.RPC)
|
|
|
|
|
2019-12-04 00:15:11 +00:00
|
|
|
c, cleanupC := TestClient(t, func(c *config.Config) {
|
2018-02-15 23:22:57 +00:00
|
|
|
c.Region = "regionFoo"
|
|
|
|
c.Servers = []string{s1.GetConfig().RPCAddr.String()}
|
|
|
|
c.TLSConfig = &sconfig.TLSConfig{
|
|
|
|
EnableHTTP: true,
|
|
|
|
EnableRPC: true,
|
|
|
|
VerifyServerHostname: true,
|
|
|
|
CAFile: cafile,
|
|
|
|
CertFile: foocert,
|
|
|
|
KeyFile: fookey,
|
|
|
|
}
|
|
|
|
})
|
2019-12-04 00:15:11 +00:00
|
|
|
defer cleanupC()
|
2018-02-15 23:22:57 +00:00
|
|
|
|
|
|
|
// Wait for the client to connect
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
node, err := s1.State().NodeByID(nil, c.NodeID())
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
if node == nil {
|
|
|
|
return false, errors.New("no node")
|
|
|
|
}
|
|
|
|
|
|
|
|
return node.Status == structs.NodeStatusReady, errors.New("wrong status")
|
|
|
|
}, func(err error) {
|
|
|
|
t.Fatalf("should have a clients")
|
|
|
|
})
|
|
|
|
|
|
|
|
// Get the server
|
|
|
|
server := c.servers.FindServer()
|
|
|
|
require.NotNil(server)
|
|
|
|
|
|
|
|
conn, err := c.streamingRpcConn(server, "Bogus")
|
|
|
|
require.Nil(conn)
|
|
|
|
require.NotNil(err)
|
|
|
|
require.Contains(err.Error(), "Unknown rpc method: \"Bogus\"")
|
2018-02-06 21:03:09 +00:00
|
|
|
}
|