Documentation
¶
Overview ¶
Package testing provides test utilities for the keystore package. It includes MockKeyStore for unit testing modules that depend on app.KeyStore.
Index ¶
- func AssertKeyNotFound(t *testing.T, ks app.KeyStore, name string)
- func AssertPrivateKeyAvailable(t *testing.T, ks app.KeyStore, name string)
- func AssertPublicKeyAvailable(t *testing.T, ks app.KeyStore, name string)
- func AssertSecretAvailable(t *testing.T, ks app.KeyStore, name string)
- type MockKeyStore
- func (m *MockKeyStore) Generations(logical string) []keystore.Generation
- func (m *MockKeyStore) PrivateKey(name string) (*rsa.PrivateKey, error)
- func (m *MockKeyStore) PublicKey(name string) (*rsa.PublicKey, error)
- func (m *MockKeyStore) RecordResolution(entry, role string)
- func (m *MockKeyStore) Recorded() [][2]string
- func (m *MockKeyStore) Secret(name string) ([]byte, error)
- func (m *MockKeyStore) WithGeneration(logical, version string, role keystore.Role) *MockKeyStore
- func (m *MockKeyStore) WithPrivateKey(name string, key *rsa.PrivateKey) *MockKeyStore
- func (m *MockKeyStore) WithPrivateKeyError(err error) *MockKeyStore
- func (m *MockKeyStore) WithPublicKey(name string, key *rsa.PublicKey) *MockKeyStore
- func (m *MockKeyStore) WithPublicKeyError(err error) *MockKeyStore
- func (m *MockKeyStore) WithSecret(name string, secret []byte) *MockKeyStore
- func (m *MockKeyStore) WithSecretError(err error) *MockKeyStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertKeyNotFound ¶
AssertKeyNotFound verifies that retrieving a key with the given name is a miss on both PublicKey and PrivateKey: each lookup must return a non-nil error AND no key. Note that this does not distinguish between "key name not found" and "no private key configured" — error-ness alone is all it reads from the error.
A stray key is reported by dynamic TYPE only, never by value (ADR-102).
An unexpectedly FOUND public key — an error-free lookup, or a key handed back alongside the error — aborts the caller's test rather than recording a failure and continuing: the private-key assertion that follows would otherwise run against a keystore already known to be in the wrong state, and its result — pass or fail — says nothing useful once the first lookup has produced a key (ADR-101).
func AssertPrivateKeyAvailable ¶
AssertPrivateKeyAvailable verifies that a private key with the given name can be successfully retrieved from the KeyStore.
func AssertPublicKeyAvailable ¶
AssertPublicKeyAvailable verifies that a public key with the given name can be successfully retrieved from the KeyStore.
Types ¶
type MockKeyStore ¶
type MockKeyStore struct {
// contains filtered or unexported fields
}
MockKeyStore implements app.KeyStore for unit testing. Use the fluent builder methods to configure keys and error behavior.
Example:
mock := kstest.NewMockKeyStore().
WithPublicKey("signing", pubKey).
WithPrivateKey("signing", privKey)
deps := &app.ModuleDeps{
KeyStore: mock,
}
func NewMockKeyStore ¶
func NewMockKeyStore() *MockKeyStore
NewMockKeyStore creates an empty MockKeyStore.
func (*MockKeyStore) Generations ¶ added in v0.63.0
func (m *MockKeyStore) Generations(logical string) []keystore.Generation
Generations implements keystore.FamilyEnumerator.
func (*MockKeyStore) PrivateKey ¶
func (m *MockKeyStore) PrivateKey(name string) (*rsa.PrivateKey, error)
PrivateKey implements app.KeyStore.
func (*MockKeyStore) PublicKey ¶
func (m *MockKeyStore) PublicKey(name string) (*rsa.PublicKey, error)
PublicKey implements app.KeyStore.
func (*MockKeyStore) RecordResolution ¶ added in v0.63.0
func (m *MockKeyStore) RecordResolution(entry, role string)
RecordResolution implements keystore.RoleRecorder: the mock remembers every (entry, role) a startup resolution tagged, in call order, so a test can assert which entries the module under test claimed and under which role.
func (*MockKeyStore) Recorded ¶ added in v0.63.0
func (m *MockKeyStore) Recorded() [][2]string
Recorded returns the (entry, role) pairs RecordResolution received, in order.
func (*MockKeyStore) Secret ¶ added in v0.35.0
func (m *MockKeyStore) Secret(name string) ([]byte, error)
Secret implements app.KeyStore. It returns a defensive copy, mirroring the real store so tests exercise the same ownership contract.
func (*MockKeyStore) WithGeneration ¶ added in v0.63.0
func (m *MockKeyStore) WithGeneration(logical, version string, role keystore.Role) *MockKeyStore
WithGeneration declares one provisioned generation of a Logical kid. The mock applies no grammar, so a test controls the exact accept set the module under test sees, but it keeps the FamilyEnumerator ordering contract: Generations returns ascending versions whatever the declaration order. Pair it with WithPublicKey and friends on the generation's Kid() when the module also fetches material.
func (*MockKeyStore) WithPrivateKey ¶
func (m *MockKeyStore) WithPrivateKey(name string, key *rsa.PrivateKey) *MockKeyStore
WithPrivateKey adds a private key for the given name.
func (*MockKeyStore) WithPrivateKeyError ¶
func (m *MockKeyStore) WithPrivateKeyError(err error) *MockKeyStore
WithPrivateKeyError configures all PrivateKey calls to return this error.
func (*MockKeyStore) WithPublicKey ¶
func (m *MockKeyStore) WithPublicKey(name string, key *rsa.PublicKey) *MockKeyStore
WithPublicKey adds a public key for the given name.
func (*MockKeyStore) WithPublicKeyError ¶
func (m *MockKeyStore) WithPublicKeyError(err error) *MockKeyStore
WithPublicKeyError configures all PublicKey calls to return this error.
func (*MockKeyStore) WithSecret ¶ added in v0.35.0
func (m *MockKeyStore) WithSecret(name string, secret []byte) *MockKeyStore
WithSecret adds raw symmetric key material for the given name. The slice is copied so later caller mutations do not bleed into the mock.
func (*MockKeyStore) WithSecretError ¶ added in v0.35.0
func (m *MockKeyStore) WithSecretError(err error) *MockKeyStore
WithSecretError configures all Secret calls to return this error.