2022-01-18 16:44:58 +01:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2022-03-26 12:08:54 +01:00
|
|
|
"github.com/netbirdio/netbird/client/system"
|
|
|
|
"github.com/netbirdio/netbird/management/proto"
|
2022-01-18 16:44:58 +01:00
|
|
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MockClient struct {
|
2022-05-08 11:04:57 +02:00
|
|
|
CloseFunc func() error
|
|
|
|
SyncFunc func(msgHandler func(msg *proto.SyncResponse) error) error
|
|
|
|
GetServerPublicKeyFunc func() (*wgtypes.Key, error)
|
2022-06-23 17:04:53 +02:00
|
|
|
RegisterFunc func(serverKey wgtypes.Key, setupKey string, jwtToken string, info *system.Info, sshKey []byte) (*proto.LoginResponse, error)
|
|
|
|
LoginFunc func(serverKey wgtypes.Key, info *system.Info, sshKey []byte) (*proto.LoginResponse, error)
|
2022-05-08 11:04:57 +02:00
|
|
|
GetDeviceAuthorizationFlowFunc func(serverKey wgtypes.Key) (*proto.DeviceAuthorizationFlow, error)
|
2022-01-18 16:44:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockClient) Close() error {
|
|
|
|
if m.CloseFunc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return m.CloseFunc()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockClient) Sync(msgHandler func(msg *proto.SyncResponse) error) error {
|
|
|
|
if m.SyncFunc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return m.SyncFunc(msgHandler)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockClient) GetServerPublicKey() (*wgtypes.Key, error) {
|
|
|
|
if m.GetServerPublicKeyFunc == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return m.GetServerPublicKeyFunc()
|
|
|
|
}
|
|
|
|
|
2022-06-23 17:04:53 +02:00
|
|
|
func (m *MockClient) Register(serverKey wgtypes.Key, setupKey string, jwtToken string, info *system.Info, sshKey []byte) (*proto.LoginResponse, error) {
|
2022-01-18 16:44:58 +01:00
|
|
|
if m.RegisterFunc == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return m.RegisterFunc(serverKey, setupKey, jwtToken, info, sshKey)
|
2022-01-18 16:44:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-23 17:04:53 +02:00
|
|
|
func (m *MockClient) Login(serverKey wgtypes.Key, info *system.Info, sshKey []byte) (*proto.LoginResponse, error) {
|
2022-01-18 16:44:58 +01:00
|
|
|
if m.LoginFunc == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return m.LoginFunc(serverKey, info, sshKey)
|
2022-01-18 16:44:58 +01:00
|
|
|
}
|
2022-05-08 11:04:57 +02:00
|
|
|
|
|
|
|
func (m *MockClient) GetDeviceAuthorizationFlow(serverKey wgtypes.Key) (*proto.DeviceAuthorizationFlow, error) {
|
|
|
|
if m.GetDeviceAuthorizationFlowFunc == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return m.GetDeviceAuthorizationFlowFunc(serverKey)
|
|
|
|
}
|
2023-05-31 18:25:24 +02:00
|
|
|
|
|
|
|
// GetRoutes mock implementation of GetRoutes from mgm.Client interface
|
|
|
|
func (m *MockClient) GetRoutes() ([]*proto.Route, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|