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 ¶
- func Files(t testing.TB) (certFile, keyFile, caFile, seedFile string)
- func RegenCert(certPath, keyPath, caPath string) error
- func RoleFiles(t testing.TB) (certFile, keyFile, caFile, lordSeed, thrallSeed, operatorSeed string)
- func RotateCert(t testing.TB, certPath, keyPath string) (newCAFile string)
- func RotateSeed(t testing.TB, seedPath string) (oldSeedPath string)
- type Secured
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Files ¶ added in v0.9.0
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
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
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
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
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 ¶
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.