natstest

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package natstest spins up an embedded NATS server secured with nkey auth and server TLS, for tests that need to prove aether authenticates to a secured bus. It generates an ephemeral nkey and a self-signed certificate into the test's temp dir and returns the paths a client needs (CA and nkey seed). It is test-only support code, imported only from _test.go files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Files added in v0.9.0

func Files(t testing.TB) (certFile, keyFile, caFile, seedFile string)

Files generates the on-disk credential material a [nats.security] block points at: a self-signed server cert/key (the cert doubling as the CA) and an nkey seed authorized to connect. They are written to the test's temp dir and their paths returned, so a test can drive the real secured embedded server through the manifest path.

func RegenCert added in v0.10.0

func RegenCert(certPath, keyPath, caPath string) error

RegenCert regenerates a fresh self-signed cert/key and writes it to certPath, keyPath and caPath (the cert doubling as the CA), all in place. It takes no *testing.T and returns an error, so a soak run can rotate the certificate from a worker goroutine. A caller then reloads the server (Ether.Reload) to apply it.

func RoleFiles added in v0.9.0

func RoleFiles(t testing.TB) (certFile, keyFile, caFile, lordSeed, thrallSeed, operatorSeed string)

RoleFiles is Files plus a distinct nkey seed per role (lord / thrall / operator), for driving the least-privilege tier of [nats.security].

func RotateCert added in v0.9.0

func RotateCert(t testing.TB, certPath, keyPath string) (newCAFile string)

RotateCert generates a fresh self-signed cert/key and overwrites certPath and keyPath with it, as an operator does when renewing a certificate in place. It returns the path to a CA file matching the new cert (written next to it), for a client to verify the rotated server against.

func RotateSeed added in v0.9.0

func RotateSeed(t testing.TB, seedPath string) (oldSeedPath string)

RotateSeed generates a fresh nkey user and overwrites seedPath with its seed, as an operator does when rotating a key in place. It first copies the old seed to a sibling ".old" file and returns that path, so a test can prove the old identity is no longer accepted after a reload.

Types

type Secured

type Secured struct {
	URL      string // bus address (the server requires TLS + nkey to connect)
	CAFile   string // PEM CA the client verifies the server against
	SeedFile string // nkey seed file the client authenticates with
}

Secured holds the connection details for a secured embedded server.

func SecuredServer

func SecuredServer(t testing.TB) Secured

SecuredServer starts an embedded NATS server that requires nkey auth over server TLS, with JetStream enabled (durable mailbox / KV registry). The server and its storage are torn down via t.Cleanup. The returned CA and seed files are what a client must present; connecting without them is rejected.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL