fdotest

package
v0.0.0-...-283a50a Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Overview

Package fdotest contains test harnesses for the main fdo package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ModuleNameOnlyRoutines

func ModuleNameOnlyRoutines(moduleName string) func() (func(context.Context, io.Writer) error, func(context.Context, io.Reader) error)

ModuleNameOnlyRoutines creates routines that only respond to module name commands.

func RunClientTestSuite

func RunClientTestSuite(t *testing.T, conf Config)

RunClientTestSuite is used to test different implementations of server state methods at an almost end-to-end level (transport is mocked).

func RunServerStateSuite

func RunServerStateSuite(t *testing.T, state AllServerState)

RunServerStateSuite is used to test different implementations of all server state methods.

func TestingLog

func TestingLog(t *testing.T) io.Writer

TestingLog creates a testing logger.

Types

type AllServerState

AllServerState includes all server state interfaces and additional functions needed for testing.

type Config

type Config struct {
	// If state is nil, then an in-memory implementation will be used. This is
	// useful for only testing service info modules.
	State AllServerState

	// If NewCredential is non-nil, then it will be used to create and format
	// the device credential. Otherwise the blob package will be used.
	NewCredential func(protocol.KeyType) (hmacSha256, hmacSha384 hash.Hash, key crypto.Signer, toDeviceCred func(fdo.DeviceCredential) any)

	// If NewTransport is non-nil, then it will be used in place of
	// fdo.Transport.
	NewTransport func(t *testing.T, tokens protocol.TokenService, di, to0, to1, to2 protocol.Responder) fdo.Transport

	// Use the Credential Reuse Protocol
	Reuse bool

	// If true, set the log level to info
	NoDebug bool

	// If DeviceModules is non-nil, then they will be reported as supported in
	// devmod and called if any owner modules are executed.
	DeviceModules map[string]serviceinfo.DeviceModule

	// If OwnerModules is non-nil, then it will be used to initialize owner
	// module state and owner services will be executed in order for each
	// module supported by the device (as reported in devmod).
	OwnerModules func(ctx context.Context, replacementGUID protocol.GUID, info string, chain []*x509.Certificate, devmod serviceinfo.Devmod, supportedMods []string) iter.Seq2[string, serviceinfo.OwnerModule]

	// If CustomExpect is non-nil, then it is used to validate the result of
	// TO2 with modules enabled
	CustomExpect func(*testing.T, error)
}

Config provides options to modify how the test suite runs.

type MockDeviceModule

type MockDeviceModule struct {
	ActiveState    bool
	TransitionFunc func(active bool) error
	ReceiveFunc    func(ctx context.Context, messageName string, messageBody io.Reader, respond func(message string) io.Writer, yield func()) error
	YieldFunc      func(ctx context.Context, respond func(message string) io.Writer, yield func()) error
}

MockDeviceModule implements a trivial serviceinfo.DeviceModule.

func (*MockDeviceModule) Receive

func (m *MockDeviceModule) Receive(ctx context.Context, messageName string, messageBody io.Reader, respond func(message string) io.Writer, yield func()) error

Receive implements serviceinfo.DeviceModule.

func (*MockDeviceModule) Transition

func (m *MockDeviceModule) Transition(active bool) error

Transition implements serviceinfo.DeviceModule.

func (*MockDeviceModule) Yield

func (m *MockDeviceModule) Yield(ctx context.Context, respond func(message string) io.Writer, yield func()) error

Yield implements serviceinfo.DeviceModule.

type MockOwnerModule

type MockOwnerModule struct {
	HandleInfoFunc  func(ctx context.Context, messageName string, messageBody io.Reader) error
	ProduceInfoFunc func(ctx context.Context, producer *serviceinfo.Producer) (blockPeer, moduleDone bool, _ error)
}

MockOwnerModule implements a trivial serviceinfo.OwnerModule.

func (*MockOwnerModule) HandleInfo

func (m *MockOwnerModule) HandleInfo(ctx context.Context, messageName string, messageBody io.Reader) error

HandleInfo implements serviceinfo.OwnerModule.

func (*MockOwnerModule) ProduceInfo

func (m *MockOwnerModule) ProduceInfo(ctx context.Context, producer *serviceinfo.Producer) (blockPeer, moduleDone bool, _ error)

ProduceInfo implements serviceinfo.OwnerModule.

type MockPlugin

type MockPlugin struct {
	Routines         func() (func(context.Context, io.Writer) error, func(context.Context, io.Reader) error)
	Stopped          chan struct{}
	GracefulStopped  chan struct{}
	GracefulStopFunc func(context.Context) error
	// contains filtered or unexported fields
}

MockPlugin implements a trivial plugin.Module.

func (*MockPlugin) GracefulStop

func (m *MockPlugin) GracefulStop(ctx context.Context) error

GracefulStop implements plugin.Module.

func (*MockPlugin) Start

func (m *MockPlugin) Start() (io.Writer, io.Reader, error)

Start implements plugin.Module.

func (*MockPlugin) Stop

func (m *MockPlugin) Stop() error

Stop implements plugin.Module.

type Transport

type Transport struct {
	T *testing.T

	Tokens protocol.TokenService

	DIResponder  *fdo.DIServer[custom.DeviceMfgInfo]
	TO0Responder *fdo.TO0Server
	TO1Responder *fdo.TO1Server
	TO2Responder *fdo.TO2Server
	// contains filtered or unexported fields
}

Transport for tests, directly calling the server's responder. No encryption is used, but key exchange is still performed.

func (*Transport) Send

func (t *Transport) Send(ctx context.Context, msgType uint8, msg any, sess kex.Session) (uint8, io.ReadCloser, error)

Send implements fdo.Transport.

Directories

Path Synopsis
Package internal includes internal test helpers.
Package internal includes internal test helpers.
memory
Package memory implements server state using non-persistent memory to complement internal/token.Service for state that must persist between protocol sessions.
Package memory implements server state using non-persistent memory to complement internal/token.Service for state that must persist between protocol sessions.
token
Package token implements all server state interfaces possible using a stateless token.
Package token implements all server state interfaces possible using a stateless token.

Jump to

Keyboard shortcuts

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