From 1a55ba4fbfa307e6d2f3269013b621bc71def225 Mon Sep 17 00:00:00 2001 From: Dominik Korittki <23359034+dkorittki@users.noreply.github.com> Date: Wed, 22 Apr 2026 17:25:50 +0200 Subject: [PATCH 01/10] chore: add router-tests for testing tls on nats --- router-tests/events/nats_tls_test.go | 376 +++++++++++++++++++++++++++ router-tests/go.mod | 27 +- router-tests/go.sum | 55 ++-- 3 files changed, 425 insertions(+), 33 deletions(-) create mode 100644 router-tests/events/nats_tls_test.go diff --git a/router-tests/events/nats_tls_test.go b/router-tests/events/nats_tls_test.go new file mode 100644 index 0000000000..d1b7a85419 --- /dev/null +++ b/router-tests/events/nats_tls_test.go @@ -0,0 +1,376 @@ +package events_test + +import ( + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/tls" + "crypto/x509" + "crypto/x509/pkix" + "encoding/pem" + "math/big" + "net" + "os" + "strings" + "testing" + "time" + + graphql "github.com/hasura/go-graphql-client" + natssrv "github.com/nats-io/nats-server/v2/server" + "github.com/nats-io/nats.go" + "github.com/stretchr/testify/require" + "github.com/wundergraph/cosmo/router-tests/testenv" + "github.com/wundergraph/cosmo/router/pkg/config" +) + +// natsTLSTestCerts holds file paths to TLS certificate files used in nats_tls_test.go. +type natsTLSTestCerts struct { + CACertFile string // self-signed CA certificate (PEM) + ServerCertFile string // server certificate signed by the CA (PEM, SAN: 127.0.0.1/localhost) + ServerKeyFile string // server private key (PEM) + ClientCertFile string // client certificate signed by the CA, for mTLS (PEM) + ClientKeyFile string // client private key, for mTLS (PEM) +} + +// generateNATSTLSTestCerts creates a CA, a server cert (with SAN 127.0.0.1 and localhost), and a +// client cert. All PEM files are written to the test's temp directory and cleaned up automatically. +func generateNATSTLSTestCerts(t *testing.T) *natsTLSTestCerts { + t.Helper() + + // CA key + self-signed cert + caKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + require.NoError(t, err) + caTemplate := &x509.Certificate{ + SerialNumber: big.NewInt(1), + Subject: pkix.Name{CommonName: "nats-test-ca"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(24 * time.Hour), + IsCA: true, + BasicConstraintsValid: true, + KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign, + } + caDER, err := x509.CreateCertificate(rand.Reader, caTemplate, caTemplate, &caKey.PublicKey, caKey) + require.NoError(t, err) + caCert, err := x509.ParseCertificate(caDER) + require.NoError(t, err) + caPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: caDER}) + + // Server key + cert signed by the CA (SAN required for hostname verification) + serverKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + require.NoError(t, err) + serverTemplate := &x509.Certificate{ + SerialNumber: big.NewInt(2), + Subject: pkix.Name{CommonName: "localhost"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(24 * time.Hour), + IPAddresses: []net.IP{net.ParseIP("127.0.0.1")}, + DNSNames: []string{"localhost"}, + KeyUsage: x509.KeyUsageDigitalSignature, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, + } + serverDER, err := x509.CreateCertificate(rand.Reader, serverTemplate, caCert, &serverKey.PublicKey, caKey) + require.NoError(t, err) + serverCertPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: serverDER}) + serverKeyDER, err := x509.MarshalECPrivateKey(serverKey) + require.NoError(t, err) + serverKeyPEM := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: serverKeyDER}) + + // Client key + cert signed by the CA (used for mTLS) + clientKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + require.NoError(t, err) + clientTemplate := &x509.Certificate{ + SerialNumber: big.NewInt(3), + Subject: pkix.Name{CommonName: "nats-test-client"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(24 * time.Hour), + KeyUsage: x509.KeyUsageDigitalSignature, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth}, + } + clientDER, err := x509.CreateCertificate(rand.Reader, clientTemplate, caCert, &clientKey.PublicKey, caKey) + require.NoError(t, err) + clientCertPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: clientDER}) + clientKeyDER, err := x509.MarshalECPrivateKey(clientKey) + require.NoError(t, err) + clientKeyPEM := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: clientKeyDER}) + + return &natsTLSTestCerts{ + CACertFile: writeNATSPEMFile(t, caPEM), + ServerCertFile: writeNATSPEMFile(t, serverCertPEM), + ServerKeyFile: writeNATSPEMFile(t, serverKeyPEM), + ClientCertFile: writeNATSPEMFile(t, clientCertPEM), + ClientKeyFile: writeNATSPEMFile(t, clientKeyPEM), + } +} + +func writeNATSPEMFile(t *testing.T, data []byte) string { + t.Helper() + f, err := os.CreateTemp(t.TempDir(), "nats-tls-*.pem") + require.NoError(t, err) + _, err = f.Write(data) + require.NoError(t, err) + require.NoError(t, f.Close()) + return f.Name() +} + +// buildServerTLSConfig returns a *tls.Config for the embedded NATS server using the given cert/key files. +func buildServerTLSConfig(t *testing.T, certFile, keyFile string) *tls.Config { + t.Helper() + cert, err := tls.LoadX509KeyPair(certFile, keyFile) + require.NoError(t, err) + return &tls.Config{ + Certificates: []tls.Certificate{cert}, + MinVersion: tls.VersionTLS12, + } +} + +// buildMTLSServerConfig returns a *tls.Config that requires and verifies client certificates. +func buildMTLSServerConfig(t *testing.T, certFile, keyFile, caFile string) *tls.Config { + t.Helper() + cfg := buildServerTLSConfig(t, certFile, keyFile) + caPEM, err := os.ReadFile(caFile) + require.NoError(t, err) + caPool := x509.NewCertPool() + require.True(t, caPool.AppendCertsFromPEM(caPEM), "failed to parse CA certificate") + cfg.ClientAuth = tls.RequireAndVerifyClientCert + cfg.ClientCAs = caPool + return cfg +} + +// startTLSNATSServer starts an embedded NATS server with the given options. +// It is automatically shut down when the test completes. +func startTLSNATSServer(t *testing.T, opts *natssrv.Options) *natssrv.Server { + t.Helper() + s, err := natssrv.NewServer(opts) + require.NoError(t, err, "failed to create embedded NATS server") + s.Start() + require.True(t, s.ReadyForConnections(10*time.Second), "embedded NATS server did not become ready") + t.Cleanup(func() { + s.Shutdown() + s.WaitForShutdown() + }) + return s +} + +// natsPlainURL returns a nats:// URL for the server regardless of its TLS scheme. +// Use this when TLS is enabled via explicit nats.Option / router TLS config rather than URL scheme. +func natsPlainURL(s *natssrv.Server) string { + return strings.Replace(s.ClientURL(), "tls://", "nats://", 1) +} + +// connectInsecureTLSNATSClient connects a NATS test-helper client to the given URL using +// InsecureSkipVerify TLS. Extra options are applied after the defaults, allowing the caller +// to override the TLS config (e.g., to add a client certificate for mTLS). +func connectInsecureTLSNATSClient(t *testing.T, serverURL string, extraOpts ...nats.Option) *nats.Conn { + t.Helper() + opts := []nats.Option{ + nats.Secure(&tls.Config{InsecureSkipVerify: true}), //nolint:gosec // test helper only + nats.MaxReconnects(3), + nats.Timeout(10 * time.Second), + nats.ErrorHandler(func(_ *nats.Conn, _ *nats.Subscription, err error) { + t.Logf("NATS test client error: %v", err) + }), + } + // extraOpts come last so they can override defaults (e.g., supply a richer TLS config). + opts = append(opts, extraOpts...) + conn, err := nats.Connect(serverURL, opts...) + require.NoError(t, err, "failed to connect NATS test client to %s", serverURL) + t.Cleanup(conn.Close) + return conn +} + +// tlsNATSEventSources builds event sources for every demo NATS provider, all pointing at url +// with the given TLS config. This replaces the empty provider list that results from not using +// EnableNats: true. +func tlsNATSEventSources(url string, tlsCfg *config.NatsTLSConfiguration) []config.NatsEventSource { + sources := make([]config.NatsEventSource, len(testenv.DemoNatsProviders)) + for i, id := range testenv.DemoNatsProviders { + sources[i] = config.NatsEventSource{ID: id, URL: url, TLS: tlsCfg} + } + return sources +} + +// TestNATSTLSEvents verifies that the router connects to NATS correctly under various TLS scenarios. +// Each sub-test spins up an embedded NATS server and drives a full subscribe → publish → receive cycle. +func TestNATSTLSEvents(t *testing.T) { + t.Parallel() + + // subscribePublishVerify is the common test body: it subscribes to employeeUpdated(employeeID:3), + // publishes one event via natsConn, and asserts the subscription response. + subscribePublishVerify := func(t *testing.T, xEnv *testenv.Environment, natsConn *nats.Conn) { + t.Helper() + + var sub struct { + EmployeeUpdated struct { + ID float64 `graphql:"id"` + Details struct { + Forename string `graphql:"forename"` + Surname string `graphql:"surname"` + } `graphql:"details"` + } `graphql:"employeeUpdated(employeeID: 3)"` + } + + surl := xEnv.GraphQLWebSocketSubscriptionURL() + client := graphql.NewSubscriptionClient(surl) + + resultCh := make(chan natsSubscriptionArgs, 1) + subscriptionID, err := client.Subscribe(&sub, nil, func(dataValue []byte, errValue error) error { + resultCh <- natsSubscriptionArgs{dataValue: dataValue, errValue: errValue} + return nil + }) + require.NoError(t, err) + require.NotEmpty(t, subscriptionID) + + clientErrCh := make(chan error, 1) + go func() { clientErrCh <- client.Run() }() + + xEnv.WaitForSubscriptionCount(1, EventWaitTimeout) + xEnv.WaitForTriggerCount(1, EventWaitTimeout) + + subject := xEnv.GetPubSubName("employeeUpdated.3") + payload := []byte(`{"id":3,"__typename":"Employee"}`) + xEnv.NATSPublishUntilReceived(natsConn, subject, payload, 1, EventWaitTimeout) + + testenv.AwaitChannelWithT(t, EventWaitTimeout, resultCh, func(t *testing.T, args natsSubscriptionArgs) { + require.NoError(t, args.errValue) + require.JSONEq(t, + `{"employeeUpdated":{"id":3,"details":{"forename":"Stefan","surname":"Avram"}}}`, + string(args.dataValue), + ) + }) + + require.NoError(t, client.Close()) + testenv.AwaitChannelWithT(t, EventWaitTimeout, clientErrCh, func(t *testing.T, err error) { + require.NoError(t, err) + }) + } + + // Test 1: server requires TLS; router connects using InsecureSkipCaVerification. + t.Run("router connects when server requires TLS", func(t *testing.T) { + t.Parallel() + + certs := generateNATSTLSTestCerts(t) + srv := startTLSNATSServer(t, &natssrv.Options{ + Host: "127.0.0.1", + Port: -1, + TLS: true, + TLSConfig: buildServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), + }) + + serverURL := natsPlainURL(srv) + natsConn := connectInsecureTLSNATSClient(t, serverURL) + routerTLS := &config.NatsTLSConfiguration{InsecureSkipCaVerification: true} + + testenv.Run(t, &testenv.Config{ + RouterConfigJSONTemplate: testenv.ConfigWithEdfsNatsJSONTemplate, + ModifyEventsConfiguration: func(cfg *config.EventsConfiguration) { + cfg.Providers.Nats = tlsNATSEventSources(serverURL, routerTLS) + }, + }, func(t *testing.T, xEnv *testenv.Environment) { + subscribePublishVerify(t, xEnv, natsConn) + }) + }) + + // Test 2: router supplies a custom CA certificate to verify the server certificate. + t.Run("router uses custom CA certificate", func(t *testing.T) { + t.Parallel() + + certs := generateNATSTLSTestCerts(t) + srv := startTLSNATSServer(t, &natssrv.Options{ + Host: "127.0.0.1", + Port: -1, + TLS: true, + TLSConfig: buildServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), + }) + + serverURL := natsPlainURL(srv) + natsConn := connectInsecureTLSNATSClient(t, serverURL) + // Router verifies the server certificate against the custom CA — no InsecureSkipVerify. + routerTLS := &config.NatsTLSConfiguration{CaFile: certs.CACertFile} + + testenv.Run(t, &testenv.Config{ + RouterConfigJSONTemplate: testenv.ConfigWithEdfsNatsJSONTemplate, + ModifyEventsConfiguration: func(cfg *config.EventsConfiguration) { + cfg.Providers.Nats = tlsNATSEventSources(serverURL, routerTLS) + }, + }, func(t *testing.T, xEnv *testenv.Environment) { + subscribePublishVerify(t, xEnv, natsConn) + }) + }) + + // Test 3: server requires mutual TLS; router presents a client certificate. + t.Run("router uses mTLS when configured", func(t *testing.T) { + t.Parallel() + + certs := generateNATSTLSTestCerts(t) + // Server requires client certs verified against the CA. + srv := startTLSNATSServer(t, &natssrv.Options{ + Host: "127.0.0.1", + Port: -1, + TLS: true, + TLSVerify: true, + TLSConfig: buildMTLSServerConfig(t, certs.ServerCertFile, certs.ServerKeyFile, certs.CACertFile), + }) + + serverURL := natsPlainURL(srv) + + // Test client also needs a client cert to connect to the mTLS server. + clientCert, err := tls.LoadX509KeyPair(certs.ClientCertFile, certs.ClientKeyFile) + require.NoError(t, err) + // The extra nats.Secure call overrides the default InsecureSkipVerify-only config and + // adds the client certificate while keeping InsecureSkipVerify for server cert validation. + natsConn := connectInsecureTLSNATSClient(t, serverURL, + nats.Secure(&tls.Config{ //nolint:gosec // test helper only + InsecureSkipVerify: true, + Certificates: []tls.Certificate{clientCert}, + }), + ) + + // Router uses the CA cert to verify the server and presents the client cert/key for mTLS. + routerTLS := &config.NatsTLSConfiguration{ + CaFile: certs.CACertFile, + CertFile: certs.ClientCertFile, + KeyFile: certs.ClientKeyFile, + } + + testenv.Run(t, &testenv.Config{ + RouterConfigJSONTemplate: testenv.ConfigWithEdfsNatsJSONTemplate, + ModifyEventsConfiguration: func(cfg *config.EventsConfiguration) { + cfg.Providers.Nats = tlsNATSEventSources(serverURL, routerTLS) + }, + }, func(t *testing.T, xEnv *testenv.Environment) { + subscribePublishVerify(t, xEnv, natsConn) + }) + }) + + // Test 4: router URL uses the "tls://" scheme, which signals the NATS client to use TLS. + t.Run("router uses TLS when URL scheme is tls://", func(t *testing.T) { + t.Parallel() + + certs := generateNATSTLSTestCerts(t) + srv := startTLSNATSServer(t, &natssrv.Options{ + Host: "127.0.0.1", + Port: -1, + TLS: true, + TLSConfig: buildServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), + }) + + // Use the tls:// URL from the server directly — this is what gets configured in the router. + tlsSchemeURL := srv.ClientURL() + + // Test client uses nats:// + explicit Secure option to connect to the same server. + natsConn := connectInsecureTLSNATSClient(t, natsPlainURL(srv)) + + // Router uses the tls:// URL scheme; InsecureSkipCaVerification is required because the + // embedded server uses a self-signed cert not in the system trust store. + routerTLS := &config.NatsTLSConfiguration{InsecureSkipCaVerification: true} + + testenv.Run(t, &testenv.Config{ + RouterConfigJSONTemplate: testenv.ConfigWithEdfsNatsJSONTemplate, + ModifyEventsConfiguration: func(cfg *config.EventsConfiguration) { + cfg.Providers.Nats = tlsNATSEventSources(tlsSchemeURL, routerTLS) + }, + }, func(t *testing.T, xEnv *testenv.Environment) { + subscribePublishVerify(t, xEnv, natsConn) + }) + }) +} diff --git a/router-tests/go.mod b/router-tests/go.mod index 8b6cf45645..e4f714e1e3 100644 --- a/router-tests/go.mod +++ b/router-tests/go.mod @@ -16,7 +16,8 @@ require ( github.com/hasura/go-graphql-client v0.14.3 github.com/mark3labs/mcp-go v0.43.2 github.com/modelcontextprotocol/go-sdk v1.4.1 - github.com/nats-io/nats.go v1.35.0 + github.com/nats-io/nats-server/v2 v2.12.7 + github.com/nats-io/nats.go v1.50.0 github.com/prometheus/client_golang v1.19.1 github.com/prometheus/client_model v0.6.1 github.com/redis/go-redis/v9 v9.7.3 @@ -37,8 +38,8 @@ require ( go.uber.org/atomic v1.11.0 go.uber.org/goleak v1.3.0 go.uber.org/zap v1.27.0 - golang.org/x/net v0.49.0 - golang.org/x/sys v0.40.0 + golang.org/x/net v0.51.0 + golang.org/x/sys v0.42.0 google.golang.org/grpc v1.79.3 google.golang.org/protobuf v1.36.10 gopkg.in/yaml.v3 v3.0.1 @@ -51,6 +52,7 @@ require ( github.com/MicahParks/keyfunc/v3 v3.6.2 // indirect github.com/agnivade/levenshtein v1.2.1 // indirect github.com/andybalholm/brotli v1.1.0 // indirect + github.com/antithesishq/antithesis-sdk-go v0.6.0-default-no-op // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/benbjohnson/clock v1.3.0 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -90,6 +92,7 @@ require ( github.com/goccy/go-yaml v1.17.1 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/golang/protobuf v1.5.4 // indirect + github.com/google/go-tpm v0.9.8 // indirect github.com/google/jsonschema-go v0.4.2 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect @@ -103,19 +106,21 @@ require ( github.com/jensneuse/abstractlogger v0.0.4 // indirect github.com/jensneuse/byte-template v0.0.0-20231025215717-69252eb3ed56 // indirect github.com/kingledion/go-tools v0.6.0 // indirect - github.com/klauspost/compress v1.18.0 // indirect + github.com/klauspost/compress v1.18.5 // indirect github.com/klauspost/cpuid/v2 v2.2.8 // indirect github.com/logrusorgru/aurora/v4 v4.0.0 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect + github.com/minio/highwayhash v1.0.4-0.20251030100505-070ab1a87a76 // indirect github.com/minio/md5-simd v1.1.2 // indirect github.com/minio/minio-go/v7 v7.0.74 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/nats-io/nkeys v0.4.7 // indirect + github.com/nats-io/jwt/v2 v2.8.1 // indirect + github.com/nats-io/nkeys v0.4.15 // indirect github.com/nats-io/nuid v1.0.1 // indirect github.com/oklog/run v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect @@ -175,14 +180,14 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.uber.org/ratelimit v0.3.1 // indirect go.withmatt.com/connect-brotli v0.4.0 // indirect - golang.org/x/crypto v0.47.0 // indirect + golang.org/x/crypto v0.49.0 // indirect golang.org/x/exp v0.0.0-20250813145105-42675adae3e6 // indirect - golang.org/x/mod v0.32.0 // indirect + golang.org/x/mod v0.33.0 // indirect golang.org/x/oauth2 v0.34.0 // indirect - golang.org/x/sync v0.19.0 // indirect - golang.org/x/text v0.33.0 // indirect - golang.org/x/time v0.9.0 // indirect - golang.org/x/tools v0.41.0 // indirect + golang.org/x/sync v0.20.0 // indirect + golang.org/x/text v0.35.0 // indirect + golang.org/x/time v0.15.0 // indirect + golang.org/x/tools v0.42.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect diff --git a/router-tests/go.sum b/router-tests/go.sum index a54b295867..e46fc330ce 100644 --- a/router-tests/go.sum +++ b/router-tests/go.sum @@ -25,6 +25,8 @@ github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1 github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= +github.com/antithesishq/antithesis-sdk-go v0.6.0-default-no-op h1:kpBdlEPbRvff0mDD1gk7o9BhI16b9p5yYAXRlidpqJE= +github.com/antithesishq/antithesis-sdk-go v0.6.0-default-no-op/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl3v2yvUZjmKncl7U91fup7E= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= @@ -139,6 +141,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/go-containerregistry v0.20.3 h1:oNx7IdTI936V8CQRveCjaxOiegWwvM7kqkbXTpyiovI= github.com/google/go-containerregistry v0.20.3/go.mod h1:w00pIgBRDVUDFM6bq+Qx8lwNWK+cxgCuX1vd3PIBDNI= +github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo= +github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY= github.com/google/jsonschema-go v0.4.2 h1:tmrUohrwoLZZS/P3x7ex0WAVknEkBZM46iALbcqoRA8= github.com/google/jsonschema-go v0.4.2/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= @@ -187,8 +191,8 @@ github.com/jsimonetti/rtnetlink/v2 v2.0.1/go.mod h1:7MoNYNbb3UaDHtF8udiJo/RH6VsT github.com/kingledion/go-tools v0.6.0 h1:y8C/4mWoHgLkO45dB+Y/j0o4Y4WUB5lDTAcMPMtFpTg= github.com/kingledion/go-tools v0.6.0/go.mod h1:qcDJQxBui/H/hterGb90GMlLs9Yi7QrwaJL8OGdbsms= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= -github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= +github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE= +github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= @@ -222,6 +226,8 @@ github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/ github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw= github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U= github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA= +github.com/minio/highwayhash v1.0.4-0.20251030100505-070ab1a87a76 h1:KGuD/pM2JpL9FAYvBrnBBeENKZNh6eNtjqytV6TYjnk= +github.com/minio/highwayhash v1.0.4-0.20251030100505-070ab1a87a76/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= github.com/minio/minio-go/v7 v7.0.74 h1:fTo/XlPBTSpo3BAMshlwKL5RspXRv9us5UeHEGYCFe0= @@ -234,10 +240,14 @@ github.com/modelcontextprotocol/go-sdk v1.4.1 h1:M4x9GyIPj+HoIlHNGpK2hq5o3BFhC+7 github.com/modelcontextprotocol/go-sdk v1.4.1/go.mod h1:Bo/mS87hPQqHSRkMv4dQq1XCu6zv4INdXnFZabkNU6s= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/nats-io/nats.go v1.35.0 h1:XFNqNM7v5B+MQMKqVGAyHwYhyKb48jrenXNxIU20ULk= -github.com/nats-io/nats.go v1.35.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= -github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= -github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= +github.com/nats-io/jwt/v2 v2.8.1 h1:V0xpGuD/N8Mi+fQNDynXohVvp7ZztevW5io8CUWlPmU= +github.com/nats-io/jwt/v2 v2.8.1/go.mod h1:nWnOEEiVMiKHQpnAy4eXlizVEtSfzacZ1Q43LIRavZg= +github.com/nats-io/nats-server/v2 v2.12.7 h1:prQ9cPiWHcnwfT81Wi5lU9LL8TLY+7pxDru6fQYLCQQ= +github.com/nats-io/nats-server/v2 v2.12.7/go.mod h1:dOnmkprKMluTmTF7/QHZioxlau3sKHUM/LBPy9AiBPw= +github.com/nats-io/nats.go v1.50.0 h1:5zAeQrTvyrKrWLJ0fu02W3br8ym57qf7csDzgLOpcds= +github.com/nats-io/nats.go v1.50.0/go.mod h1:26HypzazeOkyO3/mqd1zZd53STJN0EjCYF9Uy2ZOBno= +github.com/nats-io/nkeys v0.4.15 h1:JACV5jRVO9V856KOapQ7x+EY8Jo3qw1vJt/9Jpwzkk4= +github.com/nats-io/nkeys v0.4.15/go.mod h1:CpMchTXC9fxA5zrMo4KpySxNjiDVvr8ANOSZdiNfUrs= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= @@ -425,25 +435,25 @@ go.withmatt.com/connect-brotli v0.4.0 h1:7ObWkYmEbUXK3EKglD0Lgj0BBnnD3jNdAxeDRct go.withmatt.com/connect-brotli v0.4.0/go.mod h1:c2eELz56za+/Mxh1yJrlglZ4VM9krpOCPqS2Vxf8NVk= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8= -golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A= +golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4= +golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA= golang.org/x/exp v0.0.0-20250813145105-42675adae3e6 h1:SbTAbRFnd5kjQXbczszQ0hdk3ctwYf3qBNH9jIsGclE= golang.org/x/exp v0.0.0-20250813145105-42675adae3e6/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c= -golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU= +golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8= +golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= -golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= +golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo= +golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y= golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw= golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= -golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= +golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -460,19 +470,20 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= -golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= +golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= -golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= -golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY= -golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= +golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA= +golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= +golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc= -golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg= +golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k= +golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= From 011df23e670f27ebc5fb304a2f1fafc341535d0e Mon Sep 17 00:00:00 2001 From: Dominik Korittki <23359034+dkorittki@users.noreply.github.com> Date: Wed, 22 Apr 2026 17:36:56 +0200 Subject: [PATCH 02/10] chore: add inline comments --- router-tests/events/nats_tls_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/router-tests/events/nats_tls_test.go b/router-tests/events/nats_tls_test.go index d1b7a85419..369da2bbf9 100644 --- a/router-tests/events/nats_tls_test.go +++ b/router-tests/events/nats_tls_test.go @@ -251,7 +251,7 @@ func TestNATSTLSEvents(t *testing.T) { certs := generateNATSTLSTestCerts(t) srv := startTLSNATSServer(t, &natssrv.Options{ Host: "127.0.0.1", - Port: -1, + Port: -1, // tells nats to use a free port TLS: true, TLSConfig: buildServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), }) @@ -277,7 +277,7 @@ func TestNATSTLSEvents(t *testing.T) { certs := generateNATSTLSTestCerts(t) srv := startTLSNATSServer(t, &natssrv.Options{ Host: "127.0.0.1", - Port: -1, + Port: -1, // tells nats to use a free port TLS: true, TLSConfig: buildServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), }) @@ -305,7 +305,7 @@ func TestNATSTLSEvents(t *testing.T) { // Server requires client certs verified against the CA. srv := startTLSNATSServer(t, &natssrv.Options{ Host: "127.0.0.1", - Port: -1, + Port: -1, // tells nats to use a free port TLS: true, TLSVerify: true, TLSConfig: buildMTLSServerConfig(t, certs.ServerCertFile, certs.ServerKeyFile, certs.CACertFile), @@ -349,7 +349,7 @@ func TestNATSTLSEvents(t *testing.T) { certs := generateNATSTLSTestCerts(t) srv := startTLSNATSServer(t, &natssrv.Options{ Host: "127.0.0.1", - Port: -1, + Port: -1, // tells nats to use a free port TLS: true, TLSConfig: buildServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), }) From 5f3bbad883161df40cc805357a85ac6a6cc0fb20 Mon Sep 17 00:00:00 2001 From: Dominik Korittki <23359034+dkorittki@users.noreply.github.com> Date: Thu, 23 Apr 2026 10:39:47 +0200 Subject: [PATCH 03/10] chore: update routers nats client to v1.50.0 To have version parity between router-tests and router. And because it doesn't hurt to update deps once in a while. It's declared as a non-breaking change. --- router/go.mod | 16 ++++++++-------- router/go.sum | 36 ++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/router/go.mod b/router/go.mod index 1b107c9753..c91673fa51 100644 --- a/router/go.mod +++ b/router/go.mod @@ -20,7 +20,7 @@ require ( github.com/jensneuse/abstractlogger v0.0.4 github.com/joho/godotenv v1.5.1 github.com/mitchellh/mapstructure v1.5.0 - github.com/nats-io/nats.go v1.35.0 + github.com/nats-io/nats.go v1.50.0 github.com/nats-io/nuid v1.0.1 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.19.1 @@ -50,8 +50,8 @@ require ( go.uber.org/automaxprocs v1.5.3 go.uber.org/zap v1.27.0 go.withmatt.com/connect-brotli v0.4.0 - golang.org/x/sync v0.19.0 - golang.org/x/sys v0.40.0 // indirect + golang.org/x/sync v0.20.0 + golang.org/x/sys v0.42.0 // indirect google.golang.org/grpc v1.79.3 google.golang.org/protobuf v1.36.10 ) @@ -74,7 +74,7 @@ require ( github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-plugin v1.6.3 github.com/iancoleman/strcase v0.3.0 - github.com/klauspost/compress v1.18.0 + github.com/klauspost/compress v1.18.5 github.com/minio/minio-go/v7 v7.0.74 github.com/modelcontextprotocol/go-sdk v1.4.1 github.com/posthog/posthog-go v1.5.5 @@ -86,8 +86,8 @@ require ( go.uber.org/goleak v1.3.0 go.uber.org/ratelimit v0.3.1 golang.org/x/exp v0.0.0-20250813145105-42675adae3e6 - golang.org/x/net v0.48.0 - golang.org/x/text v0.32.0 + golang.org/x/net v0.51.0 + golang.org/x/text v0.35.0 golang.org/x/time v0.9.0 ) @@ -134,7 +134,7 @@ require ( github.com/minio/md5-simd v1.1.2 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/nats-io/nkeys v0.4.7 // indirect + github.com/nats-io/nkeys v0.4.15 // indirect github.com/oklog/run v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.1.1 // indirect @@ -167,7 +167,7 @@ require ( go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.33.0 // indirect go.opentelemetry.io/proto/otlp v1.4.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.46.0 // indirect + golang.org/x/crypto v0.49.0 // indirect golang.org/x/oauth2 v0.34.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect diff --git a/router/go.sum b/router/go.sum index f3e013294a..597a8a381a 100644 --- a/router/go.sum +++ b/router/go.sum @@ -168,8 +168,8 @@ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwA github.com/kingledion/go-tools v0.6.0 h1:y8C/4mWoHgLkO45dB+Y/j0o4Y4WUB5lDTAcMPMtFpTg= github.com/kingledion/go-tools v0.6.0/go.mod h1:qcDJQxBui/H/hterGb90GMlLs9Yi7QrwaJL8OGdbsms= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= -github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= +github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE= +github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= @@ -205,10 +205,10 @@ github.com/modelcontextprotocol/go-sdk v1.4.1 h1:M4x9GyIPj+HoIlHNGpK2hq5o3BFhC+7 github.com/modelcontextprotocol/go-sdk v1.4.1/go.mod h1:Bo/mS87hPQqHSRkMv4dQq1XCu6zv4INdXnFZabkNU6s= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/nats-io/nats.go v1.35.0 h1:XFNqNM7v5B+MQMKqVGAyHwYhyKb48jrenXNxIU20ULk= -github.com/nats-io/nats.go v1.35.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= -github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= -github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= +github.com/nats-io/nats.go v1.50.0 h1:5zAeQrTvyrKrWLJ0fu02W3br8ym57qf7csDzgLOpcds= +github.com/nats-io/nats.go v1.50.0/go.mod h1:26HypzazeOkyO3/mqd1zZd53STJN0EjCYF9Uy2ZOBno= +github.com/nats-io/nkeys v0.4.15 h1:JACV5jRVO9V856KOapQ7x+EY8Jo3qw1vJt/9Jpwzkk4= +github.com/nats-io/nkeys v0.4.15/go.mod h1:CpMchTXC9fxA5zrMo4KpySxNjiDVvr8ANOSZdiNfUrs= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= @@ -385,8 +385,8 @@ go.withmatt.com/connect-brotli v0.4.0 h1:7ObWkYmEbUXK3EKglD0Lgj0BBnnD3jNdAxeDRct go.withmatt.com/connect-brotli v0.4.0/go.mod h1:c2eELz56za+/Mxh1yJrlglZ4VM9krpOCPqS2Vxf8NVk= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU= -golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0= +golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4= +golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA= golang.org/x/exp v0.0.0-20250813145105-42675adae3e6 h1:SbTAbRFnd5kjQXbczszQ0hdk3ctwYf3qBNH9jIsGclE= golang.org/x/exp v0.0.0-20250813145105-42675adae3e6/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -395,13 +395,13 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU= -golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY= +golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo= +golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y= golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw= golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= -golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= +golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -418,19 +418,19 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= -golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= +golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU= -golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY= +golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= +golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA= golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY= golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc= -golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg= +golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k= +golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= From 5f531cc5be76688d5527a1c1981c33d05fcc7610 Mon Sep 17 00:00:00 2001 From: Dominik Korittki <23359034+dkorittki@users.noreply.github.com> Date: Fri, 24 Apr 2026 11:19:16 +0200 Subject: [PATCH 04/10] fix: add cleanup + improve tls url scheme test --- router-tests/events/nats_tls_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/router-tests/events/nats_tls_test.go b/router-tests/events/nats_tls_test.go index 369da2bbf9..8d948b0152 100644 --- a/router-tests/events/nats_tls_test.go +++ b/router-tests/events/nats_tls_test.go @@ -222,6 +222,7 @@ func TestNATSTLSEvents(t *testing.T) { clientErrCh := make(chan error, 1) go func() { clientErrCh <- client.Run() }() + t.Cleanup(func() { _ = client.Close() }) xEnv.WaitForSubscriptionCount(1, EventWaitTimeout) xEnv.WaitForTriggerCount(1, EventWaitTimeout) @@ -360,9 +361,9 @@ func TestNATSTLSEvents(t *testing.T) { // Test client uses nats:// + explicit Secure option to connect to the same server. natsConn := connectInsecureTLSNATSClient(t, natsPlainURL(srv)) - // Router uses the tls:// URL scheme; InsecureSkipCaVerification is required because the - // embedded server uses a self-signed cert not in the system trust store. - routerTLS := &config.NatsTLSConfiguration{InsecureSkipCaVerification: true} + // Router verifies the server certificate against the custom CA. No InsecureSkipVerify is + // needed here — the tls:// scheme enables TLS, and the CA file authenticates the server cert. + routerTLS := &config.NatsTLSConfiguration{CaFile: certs.CACertFile} testenv.Run(t, &testenv.Config{ RouterConfigJSONTemplate: testenv.ConfigWithEdfsNatsJSONTemplate, From b39c03d0af360058f006aab93a261b953308f77e Mon Sep 17 00:00:00 2001 From: Dominik Korittki <23359034+dkorittki@users.noreply.github.com> Date: Fri, 24 Apr 2026 13:28:12 +0200 Subject: [PATCH 05/10] chore: refactor tests --- router-tests/events/helpers_test.go | 106 ++++++++++++ router-tests/events/nats_tls_test.go | 239 +++++++++------------------ 2 files changed, 182 insertions(+), 163 deletions(-) diff --git a/router-tests/events/helpers_test.go b/router-tests/events/helpers_test.go index 03e10c3d34..24510abae1 100644 --- a/router-tests/events/helpers_test.go +++ b/router-tests/events/helpers_test.go @@ -2,10 +2,20 @@ package events_test import ( "bufio" + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "crypto/x509" + "crypto/x509/pkix" + "encoding/pem" + "math/big" + "net" + "os" "testing" "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/wundergraph/cosmo/router-tests/testenv" ) @@ -38,3 +48,99 @@ func assertMultipartValueEventually(t *testing.T, reader *bufio.Reader, expected return true }, EventWaitTimeout, time.Millisecond*100) } + +// tlsCerts holds file paths to TLS certificate files used in tests. +type tlsCerts struct { + CACertFile string // self-signed CA certificate (PEM) + ServerCertFile string // server certificate signed by the CA (PEM, SAN: 127.0.0.1/localhost) + ServerKeyFile string // server private key (PEM) + ClientCertFile string // client certificate signed by the CA, for mTLS (PEM) + ClientKeyFile string // client private key, for mTLS (PEM) +} + +// generateTLSCerts creates a CA, a server cert (with SAN 127.0.0.1 and localhost), and a +// client cert. All PEM files are written to the test's temp directory and cleaned up automatically. +func generateTLSCerts(t *testing.T) *tlsCerts { + t.Helper() + + // CA key + self-signed cert + caKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + require.NoError(t, err) + caTemplate := &x509.Certificate{ + SerialNumber: big.NewInt(1), + Subject: pkix.Name{CommonName: "events-test-ca"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(24 * time.Hour), + IsCA: true, + BasicConstraintsValid: true, + KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign, + } + caDER, err := x509.CreateCertificate(rand.Reader, caTemplate, caTemplate, &caKey.PublicKey, caKey) + require.NoError(t, err) + caCert, err := x509.ParseCertificate(caDER) + require.NoError(t, err) + caPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: caDER}) + + // Server key + cert signed by the CA (SAN required for hostname verification) + serverKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + require.NoError(t, err) + serverTemplate := &x509.Certificate{ + SerialNumber: big.NewInt(2), + Subject: pkix.Name{CommonName: "localhost"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(24 * time.Hour), + IPAddresses: []net.IP{net.ParseIP("127.0.0.1")}, + DNSNames: []string{"localhost"}, + KeyUsage: x509.KeyUsageDigitalSignature, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, + } + serverDER, err := x509.CreateCertificate(rand.Reader, serverTemplate, caCert, &serverKey.PublicKey, caKey) + require.NoError(t, err) + serverCertPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: serverDER}) + serverKeyDER, err := x509.MarshalECPrivateKey(serverKey) + require.NoError(t, err) + serverKeyPEM := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: serverKeyDER}) + + // Client key + cert signed by the CA (used for mTLS) + clientKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + require.NoError(t, err) + clientTemplate := &x509.Certificate{ + SerialNumber: big.NewInt(3), + Subject: pkix.Name{CommonName: "nats-test-client"}, + NotBefore: time.Now().Add(-time.Hour), + NotAfter: time.Now().Add(24 * time.Hour), + KeyUsage: x509.KeyUsageDigitalSignature, + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth}, + } + clientDER, err := x509.CreateCertificate(rand.Reader, clientTemplate, caCert, &clientKey.PublicKey, caKey) + require.NoError(t, err) + clientCertPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: clientDER}) + clientKeyDER, err := x509.MarshalECPrivateKey(clientKey) + require.NoError(t, err) + clientKeyPEM := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: clientKeyDER}) + + return &tlsCerts{ + CACertFile: writeTempFile(t, caPEM, certFilePattern), + ServerCertFile: writeTempFile(t, serverCertPEM, certFilePattern), + ServerKeyFile: writeTempFile(t, serverKeyPEM, certFilePattern), + ClientCertFile: writeTempFile(t, clientCertPEM, certFilePattern), + ClientKeyFile: writeTempFile(t, clientKeyPEM, certFilePattern), + } +} + +// writeTempFile writes data to the t's tempfile. +// It uses pattern to create the filename (see os.CreateTemp) and returns that name. +// It lets t fail in case of errors. +func writeTempFile(t *testing.T, data []byte, pattern string) string { + t.Helper() + + f, err := os.CreateTemp(t.TempDir(), pattern) + require.NoError(t, err) + defer func() { _ = f.Close() }() + + _, err = f.Write(data) + require.NoError(t, err) + require.NoError(t, f.Close()) + + return f.Name() +} diff --git a/router-tests/events/nats_tls_test.go b/router-tests/events/nats_tls_test.go index 8d948b0152..448ac5af8f 100644 --- a/router-tests/events/nats_tls_test.go +++ b/router-tests/events/nats_tls_test.go @@ -1,15 +1,8 @@ package events_test import ( - "crypto/ecdsa" - "crypto/elliptic" - "crypto/rand" "crypto/tls" "crypto/x509" - "crypto/x509/pkix" - "encoding/pem" - "math/big" - "net" "os" "strings" "testing" @@ -23,125 +16,46 @@ import ( "github.com/wundergraph/cosmo/router/pkg/config" ) -// natsTLSTestCerts holds file paths to TLS certificate files used in nats_tls_test.go. -type natsTLSTestCerts struct { - CACertFile string // self-signed CA certificate (PEM) - ServerCertFile string // server certificate signed by the CA (PEM, SAN: 127.0.0.1/localhost) - ServerKeyFile string // server private key (PEM) - ClientCertFile string // client certificate signed by the CA, for mTLS (PEM) - ClientKeyFile string // client private key, for mTLS (PEM) -} - -// generateNATSTLSTestCerts creates a CA, a server cert (with SAN 127.0.0.1 and localhost), and a -// client cert. All PEM files are written to the test's temp directory and cleaned up automatically. -func generateNATSTLSTestCerts(t *testing.T) *natsTLSTestCerts { - t.Helper() - - // CA key + self-signed cert - caKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - require.NoError(t, err) - caTemplate := &x509.Certificate{ - SerialNumber: big.NewInt(1), - Subject: pkix.Name{CommonName: "nats-test-ca"}, - NotBefore: time.Now().Add(-time.Hour), - NotAfter: time.Now().Add(24 * time.Hour), - IsCA: true, - BasicConstraintsValid: true, - KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign, - } - caDER, err := x509.CreateCertificate(rand.Reader, caTemplate, caTemplate, &caKey.PublicKey, caKey) - require.NoError(t, err) - caCert, err := x509.ParseCertificate(caDER) - require.NoError(t, err) - caPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: caDER}) - - // Server key + cert signed by the CA (SAN required for hostname verification) - serverKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - require.NoError(t, err) - serverTemplate := &x509.Certificate{ - SerialNumber: big.NewInt(2), - Subject: pkix.Name{CommonName: "localhost"}, - NotBefore: time.Now().Add(-time.Hour), - NotAfter: time.Now().Add(24 * time.Hour), - IPAddresses: []net.IP{net.ParseIP("127.0.0.1")}, - DNSNames: []string{"localhost"}, - KeyUsage: x509.KeyUsageDigitalSignature, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, - } - serverDER, err := x509.CreateCertificate(rand.Reader, serverTemplate, caCert, &serverKey.PublicKey, caKey) - require.NoError(t, err) - serverCertPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: serverDER}) - serverKeyDER, err := x509.MarshalECPrivateKey(serverKey) - require.NoError(t, err) - serverKeyPEM := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: serverKeyDER}) - - // Client key + cert signed by the CA (used for mTLS) - clientKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - require.NoError(t, err) - clientTemplate := &x509.Certificate{ - SerialNumber: big.NewInt(3), - Subject: pkix.Name{CommonName: "nats-test-client"}, - NotBefore: time.Now().Add(-time.Hour), - NotAfter: time.Now().Add(24 * time.Hour), - KeyUsage: x509.KeyUsageDigitalSignature, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth}, - } - clientDER, err := x509.CreateCertificate(rand.Reader, clientTemplate, caCert, &clientKey.PublicKey, caKey) - require.NoError(t, err) - clientCertPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: clientDER}) - clientKeyDER, err := x509.MarshalECPrivateKey(clientKey) - require.NoError(t, err) - clientKeyPEM := pem.EncodeToMemory(&pem.Block{Type: "EC PRIVATE KEY", Bytes: clientKeyDER}) - - return &natsTLSTestCerts{ - CACertFile: writeNATSPEMFile(t, caPEM), - ServerCertFile: writeNATSPEMFile(t, serverCertPEM), - ServerKeyFile: writeNATSPEMFile(t, serverKeyPEM), - ClientCertFile: writeNATSPEMFile(t, clientCertPEM), - ClientKeyFile: writeNATSPEMFile(t, clientKeyPEM), - } -} +const ( + certFilePattern = "nats-tls-*.pem" +) -func writeNATSPEMFile(t *testing.T, data []byte) string { +// createServerTLSConfig returns a *tls.Config for the embedded NATS server using the given cert/key files. +func createServerTLSConfig(t *testing.T, certFile, keyFile string) *tls.Config { t.Helper() - f, err := os.CreateTemp(t.TempDir(), "nats-tls-*.pem") - require.NoError(t, err) - _, err = f.Write(data) - require.NoError(t, err) - require.NoError(t, f.Close()) - return f.Name() -} -// buildServerTLSConfig returns a *tls.Config for the embedded NATS server using the given cert/key files. -func buildServerTLSConfig(t *testing.T, certFile, keyFile string) *tls.Config { - t.Helper() cert, err := tls.LoadX509KeyPair(certFile, keyFile) require.NoError(t, err) + return &tls.Config{ Certificates: []tls.Certificate{cert}, MinVersion: tls.VersionTLS12, } } -// buildMTLSServerConfig returns a *tls.Config that requires and verifies client certificates. -func buildMTLSServerConfig(t *testing.T, certFile, keyFile, caFile string) *tls.Config { +// createServerMTLSConfig returns a *tls.Config that requires and verifies client certificates using mTLS. +func createServerMTLSConfig(t *testing.T, certFile, keyFile, caFile string) *tls.Config { t.Helper() - cfg := buildServerTLSConfig(t, certFile, keyFile) + + cfg := createServerTLSConfig(t, certFile, keyFile) caPEM, err := os.ReadFile(caFile) require.NoError(t, err) caPool := x509.NewCertPool() require.True(t, caPool.AppendCertsFromPEM(caPEM), "failed to parse CA certificate") cfg.ClientAuth = tls.RequireAndVerifyClientCert cfg.ClientCAs = caPool + return cfg } -// startTLSNATSServer starts an embedded NATS server with the given options. +// startNATSServer starts and returns an embedded, in-process NATS server with the given options. // It is automatically shut down when the test completes. -func startTLSNATSServer(t *testing.T, opts *natssrv.Options) *natssrv.Server { +func startNATSServer(t *testing.T, opts *natssrv.Options) *natssrv.Server { t.Helper() + s, err := natssrv.NewServer(opts) require.NoError(t, err, "failed to create embedded NATS server") + s.Start() require.True(t, s.ReadyForConnections(10*time.Second), "embedded NATS server did not become ready") t.Cleanup(func() { @@ -157,10 +71,10 @@ func natsPlainURL(s *natssrv.Server) string { return strings.Replace(s.ClientURL(), "tls://", "nats://", 1) } -// connectInsecureTLSNATSClient connects a NATS test-helper client to the given URL using -// InsecureSkipVerify TLS. Extra options are applied after the defaults, allowing the caller -// to override the TLS config (e.g., to add a client certificate for mTLS). -func connectInsecureTLSNATSClient(t *testing.T, serverURL string, extraOpts ...nats.Option) *nats.Conn { +// connectToNATS creates a nats connection and connects to serverURL. +// By default, it skips server certificate verification. +// It allows to pass extraOpts, which override or extend defaults options. +func connectToNATS(t *testing.T, serverURL string, extraOpts ...nats.Option) *nats.Conn { t.Helper() opts := []nats.Option{ nats.Secure(&tls.Config{InsecureSkipVerify: true}), //nolint:gosec // test helper only @@ -170,18 +84,19 @@ func connectInsecureTLSNATSClient(t *testing.T, serverURL string, extraOpts ...n t.Logf("NATS test client error: %v", err) }), } - // extraOpts come last so they can override defaults (e.g., supply a richer TLS config). + opts = append(opts, extraOpts...) conn, err := nats.Connect(serverURL, opts...) require.NoError(t, err, "failed to connect NATS test client to %s", serverURL) t.Cleanup(conn.Close) + return conn } -// tlsNATSEventSources builds event sources for every demo NATS provider, all pointing at url +// tlsNATSEventSourceConfig builds event sources for every demo NATS provider, all pointing at url // with the given TLS config. This replaces the empty provider list that results from not using // EnableNats: true. -func tlsNATSEventSources(url string, tlsCfg *config.NatsTLSConfiguration) []config.NatsEventSource { +func tlsNATSEventSourceConfig(url string, tlsCfg *config.NatsTLSConfiguration) []config.NatsEventSource { sources := make([]config.NatsEventSource, len(testenv.DemoNatsProviders)) for i, id := range testenv.DemoNatsProviders { sources[i] = config.NatsEventSource{ID: id, URL: url, TLS: tlsCfg} @@ -189,17 +104,17 @@ func tlsNATSEventSources(url string, tlsCfg *config.NatsTLSConfiguration) []conf return sources } -// TestNATSTLSEvents verifies that the router connects to NATS correctly under various TLS scenarios. -// Each sub-test spins up an embedded NATS server and drives a full subscribe → publish → receive cycle. -func TestNATSTLSEvents(t *testing.T) { +// TestRouterConnectsToNATSWithTLS verifies that the router connects to NATS correctly under various TLS scenarios. +// Each subtest spins up an embedded NATS server and drives a full subscribe → publish → receive cycle. +func TestRouterConnectsToNATSWithTLS(t *testing.T) { t.Parallel() // subscribePublishVerify is the common test body: it subscribes to employeeUpdated(employeeID:3), - // publishes one event via natsConn, and asserts the subscription response. - subscribePublishVerify := func(t *testing.T, xEnv *testenv.Environment, natsConn *nats.Conn) { + // publishes one event via natsHelperConn, and asserts the subscription response. + subscribePublishVerify := func(t *testing.T, xEnv *testenv.Environment, natsHelperConn *nats.Conn) { t.Helper() - var sub struct { + var subscriptionQuery struct { EmployeeUpdated struct { ID float64 `graphql:"id"` Details struct { @@ -209,14 +124,15 @@ func TestNATSTLSEvents(t *testing.T) { } `graphql:"employeeUpdated(employeeID: 3)"` } - surl := xEnv.GraphQLWebSocketSubscriptionURL() - client := graphql.NewSubscriptionClient(surl) + client := graphql.NewSubscriptionClient(xEnv.GraphQLWebSocketSubscriptionURL()) resultCh := make(chan natsSubscriptionArgs, 1) - subscriptionID, err := client.Subscribe(&sub, nil, func(dataValue []byte, errValue error) error { + subscriptionHandler := func(dataValue []byte, errValue error) error { resultCh <- natsSubscriptionArgs{dataValue: dataValue, errValue: errValue} return nil - }) + } + + subscriptionID, err := client.Subscribe(&subscriptionQuery, nil, subscriptionHandler) require.NoError(t, err) require.NotEmpty(t, subscriptionID) @@ -229,7 +145,7 @@ func TestNATSTLSEvents(t *testing.T) { subject := xEnv.GetPubSubName("employeeUpdated.3") payload := []byte(`{"id":3,"__typename":"Employee"}`) - xEnv.NATSPublishUntilReceived(natsConn, subject, payload, 1, EventWaitTimeout) + xEnv.NATSPublishUntilReceived(natsHelperConn, subject, payload, 1, EventWaitTimeout) testenv.AwaitChannelWithT(t, EventWaitTimeout, resultCh, func(t *testing.T, args natsSubscriptionArgs) { require.NoError(t, args.errValue) @@ -245,71 +161,72 @@ func TestNATSTLSEvents(t *testing.T) { }) } - // Test 1: server requires TLS; router connects using InsecureSkipCaVerification. t.Run("router connects when server requires TLS", func(t *testing.T) { + // Server requires TLS; router connects using InsecureSkipCaVerification. t.Parallel() - certs := generateNATSTLSTestCerts(t) - srv := startTLSNATSServer(t, &natssrv.Options{ - Host: "127.0.0.1", - Port: -1, // tells nats to use a free port - TLS: true, - TLSConfig: buildServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), + certs := generateTLSCerts(t) + srv := startNATSServer(t, &natssrv.Options{ + Host: "127.0.0.1", + Port: -1, // tells nats to use a free port + TLS: true, + TLSConfig: createServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), + AllowNonTLS: false, }) serverURL := natsPlainURL(srv) - natsConn := connectInsecureTLSNATSClient(t, serverURL) + natsConn := connectToNATS(t, serverURL) routerTLS := &config.NatsTLSConfiguration{InsecureSkipCaVerification: true} testenv.Run(t, &testenv.Config{ RouterConfigJSONTemplate: testenv.ConfigWithEdfsNatsJSONTemplate, ModifyEventsConfiguration: func(cfg *config.EventsConfiguration) { - cfg.Providers.Nats = tlsNATSEventSources(serverURL, routerTLS) + cfg.Providers.Nats = tlsNATSEventSourceConfig(serverURL, routerTLS) }, }, func(t *testing.T, xEnv *testenv.Environment) { subscribePublishVerify(t, xEnv, natsConn) }) }) - // Test 2: router supplies a custom CA certificate to verify the server certificate. t.Run("router uses custom CA certificate", func(t *testing.T) { + // Router accepts nats server certs using a custom CA cert and connects to it. t.Parallel() - certs := generateNATSTLSTestCerts(t) - srv := startTLSNATSServer(t, &natssrv.Options{ + certs := generateTLSCerts(t) + srv := startNATSServer(t, &natssrv.Options{ Host: "127.0.0.1", Port: -1, // tells nats to use a free port TLS: true, - TLSConfig: buildServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), + TLSConfig: createServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), }) serverURL := natsPlainURL(srv) - natsConn := connectInsecureTLSNATSClient(t, serverURL) // Router verifies the server certificate against the custom CA — no InsecureSkipVerify. routerTLS := &config.NatsTLSConfiguration{CaFile: certs.CACertFile} testenv.Run(t, &testenv.Config{ RouterConfigJSONTemplate: testenv.ConfigWithEdfsNatsJSONTemplate, ModifyEventsConfiguration: func(cfg *config.EventsConfiguration) { - cfg.Providers.Nats = tlsNATSEventSources(serverURL, routerTLS) + cfg.Providers.Nats = tlsNATSEventSourceConfig(serverURL, routerTLS) }, }, func(t *testing.T, xEnv *testenv.Environment) { - subscribePublishVerify(t, xEnv, natsConn) + natsHelperConn := connectToNATS(t, serverURL) + subscribePublishVerify(t, xEnv, natsHelperConn) }) }) - // Test 3: server requires mutual TLS; router presents a client certificate. t.Run("router uses mTLS when configured", func(t *testing.T) { + // Server requires mutual TLS; router presents a client certificate. t.Parallel() - certs := generateNATSTLSTestCerts(t) + certs := generateTLSCerts(t) // Server requires client certs verified against the CA. - srv := startTLSNATSServer(t, &natssrv.Options{ + srv := startNATSServer(t, &natssrv.Options{ Host: "127.0.0.1", Port: -1, // tells nats to use a free port TLS: true, TLSVerify: true, - TLSConfig: buildMTLSServerConfig(t, certs.ServerCertFile, certs.ServerKeyFile, certs.CACertFile), + TLSConfig: createServerMTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile, certs.CACertFile), }) serverURL := natsPlainURL(srv) @@ -317,16 +234,8 @@ func TestNATSTLSEvents(t *testing.T) { // Test client also needs a client cert to connect to the mTLS server. clientCert, err := tls.LoadX509KeyPair(certs.ClientCertFile, certs.ClientKeyFile) require.NoError(t, err) - // The extra nats.Secure call overrides the default InsecureSkipVerify-only config and - // adds the client certificate while keeping InsecureSkipVerify for server cert validation. - natsConn := connectInsecureTLSNATSClient(t, serverURL, - nats.Secure(&tls.Config{ //nolint:gosec // test helper only - InsecureSkipVerify: true, - Certificates: []tls.Certificate{clientCert}, - }), - ) - - // Router uses the CA cert to verify the server and presents the client cert/key for mTLS. + + // Router uses the CA cert to verify the server and presents it's client cert/key for mTLS. routerTLS := &config.NatsTLSConfiguration{ CaFile: certs.CACertFile, CertFile: certs.ClientCertFile, @@ -336,42 +245,46 @@ func TestNATSTLSEvents(t *testing.T) { testenv.Run(t, &testenv.Config{ RouterConfigJSONTemplate: testenv.ConfigWithEdfsNatsJSONTemplate, ModifyEventsConfiguration: func(cfg *config.EventsConfiguration) { - cfg.Providers.Nats = tlsNATSEventSources(serverURL, routerTLS) + cfg.Providers.Nats = tlsNATSEventSourceConfig(serverURL, routerTLS) }, }, func(t *testing.T, xEnv *testenv.Environment) { - subscribePublishVerify(t, xEnv, natsConn) + // Helper connection needs to do mTLS as well in order to connect to the server + natsHelperConn := connectToNATS(t, serverURL, + nats.Secure(&tls.Config{ + InsecureSkipVerify: true, //nolint:gosec // test helper only + Certificates: []tls.Certificate{clientCert}, + }), + ) + subscribePublishVerify(t, xEnv, natsHelperConn) }) }) - // Test 4: router URL uses the "tls://" scheme, which signals the NATS client to use TLS. - t.Run("router uses TLS when URL scheme is tls://", func(t *testing.T) { + t.Run("router connects to server when using tls:// url", func(t *testing.T) { + // Router must also perform a TLS connection when nats url is prefixed with "tls://". t.Parallel() - certs := generateNATSTLSTestCerts(t) - srv := startTLSNATSServer(t, &natssrv.Options{ + certs := generateTLSCerts(t) + srv := startNATSServer(t, &natssrv.Options{ Host: "127.0.0.1", Port: -1, // tells nats to use a free port TLS: true, - TLSConfig: buildServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), + TLSConfig: createServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), }) // Use the tls:// URL from the server directly — this is what gets configured in the router. tlsSchemeURL := srv.ClientURL() - // Test client uses nats:// + explicit Secure option to connect to the same server. - natsConn := connectInsecureTLSNATSClient(t, natsPlainURL(srv)) - - // Router verifies the server certificate against the custom CA. No InsecureSkipVerify is - // needed here — the tls:// scheme enables TLS, and the CA file authenticates the server cert. + // Router verifies the server certificate against the custom CA. routerTLS := &config.NatsTLSConfiguration{CaFile: certs.CACertFile} testenv.Run(t, &testenv.Config{ RouterConfigJSONTemplate: testenv.ConfigWithEdfsNatsJSONTemplate, ModifyEventsConfiguration: func(cfg *config.EventsConfiguration) { - cfg.Providers.Nats = tlsNATSEventSources(tlsSchemeURL, routerTLS) + cfg.Providers.Nats = tlsNATSEventSourceConfig(tlsSchemeURL, routerTLS) }, }, func(t *testing.T, xEnv *testenv.Environment) { - subscribePublishVerify(t, xEnv, natsConn) + natsHelperConn := connectToNATS(t, natsPlainURL(srv)) + subscribePublishVerify(t, xEnv, natsHelperConn) }) }) } From e88bcca3c9e5200ecbba89263c3e37737bbb88b1 Mon Sep 17 00:00:00 2001 From: Dominik Korittki <23359034+dkorittki@users.noreply.github.com> Date: Tue, 12 May 2026 13:34:56 +0200 Subject: [PATCH 06/10] chore(router): add tls handshake failure test --- router-tests/events/nats_tls_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/router-tests/events/nats_tls_test.go b/router-tests/events/nats_tls_test.go index 448ac5af8f..f64176433f 100644 --- a/router-tests/events/nats_tls_test.go +++ b/router-tests/events/nats_tls_test.go @@ -50,6 +50,7 @@ func createServerMTLSConfig(t *testing.T, certFile, keyFile, caFile string) *tls // startNATSServer starts and returns an embedded, in-process NATS server with the given options. // It is automatically shut down when the test completes. +// https://docs.nats.io/running-a-nats-service/clients#embedding-nats func startNATSServer(t *testing.T, opts *natssrv.Options) *natssrv.Server { t.Helper() @@ -259,6 +260,32 @@ func TestRouterConnectsToNATSWithTLS(t *testing.T) { }) }) + t.Run("router fails to start when server requires TLS but no TLS configured", func(t *testing.T) { + // Server requires TLS; router has no TLS config — connection must fail at startup. + // The routers NATS client will attempt a TLS upgrade (server sends tls_required in INFO) + // but the self-signed cert is not in the system CA pool, so the handshake fails. + t.Parallel() + + certs := generateTLSCerts(t) + srv := startNATSServer(t, &natssrv.Options{ + Host: "127.0.0.1", + Port: -1, + TLS: true, + TLSConfig: createServerTLSConfig(t, certs.ServerCertFile, certs.ServerKeyFile), + AllowNonTLS: false, + }) + serverURL := natsPlainURL(srv) + + testenv.FailsOnStartup(t, &testenv.Config{ + RouterConfigJSONTemplate: testenv.ConfigWithEdfsNatsJSONTemplate, + ModifyEventsConfiguration: func(cfg *config.EventsConfiguration) { + cfg.Providers.Nats = tlsNATSEventSourceConfig(serverURL, nil) + }, + }, func(t *testing.T, err error) { + require.ErrorContains(t, err, "certificate is not trusted") + }) + }) + t.Run("router connects to server when using tls:// url", func(t *testing.T) { // Router must also perform a TLS connection when nats url is prefixed with "tls://". t.Parallel() From 8716acb67288fc05276e7b369e38986071282eaf Mon Sep 17 00:00:00 2001 From: Dominik Korittki <23359034+dkorittki@users.noreply.github.com> Date: Tue, 12 May 2026 15:28:14 +0200 Subject: [PATCH 07/10] chore(router): add cert mismatch nats test --- router-tests/events/nats_tls_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/router-tests/events/nats_tls_test.go b/router-tests/events/nats_tls_test.go index f64176433f..53dc2a0558 100644 --- a/router-tests/events/nats_tls_test.go +++ b/router-tests/events/nats_tls_test.go @@ -286,6 +286,34 @@ func TestRouterConnectsToNATSWithTLS(t *testing.T) { }) }) + t.Run("router fails to start when ca cert does not match server cert", func(t *testing.T) { + // Server uses a cert signed by serverCerts CA; router is configured with a + // completely different CA (unrelatedCerts), so certificate verification must fail. + t.Parallel() + + serverCerts := generateTLSCerts(t) + unrelatedCerts := generateTLSCerts(t) + + srv := startNATSServer(t, &natssrv.Options{ + Host: "127.0.0.1", + Port: -1, + TLS: true, + TLSConfig: createServerTLSConfig(t, serverCerts.ServerCertFile, serverCerts.ServerKeyFile), + }) + + serverURL := natsPlainURL(srv) + routerTLS := &config.NatsTLSConfiguration{CaFile: unrelatedCerts.CACertFile} + + testenv.FailsOnStartup(t, &testenv.Config{ + RouterConfigJSONTemplate: testenv.ConfigWithEdfsNatsJSONTemplate, + ModifyEventsConfiguration: func(cfg *config.EventsConfiguration) { + cfg.Providers.Nats = tlsNATSEventSourceConfig(serverURL, routerTLS) + }, + }, func(t *testing.T, err error) { + require.ErrorContains(t, err, "certificate signed by unknown authority") + }) + }) + t.Run("router connects to server when using tls:// url", func(t *testing.T) { // Router must also perform a TLS connection when nats url is prefixed with "tls://". t.Parallel() From 27847d5403b929dc8bfd23370389ef392693b86d Mon Sep 17 00:00:00 2001 From: Dominik Korittki <23359034+dkorittki@users.noreply.github.com> Date: Tue, 12 May 2026 15:30:10 +0200 Subject: [PATCH 08/10] fix(router): assert on os-independent error msg part --- router-tests/events/nats_tls_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router-tests/events/nats_tls_test.go b/router-tests/events/nats_tls_test.go index 53dc2a0558..c7bf5dfc14 100644 --- a/router-tests/events/nats_tls_test.go +++ b/router-tests/events/nats_tls_test.go @@ -282,7 +282,7 @@ func TestRouterConnectsToNATSWithTLS(t *testing.T) { cfg.Providers.Nats = tlsNATSEventSourceConfig(serverURL, nil) }, }, func(t *testing.T, err error) { - require.ErrorContains(t, err, "certificate is not trusted") + require.ErrorContains(t, err, "tls: failed to verify certificate") }) }) From 00ce5534ab42426ab305569ebd96ba2669cf9911 Mon Sep 17 00:00:00 2001 From: Dominik Korittki <23359034+dkorittki@users.noreply.github.com> Date: Tue, 12 May 2026 15:42:11 +0200 Subject: [PATCH 09/10] chore(router): move client close assertion into test cleanup func --- router-tests/events/nats_tls_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/router-tests/events/nats_tls_test.go b/router-tests/events/nats_tls_test.go index c7bf5dfc14..9b5620444e 100644 --- a/router-tests/events/nats_tls_test.go +++ b/router-tests/events/nats_tls_test.go @@ -139,7 +139,12 @@ func TestRouterConnectsToNATSWithTLS(t *testing.T) { clientErrCh := make(chan error, 1) go func() { clientErrCh <- client.Run() }() - t.Cleanup(func() { _ = client.Close() }) + t.Cleanup(func() { + require.NoError(t, client.Close()) + testenv.AwaitChannelWithT(t, EventWaitTimeout, clientErrCh, func(t *testing.T, err error) { + require.NoError(t, err) + }) + }) xEnv.WaitForSubscriptionCount(1, EventWaitTimeout) xEnv.WaitForTriggerCount(1, EventWaitTimeout) @@ -156,10 +161,6 @@ func TestRouterConnectsToNATSWithTLS(t *testing.T) { ) }) - require.NoError(t, client.Close()) - testenv.AwaitChannelWithT(t, EventWaitTimeout, clientErrCh, func(t *testing.T, err error) { - require.NoError(t, err) - }) } t.Run("router connects when server requires TLS", func(t *testing.T) { From d6737b6fa481be85286b411f62666f3facc35c53 Mon Sep 17 00:00:00 2001 From: Dominik Korittki <23359034+dkorittki@users.noreply.github.com> Date: Tue, 12 May 2026 15:54:28 +0200 Subject: [PATCH 10/10] chore(router): improve variable names and comments --- router-tests/events/nats_tls_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/router-tests/events/nats_tls_test.go b/router-tests/events/nats_tls_test.go index 9b5620444e..f2bb320545 100644 --- a/router-tests/events/nats_tls_test.go +++ b/router-tests/events/nats_tls_test.go @@ -78,7 +78,8 @@ func natsPlainURL(s *natssrv.Server) string { func connectToNATS(t *testing.T, serverURL string, extraOpts ...nats.Option) *nats.Conn { t.Helper() opts := []nats.Option{ - nats.Secure(&tls.Config{InsecureSkipVerify: true}), //nolint:gosec // test helper only + // allowing self-signed certificates for the test helper + nats.Secure(&tls.Config{InsecureSkipVerify: true}), //nolint:gosec nats.MaxReconnects(3), nats.Timeout(10 * time.Second), nats.ErrorHandler(func(_ *nats.Conn, _ *nats.Subscription, err error) { @@ -177,7 +178,7 @@ func TestRouterConnectsToNATSWithTLS(t *testing.T) { }) serverURL := natsPlainURL(srv) - natsConn := connectToNATS(t, serverURL) + natsHelperConn := connectToNATS(t, serverURL) routerTLS := &config.NatsTLSConfiguration{InsecureSkipCaVerification: true} testenv.Run(t, &testenv.Config{ @@ -186,7 +187,7 @@ func TestRouterConnectsToNATSWithTLS(t *testing.T) { cfg.Providers.Nats = tlsNATSEventSourceConfig(serverURL, routerTLS) }, }, func(t *testing.T, xEnv *testenv.Environment) { - subscribePublishVerify(t, xEnv, natsConn) + subscribePublishVerify(t, xEnv, natsHelperConn) }) })