Documentation
¶
Overview ¶
Package testsupport holds fixtures shared by the protocol proxies' test suites (PostgreSQL, MySQL, MongoDB, Oracle, SQL Server).
Nothing here carries the `integration` build tag. The SQL Server suite mints its grants from the same fixture but runs against an in-process fake, so it is untagged and would not otherwise be able to import a tagged helper. That costs nothing in the shipped binary: this package is only ever imported by _test.go files, so it is absent from `go list -deps .` and never links into dbbat itself.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateGrantWithControls ¶
func CreateGrantWithControls( ctx context.Context, t *testing.T, dataStore *store.Store, userUID, databaseUID uuid.UUID, controls []string, opts ...GrantOption, ) (*store.Grant, error)
CreateGrantWithControls issues a grant carrying the given controls. Every grant is an *instance of a definition* and carries no shape of its own, so the definition has to exist first and be named by uid — an inline GrantDefinition on the grant is not enough (CreateGrant answers ErrGrantDefinitionRequired), which is what used to fail these suites at setup.
The definition's name/slug is randomized per call: a suite that seeds twice against one store would otherwise trip "grant definition with this slug already exists". Callers never have to think about it.
func PipeSSHChannel ¶ added in v0.27.0
PipeSSHChannel relays an accepted direct-tcpip channel to its upstream connection, the way a real sshd does — and, crucially for the tests that use it, propagating each direction's EOF as a *half*-close rather than a full one.
That distinction is the whole point of this helper existing. A relay that answers one direction's EOF by closing the opposite end tears down bytes that are still in flight: an upstream which writes a protocol-level refusal and then half-closes has its refusal truncated, and the client sees a bare EOF instead. The conncheck suite classifies exactly that difference (db_auth_failed vs db_handshake_failed), so a full-closing relay makes it flaky. Here each copy shuts down only the write side of the peer it was feeding, and both ends are closed for real only once both directions have finished.
Test support only: production never relays an SSH channel like this. The real tunnel hands x/crypto/ssh's net.Conn straight to the database driver.
Types ¶
type GrantOption ¶
type GrantOption func(*store.GrantDefinition)
GrantOption tunes the definition a grant is minted from, for the suites that care about a field the common case never sets. It is an option rather than another parameter so the four suites that only ever pass controls keep reading as one line.
func WithApprovalPatterns ¶
func WithApprovalPatterns(patterns ...string) GrantOption
WithApprovalPatterns puts approval-hold patterns on the definition — the RE2 patterns that suspend a matching statement until a second human releases it. The SQL Server suites are the ones that exercise holds.
func WithMaxBytesTransferred ¶
func WithMaxBytesTransferred(maxBytes int64) GrantOption
WithMaxBytesTransferred puts a transfer quota on the definition — the cumulative wire-byte budget the limit guard enforces mid-stream. The Oracle suite uses it to trip a quota in the middle of a reply, which is the only way to observe the refusal that cuts into a call rather than answering one.
func WithStatementTimeout ¶ added in v0.29.0
func WithStatementTimeout(seconds int64) GrantOption
WithStatementTimeout puts a per-statement time limit on the definition, in seconds. Zero is meaningful here and is *not* "unset": it means "no limit, overriding the instance-wide default", which is the state a dump or ETL definition needs. Leaving the option off is what means "inherit".