netxtest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 18 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 netxtest holds loopback test wiring for code that talks through internal/netx: a throwaway certificate authority, TLS test servers whose leaf certificates name any host, and a CONNECT-only proxy. It imports only the standard library and never reaches the real network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(user, password string) string

BasicAuth returns the Proxy-Authorization value for user and password.

func NewTLSServer

func NewTLSServer(t testing.TB, ca *CA, handler http.Handler, hosts ...string) *httptest.Server

NewTLSServer starts a TLS server for handler with a leaf for hosts signed by ca. The server is closed when the test ends.

func NewTLSServerConfig

func NewTLSServerConfig(t testing.TB, ca *CA, handler http.Handler, tweak func(*tls.Config), hosts ...string) *httptest.Server

NewTLSServerConfig is NewTLSServer with tweak applied to the server TLS config before start (for example to set MaxVersion). A nil tweak changes nothing.

Types

type CA

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

CA is a test certificate authority with an ECDSA P-256 key.

func NewCA

func NewCA(t testing.TB) *CA

NewCA returns a fresh test CA valid for one day.

func (*CA) PEM

func (ca *CA) PEM() []byte

PEM returns the CA certificate in PEM form, for netx.Config.CABundle.

func (*CA) TLSConfig

func (ca *CA) TLSConfig(hosts ...string) *tls.Config

TLSConfig returns a server config holding a leaf certificate signed by ca for hosts (DNS names, or IP addresses as IP SANs). Failures fail the test that made ca.

type Proxy

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

Proxy is a CONNECT-only test proxy. It records every CONNECT target and every Proxy-Authorization value it receives, answers 407 when wantAuth is set and does not match, and tunnels to the target (mapped through dialAddrs) otherwise. A strict proxy (NewStrictProxy) answers 502 for a target dialAddrs does not map.

func NewProxy

func NewProxy(t testing.TB, dialAddrs map[string]string, wantAuth string) *Proxy

NewProxy starts a CONNECT proxy on loopback, closed when the test ends. dialAddrs maps a CONNECT target "host:port" to the loopback address to dial; wantAuth is the exact Proxy-Authorization value required ("" accepts any).

func NewStrictProxy added in v0.2.0

func NewStrictProxy(t testing.TB, dialAddrs map[string]string, wantAuth string) *Proxy

NewStrictProxy is NewProxy that never dials a target missing from dialAddrs: it answers 502 Bad Gateway instead, so a test whose code may reach any host (every verify host of the registry) stays on loopback.

func (*Proxy) Addr

func (p *Proxy) Addr() string

Addr returns the proxy listen address "127.0.0.1:port".

func (*Proxy) Auth

func (p *Proxy) Auth() []string

Auth returns every Proxy-Authorization value received, in order.

func (*Proxy) Connects

func (p *Proxy) Connects() []string

Connects returns every CONNECT target received, in order.

func (*Proxy) URL

func (p *Proxy) URL(user, password string) string

URL returns the proxy URL, with userinfo when user is not empty.

Jump to

Keyboard shortcuts

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