2022-01-18 16:44:58 +01:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2024-01-22 12:20:24 +01:00
|
|
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2023-07-27 11:31:07 +02:00
|
|
|
GetPKCEAuthorizationFlowFunc func(serverKey wgtypes.Key) (*proto.PKCEAuthorizationFlow, error)
|
2022-01-18 16:44:58 +01:00
|
|
|
}
|
|
|
|
|
2024-01-22 12:20:24 +01:00
|
|
|
func (m *MockClient) IsHealthy() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-07-27 11:31:07 +02:00
|
|
|
func (m *MockClient) GetPKCEAuthorizationFlow(serverKey wgtypes.Key) (*proto.PKCEAuthorizationFlow, error) {
|
|
|
|
if m.GetPKCEAuthorizationFlowFunc == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return m.GetPKCEAuthorizationFlow(serverKey)
|
|
|
|
}
|
|
|
|
|
2023-06-12 14:43:55 +02:00
|
|
|
// GetNetworkMap mock implementation of GetNetworkMap from mgm.Client interface
|
|
|
|
func (m *MockClient) GetNetworkMap() (*proto.NetworkMap, error) {
|
2023-05-31 18:25:24 +02:00
|
|
|
return nil, nil
|
|
|
|
}
|