testutil

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPrivateKey

func GetPrivateKey(t *testing.T, identityIndex int) string

GetPrivateKey returns the PEM-encoded private key for the identity at the given 1-based index. Returns empty string if the identity has no private key.

func GetTestClient

func GetTestClient(t *testing.T, identityIndex int) *protect.Client

GetTestClient creates a ProtectClient from the identity at the given 1-based index. The client is configured with SuperAdmin keys for integrity verification.

func ParseProperties

func ParseProperties(filename string) (map[string]string, error)

ParseProperties parses a .properties file (key=value format). Supports # comments, blank lines, and literal \n escape in values (for PEM keys).

func SkipIfInsufficientIdentities

func SkipIfInsufficientIdentities(t *testing.T, required int)

SkipIfInsufficientIdentities skips the test if fewer than required identities are configured.

func SkipIfNotEnabled

func SkipIfNotEnabled(t *testing.T)

SkipIfNotEnabled skips the test if integration/e2e tests are not enabled.

Types

type Identity

type Identity struct {
	Index      int
	Name       string
	APIKey     string
	APISecret  string
	PrivateKey string // PEM string
	PublicKey  string // PEM string
}

Identity represents a user identity with optional API credentials, private key, and public key.

func (*Identity) HasAPICredentials

func (id *Identity) HasAPICredentials() bool

HasAPICredentials returns true if this identity has both API key and secret.

func (*Identity) HasPrivateKey

func (id *Identity) HasPrivateKey() bool

HasPrivateKey returns true if this identity has a private key.

func (*Identity) HasPublicKey

func (id *Identity) HasPublicKey() bool

HasPublicKey returns true if this identity has a public key.

type TestConfig

type TestConfig struct {
	Host               string
	MinValidSignatures int
	Identities         []Identity
}

TestConfig holds multi-identity test configuration.

func LoadConfig

func LoadConfig() *TestConfig

LoadConfig loads configuration from test.properties file with environment variable overrides. The properties file is searched in multiple locations relative to the project root. Environment variables: PROTECT_API_HOST, PROTECT_MIN_VALID_SIGNATURES, PROTECT_API_KEY_N, PROTECT_API_SECRET_N, PROTECT_PRIVATE_KEY_N, PROTECT_PUBLIC_KEY_N.

func (*TestConfig) GetIdentity

func (c *TestConfig) GetIdentity(index int) *Identity

GetIdentity returns the identity with the given 1-based index (supports gaps).

func (*TestConfig) GetIdentityCount

func (c *TestConfig) GetIdentityCount() int

GetIdentityCount returns the number of configured identities.

func (*TestConfig) GetSuperAdminKeys

func (c *TestConfig) GetSuperAdminKeys() []string

GetSuperAdminKeys returns all public keys from identities that have them.

func (*TestConfig) IsEnabled

func (c *TestConfig) IsEnabled() bool

IsEnabled returns true if tests should run. Tests are enabled if PROTECT_INTEGRATION_TEST=true or any identity has API credentials.

Jump to

Keyboard shortcuts

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