Documentation
¶
Overview ¶
Package testutil provides helpers and utilities to make testing easier and less tedious.
Index ¶
- func ECDSACert(t *testing.T, tmpl *x509.Certificate) []byte
- func GenerateMTLSCerts(t *testing.T) (caFile, certFile, keyFile string)
- func GenerateRSACert(t *testing.T) (certFile, keyFile string)
- func GenerateSelfSignedCert(t *testing.T) (certFile, keyFile string)
- func RSACert(t *testing.T, tmpl *x509.Certificate) []byte
- func WriteFile(t *testing.T, dir, name string, contents []byte) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ECDSACert ¶
func ECDSACert(t *testing.T, tmpl *x509.Certificate) []byte
ECDSACert generates a self-signed ECDSA P-256 certificate from tmpl and returns its PEM encoding. The generated key is discarded; callers that need a matching key should use GenerateSelfSignedCert or GenerateMTLSCerts.
func GenerateMTLSCerts ¶
GenerateMTLSCerts writes a self-signed ECDSA P-256 CA certificate plus an RSA-2048 leaf certificate signed by that CA (with its matching key) to a fresh testing.T.TempDir and returns the three paths. The leaf is RSA because credential validation checks the leaf's key type against an RSA-only cipher suite allowlist; an ECDSA leaf fails that check even though it verifies fine against the CA. The leaf advertises CN "localhost" with DNSNames=["localhost"]; both certificates are valid for one hour. Use this when a test needs the leaf to verify against the CA.
func GenerateRSACert ¶
GenerateRSACert writes a self-signed RSA-2048 certificate and its matching PKCS#1 private key to a fresh testing.T.TempDir and returns the paths. It is the RSA counterpart to GenerateSelfSignedCert: the key is retained and written out, so the pair loads via crypto/tls.LoadX509KeyPair as a real TLS identity. The certificate advertises CN "localhost" with DNSNames=["localhost"] and both server- and client-auth extended key usages, so it serves as either a server certificate or a client identity. It is valid for one hour.
func GenerateSelfSignedCert ¶
GenerateSelfSignedCert writes a self-signed ECDSA P-256 certificate and its matching PKCS#1-style EC private key to a fresh testing.T.TempDir and returns the paths. The certificate is valid for one hour, advertises CN "localhost" with DNSNames=["localhost"], and is suitable for loading via crypto/tls.LoadX509KeyPair in server-auth scenarios.
func RSACert ¶
func RSACert(t *testing.T, tmpl *x509.Certificate) []byte
RSACert generates a self-signed RSA-2048 certificate from tmpl and returns its PEM encoding. The generated key is discarded; callers that need a matching key should use GenerateSelfSignedCert or GenerateMTLSCerts.
Types ¶
This section is empty.