Documentation ¶
Overview ¶
Package vpntest provides utitities to facilitate testing different minivpn packages.
Package vpntest provides utilities for minivpn testing.
Index ¶
- func AssertPanic(t *testing.T, f func())
- type Addr
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(b []byte) (int, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(b []byte) (int, error)
- type Dialer
- type EchoServer
- type LoggedPacket
- type PacketLog
- type PacketReader
- func (pr *PacketReader) Log() PacketLog
- func (pr *PacketReader) Payload() string
- func (pr *PacketReader) WaitForNumberOfACKs(total int, start time.Time)
- func (pr *PacketReader) WaitForOrderedPayloadLen(total int, start time.Time)
- func (pr *PacketReader) WaitForSequence(seq []int, start time.Time) bool
- type PacketRelay
- type PacketWriter
- type TestPacket
- type TestingCert
- type Witness
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertPanic ¶
Types ¶
type Conn ¶
type Conn struct { MockRead func(b []byte) (int, error) MockWrite func(b []byte) (int, error) MockClose func() error MockLocalAddr func() net.Addr MockRemoteAddr func() net.Addr MockSetDeadline func(t time.Time) error MockSetReadDeadline func(t time.Time) error MockSetWriteDeadline func(t time.Time) error }
Conn is a mockable net.Conn.
func (*Conn) SetDeadline ¶
SetDeadline calls MockSetDeadline.
func (*Conn) SetReadDeadline ¶
SetReadDeadline calls MockSetReadDeadline.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline calls MockSetWriteDeadline.
type Dialer ¶
type Dialer struct {
MockDialContext func(ctx context.Context, network, address string) (net.Conn, error)
}
Dialer is a mockable Dialer.
type EchoServer ¶
type EchoServer struct { // LocalSessionID is needed to produce incoming packets that pass sanity checks. LocalSessionID model.SessionID // RemoteSessionID is needed to produce ACKs. RemoteSessionID model.SessionID // contains filtered or unexported fields }
EchoServer is a dummy server intended for testing. It will: - send sequential packets back to a client implementation, containing each the same payload and the same packet ID than incoming. - write every seen packet on the ACK array for the echo response.
func NewEchoServer ¶
func NewEchoServer(dataIn, dataOut chan *model.Packet) *EchoServer
NewEchoServer creates an EchoServer given two channels of [model.Packet]s.
type LoggedPacket ¶
LoggedPacket is a trace of a received packet.
type PacketLog ¶
type PacketLog []*LoggedPacket
PacketLog is a sequence of LoggedPacket.
func (PacketLog) ACKs ¶
ACKs filters the log and returns an array of unique ids that have been acked either as ack packets or as part of the ack array of an outgoing packet.
func (PacketLog) IDSequence ¶
IDSequence returns a sequence of int from the logged packets.
type PacketReader ¶
type PacketReader struct {
// contains filtered or unexported fields
}
PacketReader reads packets from a channel.
func NewPacketReader ¶
func NewPacketReader(ch <-chan *model.Packet) *PacketReader
NewPacketReader creates a new PacketReader.
func (*PacketReader) Log ¶
func (pr *PacketReader) Log() PacketLog
Log returns the log of the received packets.
func (*PacketReader) Payload ¶
func (pr *PacketReader) Payload() string
Payload returns the string payload constructed from the payloads in the received packets.
func (*PacketReader) WaitForNumberOfACKs ¶
func (pr *PacketReader) WaitForNumberOfACKs(total int, start time.Time)
WaitForNumberOfACKs will read from the channel until the given number of acks have been received.
func (*PacketReader) WaitForOrderedPayloadLen ¶
func (pr *PacketReader) WaitForOrderedPayloadLen(total int, start time.Time)
WaitForOrderedPayloadLen will read from the channel until the given number of characters have been read.
func (*PacketReader) WaitForSequence ¶
func (pr *PacketReader) WaitForSequence(seq []int, start time.Time) bool
WaitForSequence loops reading from the internal channel until the logged sequence matches the len of the expected sequence; it returns true if the obtained packet ID sequence matches the expected one.
type PacketRelay ¶
type PacketRelay struct {
// contains filtered or unexported fields
}
PacketRelay sends any received packet, without modifications.
func NewPacketRelay ¶
func NewPacketRelay(dataIn <-chan *model.Packet, dataOut chan<- *model.Packet) *PacketRelay
NewPacketRelay reads packets from one channel and writes them to another.
func (*PacketRelay) RelayWithLosses ¶
func (pr *PacketRelay) RelayWithLosses(losses []int)
RelayWithLosses will relay incoming packets according to a vector of packetID that must be dropped. To specify repeated losses for a packet ID, the vector of losses must repeat the id several times.
type PacketWriter ¶
type PacketWriter struct { // LocalSessionID is needed to produce incoming packets that pass sanity checks. LocalSessionID model.SessionID // RemoteSessionID is needed to produce ACKs. RemoteSessionID model.SessionID // contains filtered or unexported fields }
PacketWriter writes packets into a channel.
func NewPacketWriter ¶
func NewPacketWriter(ch chan<- *model.Packet) *PacketWriter
NewPacketWriter creates a new PacketWriter.
func (*PacketWriter) WritePacketWithID ¶
func (pw *PacketWriter) WritePacketWithID(i int)
WritePacketWithID writes a dummy control packet with the passed ID.
func (*PacketWriter) WriteSequence ¶
func (pw *PacketWriter) WriteSequence(seq []string)
WriteSequence writes the passed packet sequence (in their string representation) to the configured channel. It will wait the specified interval between one packet and the next. The input sequence strings will be expanded for range notation, as in [1..10]
func (*PacketWriter) WriteSequenceWithFixedPayload ¶
func (pw *PacketWriter) WriteSequenceWithFixedPayload(seq []string, payload string, size int)
WriteSequenceWithFixedPayload will write packets according to the sequence specified in seq, but will sequentially pick the payload from the passed payload string, in increments defined by size.
type TestPacket ¶
type TestPacket struct { // Opcode is the OpenVPN packet opcode. Opcode model.Opcode // ID is the packet sequence ID int // ACKs is the ack array in this packet ACKs []int // IAT is the inter-arrival time until the next packet is received. IAT time.Duration }
TestPacket is used to simulate incoming packets over the network. The goal is to be able to have a compact representation of a sequence of packets, their type, and extra properties like inter-arrival time.
func NewTestPacketFromString ¶
func NewTestPacketFromString(s string) (*TestPacket, error)
NewTestPacketFromString constructs a new TestPacket. The input representation for the test packet string is in the form: "[ID] OPCODE (ack:) +42ms" where the ack array is optional.
type TestingCert ¶
TestingCert holds key, cert and ca to pass to tests needing to mock certificates.
func WriteTestingCerts ¶
func WriteTestingCerts(dir string) (TestingCert, error)
WriteTEestingCerts will write valid certificates in the passed dir, and return a TestingCert and any error.
type Witness ¶
type Witness struct {
// contains filtered or unexported fields
}
A Witness checks for different conditions over a reader
func NewWitness ¶
func NewWitness(r *PacketReader) *Witness
NewWitness constructs a Witness from a PacketReader.
func NewWitnessFromChannel ¶
NewWitnessFromChannel constructs a Witness from a channel of packets.
func (*Witness) Payload ¶
Payload returns the string payload reconstructed from the received packets.
func (*Witness) VerifyNumberOfACKs ¶
VerifyNumberOfACKs tells the underlying reader to wait for a given number of acks, returns true if we have the same number of acks.