Documentation ¶
Index ¶
- Variables
- func ResetCard(card *iso.Card) error
- func WithCard(t *testing.T, flt filter.Filter, cb func(t *testing.T, card *iso.Card))
- type MockCard
- func (c *MockCard) Base() iso.PCSCCard
- func (c *MockCard) BeginTransaction() error
- func (c *MockCard) Close() error
- func (c *MockCard) EndTransaction() error
- func (c *MockCard) LoadTranscript() error
- func (c *MockCard) Transmit(cmd []byte) (resp []byte, err error)
- func (c *MockCard) WriteTranscript() error
- type TraceCard
Constants ¶
This section is empty.
Variables ¶
var ( ErrFailedToGetCard = errors.New("failed to get physical card") ErrCardNotResettable = errors.New("card not resettable") )
var DangerousWipeRealCard = os.Getenv("TEST_DANGEROUS_WIPE_REAL_CARD") != ""
DangerousWipeRealCard is a global flag which should be used to safe guard any real smart cards from being accidentally wiped. nolint: gochecknoglobals
var ErrMalformedMockfile = fmt.Errorf("invalid mockfile")
Functions ¶
func WithCard ¶
WithCard opens the first card matching the filter flt and wraps it with the TraceCard and MockCard wrappers to trace commands for debugging as well as record a transcript of commands exchanged during the test. Finally the provided test callback is invoked. The user is expected to implement any test code within the provided callback. Thanks to wrapping the card into a mock object, tests can also be executed without the presence of a real card (e.g. in a CI environment). In this case, previously recorded command transcripts are used to emulate & assert the communication with the card.
Types ¶
type MockCard ¶
MockCard is a wrapper around iso.PCSCCard which reads/writes transcripts of the commands (APDUs) from a file to emulate a real smart card with a mock object.
func NewMockCard ¶
NewMockCard creates a new smart card mock.
If realCard is nil, we attempt to load a transcript of the expected commands from a transcript file at: `mockdata/t.Name()`.
If realCard is not nil, all exchanged commands will be recorded and written the the transcript file above during Close().
func (*MockCard) Base ¶ added in v0.6.0
Base returns the underlying smart card. We need to overload this as c.PCSCard can be nil
func (*MockCard) BeginTransaction ¶
func (*MockCard) Close ¶
Close invokes WriteTranscript() in case a real-card was passed to NewMockCard().
func (*MockCard) EndTransaction ¶
func (*MockCard) LoadTranscript ¶
LoadTranscript loads the a command transcript from `mockdata/t.Name()` and configures the mock object with the expected calls to Transmit(), BeginTransaction() and EndTransaction().
func (*MockCard) WriteTranscript ¶
WriteTranscript writes recorded commands exchanged with a real card to the transcript file at `mockdata/t.Name()`.
type TraceCard ¶
TraceCard is a wrapper around iso7816.PCSCCard which logs a exchanged commands (APDUs) to a log/slog logger.
func NewTraceCard ¶
NewTraceCard wraps a iso7816.PCSCCard into a TraceCard which logs a exchanged commands (APDUs) to a log/slog logger.