webhooktest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 7 Imported by: ? 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 webhooktest provides a sign↔verify conformance suite for webhook.Signer and webhook.Verifier implementations. It is intended for _test.go use only; production code must not import this package.

kernel/ layering rule: non-_test.go files in kernel/ must not import testify or kernel/clock/clockmock. This package uses stdlib testing.T helpers only and accepts a VerifierFactory to avoid importing clockmock directly.

Usage — wire in the package-level conformance call:

func TestSignerVerifierConformance(t *testing.T) {
    webhooktest.RunSignerVerifierConformance(t,
        webhook.NewHMACSigner,
        func(ts time.Time) (webhook.Verifier, error) {
            return webhook.NewHMACVerifier(clockmock.New(ts))
        },
    )
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunSignerVerifierConformance

func RunSignerVerifierConformance(
	t *testing.T,
	newSigner func(webhook.Source) (webhook.Signer, error),
	newVerifier VerifierFactory,
)

RunSignerVerifierConformance runs the sign↔verify behavioral contract suite.

newSigner is a factory bound to a given Source. newVerifier is a factory that pins the verifier's clock to the given time.

Sub-cases:

  1. round_trip: sign produces Headers that verify passes.
  2. tamper_body: altering the body after signing → ErrWebhookInvalidSignature.
  3. tamper_signature: corrupted signature token → ErrWebhookInvalidSignature.
  4. tamper_timestamp_expired: out-of-window timestamp → ErrWebhookTimestampExpired.
  5. multi_token_rotation_first_matches: first valid token in multi-token header accepted.
  6. multi_token_rotation_second_matches: last token in multi-token header also accepted.
  7. timestamp_outside_window: bidirectional tolerance check.
  8. empty_secret_source_rejected_by_signer: zero-value Source → ErrWebhookConfigInvalid.
  9. no_matching_token: two non-matching tokens → ErrWebhookInvalidSignature.

Types

type VerifierFactory

type VerifierFactory func(ts time.Time) (webhook.Verifier, error)

VerifierFactory creates a webhook.Verifier whose internal clock is pinned to ts. The caller provides the factory so conformance.go does not import kernel/clock/clockmock (kernel-isolation rule prohibits clockmock in non-_test.go kernel files).

Jump to

Keyboard shortcuts

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