testhelpers

package
v0.0.0-...-e8682ef Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttemptUnsealCore

func AttemptUnsealCore(c *vault.TestCluster, core *vault.TestClusterCore) error

func AttemptUnsealCores

func AttemptUnsealCores(c *vault.TestCluster) error

func AwaitLeader

func AwaitLeader(t testing.T, cluster *vault.TestCluster) (int, error)

AwaitLeader waits for one of the cluster's nodes to become leader.

func CreateEntityAndAlias

func CreateEntityAndAlias(t testing.T, client *api.Client, mountAccessor, entityName, aliasName string) (*api.Client, string, string)

CreateEntityAndAlias clones an existing client and creates an entity/alias. It returns the cloned client, entityID, and aliasID.

func DeriveActiveCore

func DeriveActiveCore(t testing.T, cluster *vault.TestCluster) *vault.TestClusterCore

func DeriveStableActiveCore

func DeriveStableActiveCore(t testing.T, cluster *vault.TestCluster) *vault.TestClusterCore

func DeriveStandbyCores

func DeriveStandbyCores(t testing.T, cluster *vault.TestCluster) []*vault.TestClusterCore

func EnsureCoreSealed

func EnsureCoreSealed(t testing.T, core *vault.TestClusterCore)

func EnsureCoreUnsealed

func EnsureCoreUnsealed(t testing.T, c *vault.TestCluster, core *vault.TestClusterCore)

func EnsureCoresSealed

func EnsureCoresSealed(t testing.T, c *vault.TestCluster)

func EnsureCoresUnsealed

func EnsureCoresUnsealed(t testing.T, c *vault.TestCluster)

func EnsureStableActiveNode

func EnsureStableActiveNode(t testing.T, cluster *vault.TestCluster)

func GenerateDebugLogs

func GenerateDebugLogs(t testing.T, client *api.Client) chan struct{}

func GenerateRoot

func GenerateRoot(t testing.T, cluster *vault.TestCluster, kind GenerateRootKind) string

GenerateRoot generates a root token on the target cluster.

func GenerateRootWithError

func GenerateRootWithError(t testing.T, cluster *vault.TestCluster, kind GenerateRootKind) (string, error)

func GetTOTPCodeFromEngine

func GetTOTPCodeFromEngine(t testing.T, client *api.Client, enginePath string) string

GetTOTPCodeFromEngine requests a TOTP code from the specified enginePath.

func IsLocalOrRegressionTests

func IsLocalOrRegressionTests() bool

IsLocalOrRegressionTests returns true when the tests are running locally (not in CI), or when the regression test env var (BAO_REGRESSION_TESTS) is provided.

func NewHardcodedServerAddressProvider

func NewHardcodedServerAddressProvider(numCores, baseClusterPort int) raftlib.ServerAddressProvider

NewHardcodedServerAddressProvider is a convenience function that makes a ServerAddressProvider from a given cluster address base port.

func RaftAppliedIndex

func RaftAppliedIndex(core *vault.TestClusterCore) uint64

func RaftClusterJoinNodes

func RaftClusterJoinNodes(t testing.T, cluster *vault.TestCluster)

func RandomWithPrefix

func RandomWithPrefix(name string) string

RandomWithPrefix is used to generate a unique name with a prefix, for randomizing names in acceptance tests

func RegisterEntityInTOTPEngine

func RegisterEntityInTOTPEngine(t testing.T, client *api.Client, entityID, methodID string) string

RegisterEntityInTOTPEngine registers an entity with a methodID and returns the generated name.

func RekeyCluster

func RekeyCluster(t testing.T, cluster *vault.TestCluster, recovery bool) [][]byte

func RetryUntil

func RetryUntil(t testing.T, timeout time.Duration, f func() error)

RetryUntil runs f until it returns a nil result or the timeout is reached. If a nil result hasn't been obtained by timeout, calls t.Fatal.

func RetryUntilAtCadence

func RetryUntilAtCadence(t testing.T, timeout, sleepTime time.Duration, f func() error)

RetryUntilAtCadence runs f until it returns a nil result or the timeout is reached. If a nil result hasn't been obtained by timeout, calls t.Fatal.

func SealCores

func SealCores(t testing.T, cluster *vault.TestCluster)

func SetNonRootToken

func SetNonRootToken(client *api.Client) error

SetNonRootToken sets a token on :client: with a fairly generic policy. This is useful if a test needs to examine differing behavior based on if a root token is passed with the request.

func SetupLoginMFATOTP

func SetupLoginMFATOTP(t testing.T, client *api.Client, methodName string, waitPeriod int) (*api.Client, string, string)

SetupLoginMFATOTP setups up a TOTP MFA using some basic configuration and returns all relevant information to the client.

func SetupMFALoginEnforcement

func SetupMFALoginEnforcement(t testing.T, client *api.Client, config map[string]interface{})

SetupMFALoginEnforcement configures a single enforcement method using the provided config map. "name" field is required in the config map.

func SetupTOTPMethod

func SetupTOTPMethod(t testing.T, client *api.Client, config map[string]interface{}) string

SetupTOTPMethod configures the TOTP secrets engine with a provided config map.

func SetupTOTPMount

func SetupTOTPMount(t testing.T, client *api.Client)

SetupTOTPMount enables the totp secrets engine by mounting it. This requires that the test cluster has a totp backend available.

func SetupUserpassMountAccessor

func SetupUserpassMountAccessor(t testing.T, client *api.Client) string

SetupUserpassMountAccessor sets up userpass auth and returns its mount accessor. This requires that the test cluster has a "userpass" auth method available.

func SkipUnlessEnvVarsSet

func SkipUnlessEnvVarsSet(t testing.T, envVars []string)

func TestMetricSinkProvider

func TestMetricSinkProvider(gaugeInterval time.Duration) func(string) (*metricsutil.ClusterMetricSink, *metricsutil.MetricsHelper)

func VerifyRaftConfiguration

func VerifyRaftConfiguration(core *vault.TestClusterCore, numCores int) error

VerifyRaftConfiguration checks that we have a valid raft configuration, i.e. the correct number of servers, having the correct NodeIDs, and exactly one leader.

func VerifyRaftPeers

func VerifyRaftPeers(t testing.T, client *api.Client, expected map[string]bool) error

VerifyRaftPeers verifies that the raft configuration contains a given set of peers. The `expected` contains a map of expected peers. Existing entries are deleted from the map by removing entries whose keys are in the raft configuration. Remaining entries result in an error return so that the caller can poll for an expected configuration.

func WaitForActiveNode

func WaitForActiveNode(t testing.T, cluster *vault.TestCluster) *vault.TestClusterCore

func WaitForActiveNodeAndStandbys

func WaitForActiveNodeAndStandbys(t testing.T, cluster *vault.TestCluster)

WaitForActiveNodeAndStandbys does nothing more than wait for the active node on OSS. On enterprise it waits for perf standbys to be healthy too.

func WaitForNCoresSealed

func WaitForNCoresSealed(t testing.T, cluster *vault.TestCluster, n int)

func WaitForNCoresUnsealed

func WaitForNCoresUnsealed(t testing.T, cluster *vault.TestCluster, n int)

func WaitForNodesExcludingSelectedStandbys

func WaitForNodesExcludingSelectedStandbys(t testing.T, cluster *vault.TestCluster, indexesToSkip ...int)

WaitForNodesExcludingSelectedStandbys is variation on WaitForActiveNodeAndStandbys. It waits for the active node before waiting for standby nodes, however it will not wait for cores with indexes that match those specified as arguments. Whilst you could specify index 0 which is likely to be the leader node, the function checks for the leader first regardless of the indexes to skip, so it would be redundant to do so. The intention/use case for this function is to allow a cluster to start and become active with one or more nodes not joined, so that we can test scenarios where a node joins later. e.g. 4 nodes in the cluster, only 3 nodes in cluster 'active', 1 node can be joined later in tests.

func WaitForRaftApply

func WaitForRaftApply(t testing.T, core *vault.TestClusterCore, index uint64)

func WaitForStandbyNode

func WaitForStandbyNode(t testing.T, core *vault.TestClusterCore)

Types

type GenerateRootKind

type GenerateRootKind int
const (
	GenerateRootRegular GenerateRootKind = iota
	GenerateRootDR
	GenerateRecovery
)

type HardcodedServerAddressProvider

type HardcodedServerAddressProvider struct {
	Entries map[raftlib.ServerID]raftlib.ServerAddress
}

HardcodedServerAddressProvider is a ServerAddressProvider that uses a hardcoded map of raft node addresses.

It is useful in cases where the raft configuration is known ahead of time, but some of the cores have not yet had startClusterListener() called (via either unsealing or raft joining), and thus do not yet have a ClusterAddr() assigned.

func (*HardcodedServerAddressProvider) ServerAddr

type SysMetricsJSON

type SysMetricsJSON struct {
	Gauges   []gaugeJSON   `json:"Gauges"`
	Counters []counterJSON `json:"Counters"`

	// note: this is referred to as a "Summary" type in our telemetry docs, but
	// the field name in the JSON is "Samples"
	Summaries []summaryJSON `json:"Samples"`
}

func SysMetricsReq

func SysMetricsReq(client *api.Client, cluster *vault.TestCluster, unauth bool) (*SysMetricsJSON, error)

type TestRaftServerAddressProvider

type TestRaftServerAddressProvider struct {
	Cluster *vault.TestCluster
}

TestRaftServerAddressProvider is a ServerAddressProvider that uses the ClusterAddr() of each node to provide raft addresses.

Note that TestRaftServerAddressProvider should only be used in cases where cores that are part of a raft configuration have already had startClusterListener() called (via either unsealing or raft joining).

func (*TestRaftServerAddressProvider) ServerAddr

Directories

Path Synopsis
Package corehelpers contains testhelpers that don't depend on package vault, and thus can be used within vault (as well as elsewhere.)
Package corehelpers contains testhelpers that don't depend on package vault, and thus can be used within vault (as well as elsewhere.)
Package pluginhelpers contains testhelpers that don't depend on package vault, and thus can be used within vault (as well as elsewhere.)
Package pluginhelpers contains testhelpers that don't depend on package vault, and thus can be used within vault (as well as elsewhere.)

Jump to

Keyboard shortcuts

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