2022-04-05 14:26:14 +00:00
|
|
|
package connectca
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/consul/state"
|
2022-04-12 13:47:42 +00:00
|
|
|
"github.com/hashicorp/consul/agent/consul/stream"
|
2022-04-21 16:56:18 +00:00
|
|
|
"github.com/hashicorp/consul/agent/grpc/public/testutils"
|
|
|
|
structs "github.com/hashicorp/consul/agent/structs"
|
2022-04-05 14:26:14 +00:00
|
|
|
"github.com/hashicorp/consul/proto-public/pbconnectca"
|
|
|
|
)
|
|
|
|
|
2022-04-14 13:26:14 +00:00
|
|
|
func noopForwardRPC(structs.RPCInfo, func(*grpc.ClientConn) error) (bool, error) {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2022-04-21 16:56:18 +00:00
|
|
|
func setupFSMAndPublisher(t *testing.T) (*testutils.FakeFSM, state.EventPublisher) {
|
2022-04-05 14:26:14 +00:00
|
|
|
t.Helper()
|
|
|
|
|
2022-04-21 16:56:18 +00:00
|
|
|
config := testutils.FakeFSMConfig{
|
|
|
|
Register: func(fsm *testutils.FakeFSM, publisher *stream.EventPublisher) {
|
|
|
|
// register handlers
|
|
|
|
publisher.RegisterHandler(state.EventTopicCARoots, func(req stream.SubscribeRequest, buf stream.SnapshotAppender) (uint64, error) {
|
|
|
|
return fsm.GetStore().CARootsSnapshot(req, buf)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
Refresh: []stream.Topic{state.EventTopicCARoots},
|
|
|
|
}
|
2022-04-12 13:47:42 +00:00
|
|
|
|
2022-04-21 16:56:18 +00:00
|
|
|
return testutils.SetupFSMAndPublisher(t, config)
|
2022-04-05 14:26:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testClient(t *testing.T, server *Server) pbconnectca.ConnectCAServiceClient {
|
|
|
|
t.Helper()
|
|
|
|
|
2022-04-21 16:56:18 +00:00
|
|
|
addr := testutils.RunTestServer(t, server)
|
2022-04-05 14:26:14 +00:00
|
|
|
|
|
|
|
conn, err := grpc.DialContext(context.Background(), addr.String(), grpc.WithInsecure())
|
|
|
|
require.NoError(t, err)
|
|
|
|
t.Cleanup(func() {
|
|
|
|
require.NoError(t, conn.Close())
|
|
|
|
})
|
|
|
|
|
|
|
|
return pbconnectca.NewConnectCAServiceClient(conn)
|
|
|
|
}
|