Documentation
¶
Overview ¶
Package provtest is the conformance suite of the cryptoprov key management contract: every provider of this module runs it against its own backend or fake, so that the rules of a listing mean the same thing on a PKCS#11 token, on AWS KMS, on Google Cloud KMS and in memory.
The suite generates a small set of keys with a random label prefix, lists and describes them, and destroys them when it ends. It asserts that a full listing at several page sizes returns every key once, that every filter selects the expected keys, that a page token is rejected with another filter or field mask, that no listing returns a public key, that the requested field groups are filled, that a missing key and an unsupported request are reported with cryptoprov.ErrKeyNotFound and cryptoprov.ErrNotSupported, and that a cancelled context fails the call. What a backend cannot do is declared in Config, not skipped silently.
func TestConformance(t *testing.T) {
provtest.Run(t, provtest.Config{
New: func(t *testing.T) cryptoprov.Provider {
return inmemcrypto.NewProvider()
},
Tags: true,
Encrypt: true,
MLDSA: true,
DestroyRemoves: true,
})
}
Index ¶
- func Run(t *testing.T, cfg Config)
- type Config
- type Suite
- func (s *Suite) SetupSuite()
- func (s *Suite) TearDownSuite()
- func (s *Suite) TestCancelledContext()
- func (s *Suite) TestDestroyKey()
- func (s *Suite) TestFields()
- func (s *Suite) TestFilters()
- func (s *Suite) TestGetKey()
- func (s *Suite) TestInvalidRequests()
- func (s *Suite) TestKeyInfo()
- func (s *Suite) TestKeyNotFound()
- func (s *Suite) TestNotSupported()
- func (s *Suite) TestPageToken()
- func (s *Suite) TestPaging()
- func (s *Suite) TestSignContext()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// New returns the provider, which must implement cryptoprov.KeyManager.
// The suite calls it once. The store may hold other keys and may be
// changed by other tests while the suite runs.
New func(t *testing.T) cryptoprov.Provider
// Tags reports that keys can be tagged and filtered by tag. Without it
// the suite asserts cryptoprov.ErrNotSupported for both.
Tags bool
// Encrypt reports that RSA encryption keys can be generated. Without it
// the suite asserts cryptoprov.ErrNotSupported.
Encrypt bool
// MLDSA reports that ML-DSA keys can be generated.
MLDSA bool
// DestroyRemoves reports that DestroyKey removes a key at once, so that
// it is not found afterwards. Otherwise the key stays, in a state other
// than enabled.
DestroyRemoves bool
// PagingByLabel makes the paging test give its keys one label and list
// them by that exact label instead of by a label prefix. It is for a
// provider whose page token is an offset in the order of the keys that
// pass the backend's own filter, in a store other tests change: only
// the exact label keeps that order to the suite's keys.
PagingByLabel bool
// ListedID returns the KeyInfo.ID a listing has for the key that
// IdentifyKey names keyID; nil when they are the same. Google Cloud KMS
// lists the key and identifies a signer by its version.
ListedID func(keyID string) string
}
Config describes the provider under test and what its backend can do.
type Suite ¶
Suite is the conformance suite; use Run.
func (*Suite) SetupSuite ¶
func (s *Suite) SetupSuite()
SetupSuite creates the provider and the keys of the run.
func (*Suite) TearDownSuite ¶
func (s *Suite) TearDownSuite()
TearDownSuite destroys the keys of the run.
func (*Suite) TestCancelledContext ¶
func (s *Suite) TestCancelledContext()
TestCancelledContext checks that a call with a cancelled context fails with its error and does not create a key.
func (*Suite) TestDestroyKey ¶
func (s *Suite) TestDestroyKey()
TestDestroyKey checks that a destroyed key is gone, or is no longer enabled on a backend that defers the destruction.
func (*Suite) TestFields ¶
func (s *Suite) TestFields()
TestFields checks that a listing fills the groups its field mask selects.
func (*Suite) TestFilters ¶
func (s *Suite) TestFilters()
TestFilters checks every filter condition against the keys of the run.
func (*Suite) TestGetKey ¶
func (s *Suite) TestGetKey()
TestGetKey checks that a key is loaded by its ID and exported in a form that names it.
func (*Suite) TestInvalidRequests ¶
func (s *Suite) TestInvalidRequests()
TestInvalidRequests checks the requests no provider accepts.
func (*Suite) TestKeyInfo ¶
func (s *Suite) TestKeyInfo()
TestKeyInfo checks the description of every key, with and without its public key.
func (*Suite) TestKeyNotFound ¶
func (s *Suite) TestKeyNotFound()
TestKeyNotFound checks the error for a key the provider does not have.
func (*Suite) TestNotSupported ¶
func (s *Suite) TestNotSupported()
TestNotSupported checks that what the backend cannot do is an error, not an empty result or a key of another kind.
func (*Suite) TestPageToken ¶
func (s *Suite) TestPageToken()
TestPageToken checks that a page token is opaque state of one listing: it is rejected with another filter, another field mask, or when it is not a token.
func (*Suite) TestPaging ¶
func (s *Suite) TestPaging()
TestPaging checks that a full listing returns every key once at every page size, by pages and through AllKeys.
func (*Suite) TestSignContext ¶ added in v2.0.328
func (s *Suite) TestSignContext()
TestSignContext checks that every signing key is a cryptoprov.ContextSigner that signs under a live context, through BindContext as x509 calls it, and fails with a cancelled one; and that an encryption key is a cryptoprov.ContextDecrypter that does the same.