testinstance

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package testinstance builds an initialized instance for tests of the HTTP layers (API, web UI): init --demo with the test CA, the services wired like the server does, a fake clock and helpers for users and TOTP codes. It is imported by tests only.

Index

Constants

View Source
const BrowserOrigin = "https://pki.homelab.lan:9443"

BrowserOrigin is where the tests' browser runs (passkeys, step 17).

View Source
const Password = "a long password for the HTTP tests"

Password is the password of every user made with User.

Variables

View Source
var Console = keys.Who{Actor: audit.Actor{Type: audit.ActorUser, Name: "console:test"}, Principal: authz.Console()}

Console is the console operator of the tests.

Functions

func Audit

func Audit(t *testing.T, db *store.DB) []string

Audit lists "action/result" of an audit log (direct entries are there at once; outbox entries need a delivery, which these tests don't run).

func AuditIPs

func AuditIPs(t *testing.T, db *store.DB) []string

AuditIPs lists "action/result ip" of an audit log.

func TOTP

func TOTP(secret string, at time.Time) string

TOTP is the RFC 6238 code of a Base32 secret (as shown at enrollment) at t.

Types

type Instance

type Instance struct {
	Auth    *auth.Service
	Engine  *ca.Engine
	Ring    *keys.Keyring
	Presets *preset.Set
	Clock   *clock.Fake
	// SystemDB, InstanceAudit, TenantAudit and PKIDB are open for checks.
	SystemDB, InstanceAudit, TenantAudit, PKIDB *store.DB
	// Config is the configuration init ran with (data directory, auth key).
	Config config.Config

	Passphrase   string // unseal passphrase
	DemoPassword string // password of the init user "demo"
	CAIDs        map[string]string
	// contains filtered or unexported fields
}

Instance is an initialized instance, sealed.

func New

func New(t *testing.T, o Options) *Instance

New runs init --demo with the test CA and wires the services. The clock is not on a whole second: the engine works in seconds, sessions in milliseconds, and the tests must see both.

func OpenExisting added in v0.2.0

func OpenExisting(t *testing.T, dataDir, demoSecretsFile string) *Instance

OpenExisting opens a data directory made elsewhere – an older release, a restored backup – with the secrets file of its `init --demo`. Like server.Open it first applies the migrations of this build (the upgrade test, PHASE2 step 15).

func (*Instance) Code

func (v *Instance) Code(name string) string

Code is the TOTP code of name now (RFC 6238: HMAC-SHA1, 30 s, 6 digits).

func (*Instance) Deliver

func (v *Instance) Deliver(t *testing.T)

Deliver moves the outbox entries of system.db and pki.db into their audit logs, as the server's deliverer does.

func (*Instance) Unseal

func (v *Instance) Unseal(t *testing.T)

Unseal unlocks the keyring as the console.

func (*Instance) User

func (v *Instance) User(t *testing.T, name string, instanceAdmin bool, roles ...authz.Binding)

User creates a user with Password and roles in the default tenant.

func (*Instance) UserID

func (v *Instance) UserID(t *testing.T, name string) string

UserID is the ID of the user name.

type Options

type Options struct {
	// Hostname is O of the test CA; "" = "pki01".
	Hostname string
	// BaseURL of the test CA; "" = http://pki.homelab.lan.
	BaseURL string
	// NoPasskeys leaves passkeys off (default: on for BrowserOrigin).
	NoPasskeys bool
}

Options shape the instance.

Jump to

Keyboard shortcuts

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