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-07-13 15:33:48 +00:00
|
|
|
"github.com/hashicorp/consul/agent/grpc-external/testutils"
|
2022-11-07 16:34:30 +00:00
|
|
|
"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)
|
proxycfg: server-local config entry data sources
This is the OSS portion of enterprise PR 2056.
This commit provides server-local implementations of the proxycfg.ConfigEntry
and proxycfg.ConfigEntryList interfaces, that source data from streaming events.
It makes use of the LocalMaterializer type introduced for peering replication,
adding the necessary support for authorization.
It also adds support for "wildcard" subscriptions (within a topic) to the event
publisher, as this is needed to fetch service-resolvers for all services when
configuring mesh gateways.
Currently, events will be emitted for just the ingress-gateway, service-resolver,
and mesh config entry types, as these are the only entries required by proxycfg
— the events will be emitted on topics named IngressGateway, ServiceResolver,
and MeshConfig topics respectively.
Though these events will only be consumed "locally" for now, they can also be
consumed via the gRPC endpoint (confirmed using grpcurl) so using them from
client agents should be a case of swapping the LocalMaterializer for an
RPCMaterializer.
2022-07-01 15:09:47 +00:00
|
|
|
}, false)
|
2022-04-21 16:56:18 +00:00
|
|
|
},
|
|
|
|
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
|
|
|
|
2022-11-07 16:34:30 +00:00
|
|
|
//nolint:staticcheck
|
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)
|
|
|
|
}
|