probetest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package probetest builds the stub debug endpoints that RFC-0013's tests run against: a port that accepts and stalls, one that completes the WebSocket upgrade (now or later), and one with nothing listening at all.

It exists because the consent-pending state is exactly a TCP listener that accepts and says nothing, so every scenario in that RFC is reproducible with net.Listen and no browser — which matters more here than usual: reproducing the bug by hand wedged a real user's Chrome twice, and a regression test that needs a human to click a browser-modal dialog is not a test.

Three packages needed the same three listeners and each grew its own, with different signatures and separately maintained comments. Only two of them counted accepted connections, which is the assertion that proves the property the whole RFC turns on: each connection to the debug endpoint is a consent request, so "how many did we open" is the question.

It cannot live in chrometest: that package imports internal/chrome, and internal/chrome is one of the packages that needs this.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptFor

func AcceptFor(key string) string

AcceptFor is RFC 6455's Sec-WebSocket-Accept for a given key.

func RequestKey

func RequestKey(req string) string

RequestKey pulls the Sec-WebSocket-Key out of a handshake request.

Types

type Endpoint

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

Endpoint is a stub Chrome debug endpoint in one of the shapes the probe has to tell apart.

func Answer

func Answer(t *testing.T, delay time.Duration, status string) *Endpoint

Answer accepts and, after delay, completes the WebSocket upgrade with status — the user finding the dialog behind the window and clicking Allow. A 101 status gets a full, VALID RFC 6455 response, with Sec-WebSocket-Accept computed from the key the client actually sent; the probe verifies it, so a stub that skipped it would be testing nothing.

Pass a non-101 status for a live server that is not a CDP browser (a stale port file whose port another process has taken).

func AnswerRaw

func AnswerRaw(t *testing.T, delay time.Duration, reply func(req string) string) *Endpoint

AnswerRaw accepts and, after delay, writes exactly what reply returns for the request it received — for the handshakes that are meant to be wrong.

func Chrome

func Chrome(t *testing.T, delay time.Duration, status string) *Endpoint

Chrome is an endpoint with the HTTP JSON API present, i.e. a Chrome launched with --remote-debugging-port rather than toggled on in chrome://inspect. It answers /json/version with a WebSocket URL on its OWN host:port — which is the only authority the resolver will believe — and treats every other request as the upgrade: stalling forever when status is empty, replying with status after delay otherwise.

One listener, because a real Chrome is one listener. Splitting the JSON API and the WebSocket across two ports would be testing a shape that cannot occur, and the resolver rejects it on purpose.

func Closed

func Closed(t *testing.T) *Endpoint

Closed returns an endpoint with nothing listening on it: a stale port file, or a Chrome that has quit. It must fail in milliseconds, which is the safety property that makes waiting minutes on a stalling one acceptable.

func Stall

func Stall(t *testing.T) *Endpoint

Stall accepts connections and never answers — Chrome holding an unanswered consent prompt, which is the only state that hangs rather than failing.

func (*Endpoint) Addr

func (e *Endpoint) Addr() net.Addr

Addr is the endpoint's address, listening or not.

func (*Endpoint) AnsweredLive

func (e *Endpoint) AnsweredLive() bool

AnsweredLive reports whether an Answer endpoint's reply landed on a socket that was still open — i.e. whether the consent the user granted went to a connection somebody had kept.

func (*Endpoint) Conns

func (e *Endpoint) Conns() int32

Conns is how many connections have been accepted. Every one of them is a consent request, so a test that asserts zero (or exactly one) is asserting the property the RFC exists to protect.

func (*Endpoint) HostPort

func (e *Endpoint) HostPort() string

HostPort is the endpoint's "127.0.0.1:port".

func (*Endpoint) Port

func (e *Endpoint) Port() string

Port is the endpoint's port number as a string.

func (*Endpoint) PortFile

func (e *Endpoint) PortFile(t *testing.T) string

PortFile writes a DevToolsActivePort file pointing at this endpoint and returns its path.

func (*Endpoint) UsePortFile

func (e *Endpoint) UsePortFile(t *testing.T) string

UsePortFile writes the port file and points CHROME_CDP_PORT_FILE at it, so a command discovers this endpoint the way it discovers a real Chrome.

func (*Endpoint) WS

func (e *Endpoint) WS() string

WS is the browser-level ws:// URL for this endpoint.

Jump to

Keyboard shortcuts

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