test: TLS data plane end to end + CA/keypair loaders
client/tls_test: mints a throwaway CA + server cert in-memory; a client pinning the CA completes the handshake and operates (golden), a client without the CA fails the handshake (error path). busauth/tls_test: golden load of a CA PEM and a server keypair, plus error paths (missing file, non-PEM). Harness body extracted to bootHarness(ctrlMode, natsAuth, natsTLS). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package client_test
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/hex"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -59,6 +60,12 @@ func newHarnessMode(t *testing.T, mode membership.AuthMode) *testHarness {
|
||||
// flags compose. The store is created before NATS so the authenticator can
|
||||
// consult IsAuthorized for live revocation.
|
||||
func newHarnessFull(t *testing.T, ctrlMode membership.AuthMode, natsAuth bool) *testHarness {
|
||||
return bootHarness(t, ctrlMode, natsAuth, nil)
|
||||
}
|
||||
|
||||
// bootHarness is the shared body: a store, an embedded NATS (optionally with the
|
||||
// nkey authenticator and/or TLS), and the membershipd HTTP server in ctrlMode.
|
||||
func bootHarness(t *testing.T, ctrlMode membership.AuthMode, natsAuth bool, natsTLS *tls.Config) *testHarness {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
|
||||
@@ -67,13 +74,16 @@ func newHarnessFull(t *testing.T, ctrlMode membership.AuthMode, natsAuth bool) *
|
||||
t.Fatalf("membership store: %v", err)
|
||||
}
|
||||
|
||||
var ns *server.Server
|
||||
if natsAuth {
|
||||
ns, err = embeddednats.StartHostAuth(filepath.Join(dir, "js"), "127.0.0.1", freePort(t),
|
||||
busauth.NewNkeyAuthenticator(store.IsAuthorized))
|
||||
} else {
|
||||
ns, err = embeddednats.Start(filepath.Join(dir, "js"), freePort(t))
|
||||
cfg := embeddednats.ServerConfig{
|
||||
StoreDir: filepath.Join(dir, "js"),
|
||||
Host: "127.0.0.1",
|
||||
Port: freePort(t),
|
||||
TLS: natsTLS,
|
||||
}
|
||||
if natsAuth {
|
||||
cfg.Auth = busauth.NewNkeyAuthenticator(store.IsAuthorized)
|
||||
}
|
||||
ns, err := embeddednats.StartServer(cfg)
|
||||
if err != nil {
|
||||
store.Close()
|
||||
t.Fatalf("embedded nats: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user