mock

package
v0.0.0-...-65cc632 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Overview

Package errors provides errors for use in tests.

Index

Constants

View Source
const (
	StatsStart         = iota
	StatsStop          = iota
	StatsNetworkChange = iota
)

Variables

View Source
var DefaultNameserversV4 config.DNS = []string{
	"103.86.96.100",
	"103.86.99.100",
}
View Source
var En0Interface = net.Interface{
	Index:        1,
	MTU:          5,
	Name:         "en0",
	HardwareAddr: []byte("00:00:5e:00:53:01"),
	Flags:        net.FlagMulticast,
}
View Source
var En1Interface = net.Interface{
	Index:        1,
	MTU:          5,
	Name:         "en1",
	HardwareAddr: []byte("00:00:5e:00:53:01"),
	Flags:        net.FlagMulticast,
}
View Source
var ErrOnPurpose = errors.New("on purpose")

ErrOnPurpose is used in unit tests.

View Source
var TplNameserversV4 config.DNS = []string{
	"103.86.96.96",
	"103.86.99.99",
}

Functions

func CreateSignature

func CreateSignature(privateKey *rsa.PrivateKey, data string) (string, error)

CreateSignature signs data with RSA-SHA256 and encodes signature with Base64

func GenerateKeyPair

func GenerateKeyPair() (*rsa.PrivateKey, ssh.PublicKey, error)

GenerateKeyPair generates a new RSA key pair

func GenerateValidHeaders

func GenerateValidHeaders(privateKey *rsa.PrivateKey, data []byte) (http.Header, error)

GenerateValidHeaders generates HTTP Response headers that will be accepted in client side

Types

type ActiveVPN

type ActiveVPN struct{}

ActiveVPN stub of a github.com/NordSecurity/nordvpn-linux/daemon/vpn.VPN interface.

func (ActiveVPN) GetConnectionParameters

func (ActiveVPN) GetConnectionParameters() (vpn.ServerData, bool)

func (ActiveVPN) IsActive

func (ActiveVPN) IsActive() bool

func (ActiveVPN) NetworkChanged

func (ActiveVPN) NetworkChanged() error

func (ActiveVPN) Start

func (ActiveVPN) State

func (ActiveVPN) State() vpn.State

func (ActiveVPN) Stop

func (ActiveVPN) Stop() error

func (ActiveVPN) Tun

func (ActiveVPN) Tun() tunnel.T

type AnalyticsConsentCheckerMock

type AnalyticsConsentCheckerMock struct {
	ConsentCompleted bool
}

func (*AnalyticsConsentCheckerMock) IsConsentFlowCompleted

func (c *AnalyticsConsentCheckerMock) IsConsentFlowCompleted() bool

func (*AnalyticsConsentCheckerMock) PrepareDaemonIfConsentNotCompleted

func (*AnalyticsConsentCheckerMock) PrepareDaemonIfConsentNotCompleted()

type CachingMapperMock

type CachingMapperMock struct {
	Value *mesh.MachineMap
	Error error
}

func (*CachingMapperMock) Map

func (m *CachingMapperMock) Map(_ string, _ uuid.UUID, _ bool) (*mesh.MachineMap, error)

type ConfigManager

type ConfigManager struct {
	Cfg           *config.Config
	SaveCallCount int
	SaveErr       error
	LoadErr       error
	Saved         bool
	// contains filtered or unexported fields
}

func NewMockConfigManager

func NewMockConfigManager() *ConfigManager

func (*ConfigManager) Load

func (m *ConfigManager) Load(c *config.Config) error

func (*ConfigManager) Reset

func (m *ConfigManager) Reset(bool, bool) error

func (*ConfigManager) SaveWith

func (m *ConfigManager) SaveWith(fn config.SaveFunc) error

type DNSGetter

type DNSGetter struct {
	RegisteredDomains RegisteredDomainsList
	Names             []string
}

func (*DNSGetter) Get

func (md *DNSGetter) Get(isThreatProtectionLite bool) []string

func (*DNSGetter) LookupIP

func (md *DNSGetter) LookupIP(host string) ([]net.IP, error)

type FailingVPN

type FailingVPN struct{}

FailingVPN stub of a github.com/NordSecurity/nordvpn-linux/daemon/vpn.VPN interface.

func (FailingVPN) GetConnectionParameters

func (FailingVPN) GetConnectionParameters() (vpn.ServerData, bool)

func (FailingVPN) IsActive

func (FailingVPN) IsActive() bool

func (FailingVPN) NetworkChanged

func (FailingVPN) NetworkChanged() error

func (FailingVPN) Start

func (FailingVPN) State

func (FailingVPN) State() vpn.State

func (FailingVPN) Stop

func (FailingVPN) Stop() error

func (FailingVPN) Tun

func (FailingVPN) Tun() tunnel.T

type HTTPError

type HTTPError struct {
	Code int
	Msg  string
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

type HTTPTestServer

type HTTPTestServer struct {
	// contains filtered or unexported fields
}

func NewHTTPTestServer

func NewHTTPTestServer(t *testing.T, handlers []Handler) *HTTPTestServer

func (*HTTPTestServer) Close

func (s *HTTPTestServer) Close()

func (*HTTPTestServer) Running

func (s *HTTPTestServer) Running() bool

func (*HTTPTestServer) Start

func (s *HTTPTestServer) Start()

func (*HTTPTestServer) URL

func (s *HTTPTestServer) URL() string

type Handler

type Handler struct {
	Pattern string
	Fn      func() ([]byte, *HTTPError)
}

func NewHandleWithFileContent

func NewHandleWithFileContent(pattern string, path string) Handler

func NewHandleWithResponse

func NewHandleWithResponse(pattern string, response string) Handler

type MeshnetAndVPN

type MeshnetAndVPN struct {
	WorkingVPN
	MeshEnableError error
}

func (*MeshnetAndVPN) Disable

func (*MeshnetAndVPN) Disable() error

func (*MeshnetAndVPN) Enable

func (w *MeshnetAndVPN) Enable(netip.Addr, string) error

func (*MeshnetAndVPN) Refresh

func (*MeshnetAndVPN) Refresh(mesh.MachineMap) error

func (*MeshnetAndVPN) StatusMap

func (*MeshnetAndVPN) StatusMap() (map[string]string, error)

type MockDaemonClient

type MockDaemonClient struct {
	pb.DaemonClient
	CitiesResponse    []*pb.ServerGroup
	GroupsResponse    []*pb.ServerGroup
	CountriesResponse []*pb.ServerGroup
	PingFn            func() (*pb.PingResponse, error)
}

func (MockDaemonClient) Cities

func (MockDaemonClient) Countries

func (c MockDaemonClient) Countries(ctx context.Context, in *pb.Empty, opts ...grpc.CallOption) (*pb.ServerGroupsList, error)

func (MockDaemonClient) Groups

func (c MockDaemonClient) Groups(ctx context.Context, in *pb.Empty, opts ...grpc.CallOption) (*pb.ServerGroupsList, error)

func (MockDaemonClient) Ping

func (c MockDaemonClient) Ping(ctx context.Context, in *pb.Empty, opts ...grpc.CallOption) (*pb.PingResponse, error)

type NotificationClientMock

type NotificationClientMock struct {
	StartError   error
	StopError    error
	RevokeStatus bool
}

func (*NotificationClientMock) Revoke

func (nc *NotificationClientMock) Revoke() bool

func (*NotificationClientMock) Start

func (nc *NotificationClientMock) Start() error

func (*NotificationClientMock) Stop

func (nc *NotificationClientMock) Stop() error

type RegisteredDomainsList

type RegisteredDomainsList map[string][]net.IP

type RegistrationCheckerMock

type RegistrationCheckerMock struct {
	// contains filtered or unexported fields
}

func (RegistrationCheckerMock) IsRegistrationInfoCorrect

func (r RegistrationCheckerMock) IsRegistrationInfoCorrect() bool

func (RegistrationCheckerMock) Register

func (r RegistrationCheckerMock) Register() error

type RegistryMock

type RegistryMock struct {
	CurrentMachine mesh.Machine
	Peers          mesh.MachinePeers
	LocalPeers     mesh.Machines

	MapErr       error
	ConfigureErr error
	UpdateErr    error
}

func (*RegistryMock) Configure

func (r *RegistryMock) Configure(token string, id uuid.UUID, peerID uuid.UUID, peer mesh.PeerUpdateRequest) error

func (*RegistryMock) GetPeerWithIdentifier

func (r *RegistryMock) GetPeerWithIdentifier(id string) *mesh.MachinePeer

func (*RegistryMock) Map

func (r *RegistryMock) Map(token string, self uuid.UUID, _ bool) (*mesh.MachineMap, error)

func (*RegistryMock) NotifyNewTransfer

func (*RegistryMock) NotifyNewTransfer(
	token string,
	self uuid.UUID,
	peer uuid.UUID,
	fileName string,
	fileCount int,
	transferID string,
) error

func (*RegistryMock) Register

func (*RegistryMock) Register(token string, self mesh.Machine) (*mesh.Machine, error)

func (*RegistryMock) Unpair

func (*RegistryMock) Unpair(token string, self uuid.UUID, peer uuid.UUID) error

func (*RegistryMock) Unregister

func (*RegistryMock) Unregister(token string, self uuid.UUID) error

func (*RegistryMock) Update

func (r *RegistryMock) Update(token string, id uuid.UUID, info mesh.MachineUpdateRequest) error

type RemoteConfigMock

type RemoteConfigMock struct {
	NordWhisperEnabled bool
	GetNordWhisperErr  error
}

func NewRemoteConfigMock

func NewRemoteConfigMock() *RemoteConfigMock

func (*RemoteConfigMock) GetFeatureParam

func (r *RemoteConfigMock) GetFeatureParam(_, _ string) (string, error)

func (*RemoteConfigMock) GetNordWhisperEnabled

func (r *RemoteConfigMock) GetNordWhisperEnabled() (bool, error)

func (*RemoteConfigMock) GetTelioConfig

func (r *RemoteConfigMock) GetTelioConfig() (string, error)

func (*RemoteConfigMock) IsFeatureEnabled

func (r *RemoteConfigMock) IsFeatureEnabled(string) bool

func (*RemoteConfigMock) LoadConfig

func (r *RemoteConfigMock) LoadConfig() error

type SysctlSetterMock

type SysctlSetterMock struct {
	IsSet    bool
	SetErr   error
	UnsetErr error
}

func (*SysctlSetterMock) Set

func (s *SysctlSetterMock) Set() error

func (*SysctlSetterMock) Unset

func (s *SysctlSetterMock) Unset() error

type WorkingInactiveVPN

type WorkingInactiveVPN struct{}

func (WorkingInactiveVPN) GetConnectionParameters

func (WorkingInactiveVPN) GetConnectionParameters() (vpn.ServerData, bool)

func (WorkingInactiveVPN) IsActive

func (WorkingInactiveVPN) IsActive() bool

func (WorkingInactiveVPN) NetworkChanged

func (WorkingInactiveVPN) NetworkChanged() error

func (WorkingInactiveVPN) Start

func (WorkingInactiveVPN) State

func (WorkingInactiveVPN) State() vpn.State

func (WorkingInactiveVPN) Stop

func (WorkingInactiveVPN) Stop() error

func (WorkingInactiveVPN) Tun

func (WorkingInactiveVPN) Tun() tunnel.T

type WorkingT

type WorkingT struct{}

WorkingT stub of a github.com/NordSecurity/nordvpn-linux/tunnel.T interface.

func (WorkingT) AddAddrs

func (WorkingT) AddAddrs() error

func (WorkingT) DelAddrs

func (WorkingT) DelAddrs() error

func (WorkingT) IP

func (WorkingT) IP() (netip.Addr, bool)

func (WorkingT) Interface

func (WorkingT) Interface() net.Interface

func (WorkingT) TransferRates

func (WorkingT) TransferRates() (tunnel.Statistics, error)

type WorkingVPN

type WorkingVPN struct {
	StartErr          error
	ErrNetworkChanges error
	ExecutionStats    [statsLastValue]int
	// contains filtered or unexported fields
}

WorkingVPN stub of a github.com/NordSecurity/nordvpn-linux/daemon/vpn.VPN interface.

func (*WorkingVPN) GetConnectionParameters

func (w *WorkingVPN) GetConnectionParameters() (vpn.ServerData, bool)

func (*WorkingVPN) IsActive

func (w *WorkingVPN) IsActive() bool

func (*WorkingVPN) NetworkChanged

func (w *WorkingVPN) NetworkChanged() error

func (*WorkingVPN) Start

func (*WorkingVPN) State

func (w *WorkingVPN) State() vpn.State

func (*WorkingVPN) Stop

func (w *WorkingVPN) Stop() error

func (*WorkingVPN) Tun

func (*WorkingVPN) Tun() tunnel.T

Directories

Path Synopsis
norduser

Jump to

Keyboard shortcuts

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