tlstest

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 16 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 tlstest makes certificate authorities and TLS servers whose leaf a given authority signed, so a test can show that a client trusts one CA and refuses another. httptest.NewTLSServer cannot show that: every server it starts presents the same built-in certificate.

The package is imported only from tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CA

type CA struct {
	// contains filtered or unexported fields
}

CA is a certificate authority that exists for the length of one test.

func NewCA

func NewCA(t testing.TB) *CA

NewCA creates a CA and writes its certificate to a PEM file under t.TempDir(), which File returns.

func (*CA) File

func (ca *CA) File() string

File returns the path of a PEM file that holds the CA certificate and nothing else.

func (*CA) Server

func (ca *CA) Server(t testing.TB, h http.Handler) *httptest.Server

Server starts an HTTPS server for h whose certificate the CA signed for 127.0.0.1, ::1 and localhost. The server sends that leaf alone, without the CA certificate, so a client completes the handshake only when it already trusts the CA. The server is closed when the test ends.

The client that srv.Client() returns trusts the leaf directly, so a test that proves verification must use the client it is testing instead.

Jump to

Keyboard shortcuts

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