testutil

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package testutil provides helpers and utilities to make testing easier and less tedious.

Index

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

func GenerateMTLSCerts(t *testing.T) (caFile, certFile, keyFile string)

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

func GenerateRSACert(t *testing.T) (certFile, keyFile string)

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

func GenerateSelfSignedCert(t *testing.T) (certFile, keyFile string)

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.

func WriteFile

func WriteFile(t *testing.T, dir, name string, contents []byte) string

WriteFile writes contents to dir/name with mode 0600 and returns the full path. Any IO failure fails the test immediately. Callers typically pass testing.T.TempDir as dir so cleanup is automatic.

Types

This section is empty.

Jump to

Keyboard shortcuts

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