feat: support nats nkey seed auth (#21231)

This commit is contained in:
Matt Lloyd
2025-04-27 05:30:57 +01:00
committed by GitHub
parent f14198e3dc
commit 0e017ab071
5 changed files with 54 additions and 0 deletions

View File

@@ -19,6 +19,8 @@ package target
import (
"testing"
"github.com/nats-io/nats-server/v2/server"
xnet "github.com/minio/pkg/v3/net"
natsserver "github.com/nats-io/nats-server/v2/test"
)
@@ -96,3 +98,34 @@ func TestNatsConnToken(t *testing.T) {
}
defer con.Close()
}
func TestNatsConnNKeySeed(t *testing.T) {
opts := natsserver.DefaultTestOptions
opts.Port = 14223
opts.Nkeys = []*server.NkeyUser{
{
// Not a real NKey
// Taken from https://docs.nats.io/running-a-nats-service/configuration/securing_nats/auth_intro/nkey_auth
Nkey: "UDXU4RCSJNZOIQHZNWXHXORDPRTGNJAHAHFRGZNEEJCPQTT2M7NLCNF4",
},
}
s := natsserver.RunServer(&opts)
defer s.Shutdown()
clientConfig := &NATSArgs{
Enable: true,
Address: xnet.Host{
Name: "localhost",
Port: (xnet.Port(opts.Port)),
IsPortSet: true,
},
Subject: "test",
NKeySeed: "testdata/contrib/test.nkey",
}
con, err := clientConfig.connectNats()
if err != nil {
t.Errorf("Could not connect to nats: %v", err)
}
defer con.Close()
}