github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/integration/suites/leafnodes/leafnodes_test.go (about) 1 // Copyright (c) 2022, R.I. Pienaar and the Choria Project contributors 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 package leafnodes 6 7 import ( 8 "context" 9 "sync" 10 "testing" 11 "time" 12 13 "github.com/choria-io/go-choria/config" 14 "github.com/choria-io/go-choria/providers/discovery/broadcast" 15 16 "github.com/choria-io/go-choria/choria" 17 "github.com/choria-io/go-choria/integration/testbroker" 18 "github.com/choria-io/go-choria/integration/testutil" 19 . "github.com/onsi/ginkgo/v2" 20 . "github.com/onsi/gomega" 21 "github.com/onsi/gomega/gbytes" 22 "github.com/sirupsen/logrus" 23 ) 24 25 // TestBrokerLeafnode tests leafnode connections especially as relates to new auth behavior 26 func TestBrokerLeafnode(t *testing.T) { 27 RegisterFailHandler(Fail) 28 RunSpecs(t, "Integration/Leafnodes") 29 } 30 31 var _ = Describe("Leafnodes", func() { 32 var ( 33 ctx context.Context 34 cancel context.CancelFunc 35 wg sync.WaitGroup 36 logger *logrus.Logger 37 logbuff *gbytes.Buffer 38 ) 39 40 BeforeEach(func() { 41 ctx, cancel = context.WithTimeout(context.Background(), 45*time.Second) 42 DeferCleanup(func() { 43 cancel() 44 Eventually(logbuff, 5).Should(gbytes.Say("Choria Network Broker shut down")) 45 }) 46 47 logbuff, logger = testutil.GbytesLogger(logrus.DebugLevel) 48 }) 49 50 Describe("Basic Leafnode connection in mTLS mode", func() { 51 It("Should connect to a remote server", func() { 52 // start a core broker listening for leafnode connections 53 _, err := testbroker.StartNetworkBrokerWithConfigFile(ctx, &wg, "testdata/core.conf", logger) 54 Expect(err).ToNot(HaveOccurred()) 55 Eventually(logbuff, 1).Should(gbytes.Say("Starting Broker Leafnode support listening on :::7422")) 56 57 // start a choria server against the core broker with discovery agent 58 sbuff, slog := testutil.GbytesLogger(logrus.DebugLevel) 59 _, err = testutil.StartServerInstance(ctx, &wg, "testdata/core_server.conf", slog, testutil.ServerWithDiscovery()) 60 Expect(err).ToNot(HaveOccurred()) 61 Eventually(sbuff).Should(gbytes.Say("Connected to nats://localhost:4222")) 62 Eventually(sbuff).Should(gbytes.Say("Registering new agent discovery of type discovery")) 63 64 // start a leafnode broker connecting to core 65 lbuff, llog := testutil.GbytesLogger(logrus.DebugLevel) 66 _, err = testbroker.StartNetworkBrokerWithConfigFile(ctx, &wg, "testdata/leaf.conf", llog) 67 Expect(err).ToNot(HaveOccurred()) 68 Eventually(lbuff, 1).Should(gbytes.Say("Starting Broker Leafnode support with 1 remote")) 69 Eventually(lbuff, 1).Should(gbytes.Say("Leafnode connection created for account: choria")) 70 71 // create a choria client against the leaf 72 cfg, err := config.NewConfig("testdata/leaf_client.conf") 73 Expect(err).ToNot(HaveOccurred()) 74 cfg.CustomLogger = llog 75 cfg.OverrideCertname = "rip.mcollective" 76 lfw, err := choria.NewWithConfig(cfg) 77 Expect(err).ToNot(HaveOccurred()) 78 79 // discover the server running in the core 80 res, err := broadcast.New(lfw).Discover(ctx) 81 Expect(err).ToNot(HaveOccurred()) 82 Expect(res).To(Equal([]string{"localhost"})) 83 }) 84 }) 85 })