2022-02-22 18:18:05 +01:00
|
|
|
package mock_server
|
|
|
|
|
|
|
|
import (
|
2023-02-28 15:01:24 +01:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
|
2022-09-30 13:47:11 +02:00
|
|
|
nbdns "github.com/netbirdio/netbird/dns"
|
2022-03-26 12:08:54 +01:00
|
|
|
"github.com/netbirdio/netbird/management/server"
|
2023-01-02 15:11:32 +01:00
|
|
|
"github.com/netbirdio/netbird/management/server/activity"
|
2022-03-26 12:08:54 +01:00
|
|
|
"github.com/netbirdio/netbird/management/server/jwtclaims"
|
2022-08-18 18:22:15 +02:00
|
|
|
"github.com/netbirdio/netbird/route"
|
2022-02-22 18:18:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type MockAccountManager struct {
|
2023-01-02 15:11:32 +01:00
|
|
|
GetOrCreateAccountByUserFunc func(userId, domain string) (*server.Account, error)
|
|
|
|
CreateSetupKeyFunc func(accountId string, keyName string, keyType server.SetupKeyType,
|
|
|
|
expiresIn time.Duration, autoGroups []string, usageLimit int, userID string) (*server.SetupKey, error)
|
2022-11-05 10:24:50 +01:00
|
|
|
GetSetupKeyFunc func(accountID, userID, keyID string) (*server.SetupKey, error)
|
2022-10-13 18:26:31 +02:00
|
|
|
GetAccountByUserOrAccountIdFunc func(userId, accountId, domain string) (*server.Account, error)
|
2023-05-11 18:09:36 +02:00
|
|
|
GetUserFunc func(claims jwtclaims.AuthorizationClaims) (*server.User, error)
|
2022-10-13 18:26:31 +02:00
|
|
|
AccountExistsFunc func(accountId string) (*bool, error)
|
2023-02-07 20:11:08 +01:00
|
|
|
GetPeerByKeyFunc func(peerKey string) (*server.Peer, error)
|
2022-11-05 10:24:50 +01:00
|
|
|
GetPeersFunc func(accountID, userID string) ([]*server.Peer, error)
|
2022-10-13 18:26:31 +02:00
|
|
|
MarkPeerConnectedFunc func(peerKey string, connected bool) error
|
2023-01-02 15:11:32 +01:00
|
|
|
DeletePeerFunc func(accountID, peerKey, userID string) (*server.Peer, error)
|
2022-10-13 18:26:31 +02:00
|
|
|
GetPeerByIPFunc func(accountId string, peerIP string) (*server.Peer, error)
|
|
|
|
GetNetworkMapFunc func(peerKey string) (*server.NetworkMap, error)
|
|
|
|
GetPeerNetworkFunc func(peerKey string) (*server.Network, error)
|
2023-03-03 18:35:38 +01:00
|
|
|
AddPeerFunc func(setupKey string, userId string, peer *server.Peer) (*server.Peer, *server.NetworkMap, error)
|
2022-10-13 18:26:31 +02:00
|
|
|
GetGroupFunc func(accountID, groupID string) (*server.Group, error)
|
2023-01-02 15:11:32 +01:00
|
|
|
SaveGroupFunc func(accountID, userID string, group *server.Group) error
|
2022-10-13 18:26:31 +02:00
|
|
|
UpdateGroupFunc func(accountID string, groupID string, operations []server.GroupUpdateOperation) (*server.Group, error)
|
|
|
|
DeleteGroupFunc func(accountID, groupID string) error
|
|
|
|
ListGroupsFunc func(accountID string) ([]*server.Group, error)
|
|
|
|
GroupAddPeerFunc func(accountID, groupID, peerKey string) error
|
|
|
|
GroupDeletePeerFunc func(accountID, groupID, peerKey string) error
|
|
|
|
GroupListPeersFunc func(accountID, groupID string) ([]*server.Peer, error)
|
2022-11-05 10:24:50 +01:00
|
|
|
GetRuleFunc func(accountID, ruleID, userID string) (*server.Rule, error)
|
2023-01-02 15:11:32 +01:00
|
|
|
SaveRuleFunc func(accountID, userID string, rule *server.Rule) error
|
|
|
|
DeleteRuleFunc func(accountID, ruleID, userID string) error
|
2022-11-05 10:24:50 +01:00
|
|
|
ListRulesFunc func(accountID, userID string) ([]*server.Rule, error)
|
2023-03-13 15:14:18 +01:00
|
|
|
GetPolicyFunc func(accountID, policyID, userID string) (*server.Policy, error)
|
|
|
|
SavePolicyFunc func(accountID, userID string, policy *server.Policy) error
|
|
|
|
DeletePolicyFunc func(accountID, policyID, userID string) error
|
|
|
|
ListPoliciesFunc func(accountID, userID string) ([]*server.Policy, error)
|
2022-11-05 10:24:50 +01:00
|
|
|
GetUsersFromAccountFunc func(accountID, userID string) ([]*server.UserInfo, error)
|
2023-03-29 15:25:44 +02:00
|
|
|
GetAccountFromPATFunc func(pat string) (*server.Account, *server.User, *server.PersonalAccessToken, error)
|
2023-03-30 10:54:09 +02:00
|
|
|
MarkPATUsedFunc func(pat string) error
|
2023-02-03 10:33:28 +01:00
|
|
|
UpdatePeerMetaFunc func(peerID string, meta server.PeerSystemMeta) error
|
|
|
|
UpdatePeerSSHKeyFunc func(peerID string, sshKey string) error
|
2023-01-25 16:29:59 +01:00
|
|
|
UpdatePeerFunc func(accountID, userID string, peer *server.Peer) (*server.Peer, error)
|
|
|
|
CreateRouteFunc func(accountID string, prefix, peer, description, netID string, masquerade bool, metric int, groups []string, enabled bool, userID string) (*route.Route, error)
|
2022-11-05 10:24:50 +01:00
|
|
|
GetRouteFunc func(accountID, routeID, userID string) (*route.Route, error)
|
2023-01-25 16:29:59 +01:00
|
|
|
SaveRouteFunc func(accountID, userID string, route *route.Route) error
|
2022-10-13 18:26:31 +02:00
|
|
|
UpdateRouteFunc func(accountID string, routeID string, operations []server.RouteUpdateOperation) (*route.Route, error)
|
2023-01-25 16:29:59 +01:00
|
|
|
DeleteRouteFunc func(accountID, routeID, userID string) error
|
2022-11-05 10:24:50 +01:00
|
|
|
ListRoutesFunc func(accountID, userID string) ([]*route.Route, error)
|
2023-01-02 15:11:32 +01:00
|
|
|
SaveSetupKeyFunc func(accountID string, key *server.SetupKey, userID string) (*server.SetupKey, error)
|
2022-11-05 10:24:50 +01:00
|
|
|
ListSetupKeysFunc func(accountID, userID string) ([]*server.SetupKey, error)
|
2023-01-02 15:11:32 +01:00
|
|
|
SaveUserFunc func(accountID, userID string, user *server.User) (*server.UserInfo, error)
|
2023-05-11 18:09:36 +02:00
|
|
|
DeleteUserFunc func(accountID string, initiatorUserID string, targetUserID string) error
|
|
|
|
CreatePATFunc func(accountID string, initiatorUserID string, targetUserId string, tokenName string, expiresIn int) (*server.PersonalAccessTokenGenerated, error)
|
|
|
|
DeletePATFunc func(accountID string, initiatorUserID string, targetUserId string, tokenID string) error
|
|
|
|
GetPATFunc func(accountID string, initiatorUserID string, targetUserId string, tokenID string) (*server.PersonalAccessToken, error)
|
|
|
|
GetAllPATsFunc func(accountID string, initiatorUserID string, targetUserId string) ([]*server.PersonalAccessToken, error)
|
2022-10-13 18:26:31 +02:00
|
|
|
GetNameServerGroupFunc func(accountID, nsGroupID string) (*nbdns.NameServerGroup, error)
|
2023-01-25 16:29:59 +01:00
|
|
|
CreateNameServerGroupFunc func(accountID string, name, description string, nameServerList []nbdns.NameServer, groups []string, primary bool, domains []string, enabled bool, userID string) (*nbdns.NameServerGroup, error)
|
|
|
|
SaveNameServerGroupFunc func(accountID, userID string, nsGroupToSave *nbdns.NameServerGroup) error
|
|
|
|
UpdateNameServerGroupFunc func(accountID, nsGroupID, userID string, operations []server.NameServerGroupUpdateOperation) (*nbdns.NameServerGroup, error)
|
|
|
|
DeleteNameServerGroupFunc func(accountID, nsGroupID, userID string) error
|
2022-10-13 18:26:31 +02:00
|
|
|
ListNameServerGroupsFunc func(accountID string) ([]*nbdns.NameServerGroup, error)
|
2023-01-02 15:11:32 +01:00
|
|
|
CreateUserFunc func(accountID, userID string, key *server.UserInfo) (*server.UserInfo, error)
|
2022-11-11 20:36:45 +01:00
|
|
|
GetAccountFromTokenFunc func(claims jwtclaims.AuthorizationClaims) (*server.Account, *server.User, error)
|
2022-11-21 11:14:42 +01:00
|
|
|
GetDNSDomainFunc func() string
|
2023-01-02 15:11:32 +01:00
|
|
|
GetEventsFunc func(accountID, userID string) ([]*activity.Event, error)
|
2023-02-07 20:11:08 +01:00
|
|
|
GetDNSSettingsFunc func(accountID, userID string) (*server.DNSSettings, error)
|
|
|
|
SaveDNSSettingsFunc func(accountID, userID string, dnsSettingsToSave *server.DNSSettings) error
|
|
|
|
GetPeerFunc func(accountID, peerID, userID string) (*server.Peer, error)
|
2023-02-16 12:00:41 +01:00
|
|
|
UpdateAccountSettingsFunc func(accountID, userID string, newSettings *server.Settings) (*server.Account, error)
|
2023-03-03 18:35:38 +01:00
|
|
|
LoginPeerFunc func(login server.PeerLogin) (*server.Peer, *server.NetworkMap, error)
|
|
|
|
SyncPeerFunc func(sync server.PeerSync) (*server.Peer, *server.NetworkMap, error)
|
2022-05-05 08:58:34 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// GetUsersFromAccount mock implementation of GetUsersFromAccount from server.AccountManager interface
|
2022-11-05 10:24:50 +01:00
|
|
|
func (am *MockAccountManager) GetUsersFromAccount(accountID string, userID string) ([]*server.UserInfo, error) {
|
2022-05-05 08:58:34 +02:00
|
|
|
if am.GetUsersFromAccountFunc != nil {
|
2022-11-05 10:24:50 +01:00
|
|
|
return am.GetUsersFromAccountFunc(accountID, userID)
|
2022-05-05 08:58:34 +02:00
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetUsersFromAccount is not implemented")
|
2022-05-03 16:02:51 +02:00
|
|
|
}
|
|
|
|
|
2022-11-07 12:10:56 +01:00
|
|
|
// DeletePeer mock implementation of DeletePeer from server.AccountManager interface
|
2023-02-03 10:33:28 +01:00
|
|
|
func (am *MockAccountManager) DeletePeer(accountID, peerID, userID string) (*server.Peer, error) {
|
2022-11-07 12:10:56 +01:00
|
|
|
if am.DeletePeerFunc != nil {
|
2023-02-03 10:33:28 +01:00
|
|
|
return am.DeletePeerFunc(accountID, peerID, userID)
|
2022-11-07 12:10:56 +01:00
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method DeletePeer is not implemented")
|
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// GetOrCreateAccountByUser mock implementation of GetOrCreateAccountByUser from server.AccountManager interface
|
2022-05-03 16:02:51 +02:00
|
|
|
func (am *MockAccountManager) GetOrCreateAccountByUser(
|
|
|
|
userId, domain string,
|
|
|
|
) (*server.Account, error) {
|
2022-02-22 18:18:05 +01:00
|
|
|
if am.GetOrCreateAccountByUserFunc != nil {
|
|
|
|
return am.GetOrCreateAccountByUserFunc(userId, domain)
|
|
|
|
}
|
2022-05-03 16:02:51 +02:00
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.Unimplemented,
|
2022-06-23 17:04:53 +02:00
|
|
|
"method GetOrCreateAccountByUser is not implemented",
|
2022-05-03 16:02:51 +02:00
|
|
|
)
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
|
|
|
|
2022-09-11 23:16:40 +02:00
|
|
|
// CreateSetupKey mock implementation of CreateSetupKey from server.AccountManager interface
|
|
|
|
func (am *MockAccountManager) CreateSetupKey(
|
2022-12-05 13:09:59 +01:00
|
|
|
accountID string,
|
2022-05-03 16:02:51 +02:00
|
|
|
keyName string,
|
|
|
|
keyType server.SetupKeyType,
|
2022-06-14 10:32:54 +02:00
|
|
|
expiresIn time.Duration,
|
2022-09-11 23:16:40 +02:00
|
|
|
autoGroups []string,
|
2022-12-05 13:09:59 +01:00
|
|
|
usageLimit int,
|
2023-01-02 15:11:32 +01:00
|
|
|
userID string,
|
2022-05-03 16:02:51 +02:00
|
|
|
) (*server.SetupKey, error) {
|
2022-09-11 23:16:40 +02:00
|
|
|
if am.CreateSetupKeyFunc != nil {
|
2023-01-02 15:11:32 +01:00
|
|
|
return am.CreateSetupKeyFunc(accountID, keyName, keyType, expiresIn, autoGroups, usageLimit, userID)
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
2022-09-11 23:16:40 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method CreateSetupKey is not implemented")
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
|
|
|
|
2022-11-11 20:36:45 +01:00
|
|
|
// GetAccountByUserOrAccountID mock implementation of GetAccountByUserOrAccountID from server.AccountManager interface
|
2022-11-07 17:52:23 +01:00
|
|
|
func (am *MockAccountManager) GetAccountByUserOrAccountID(
|
2022-05-03 16:02:51 +02:00
|
|
|
userId, accountId, domain string,
|
|
|
|
) (*server.Account, error) {
|
2022-02-22 18:18:05 +01:00
|
|
|
if am.GetAccountByUserOrAccountIdFunc != nil {
|
|
|
|
return am.GetAccountByUserOrAccountIdFunc(userId, accountId, domain)
|
|
|
|
}
|
2022-05-03 16:02:51 +02:00
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.Unimplemented,
|
2022-11-07 17:52:23 +01:00
|
|
|
"method GetAccountByUserOrAccountID is not implemented",
|
2022-05-03 16:02:51 +02:00
|
|
|
)
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// AccountExists mock implementation of AccountExists from server.AccountManager interface
|
2022-02-22 18:18:05 +01:00
|
|
|
func (am *MockAccountManager) AccountExists(accountId string) (*bool, error) {
|
|
|
|
if am.AccountExistsFunc != nil {
|
|
|
|
return am.AccountExistsFunc(accountId)
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method AccountExists is not implemented")
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
|
|
|
|
2023-02-07 20:11:08 +01:00
|
|
|
// GetPeerByKey mocks implementation of GetPeerByKey from server.AccountManager interface
|
2023-02-03 10:33:28 +01:00
|
|
|
func (am *MockAccountManager) GetPeerByKey(peerKey string) (*server.Peer, error) {
|
2023-02-07 20:11:08 +01:00
|
|
|
if am.GetPeerByKeyFunc != nil {
|
|
|
|
return am.GetPeerByKeyFunc(peerKey)
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
2023-02-03 10:33:28 +01:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPeerByKey is not implemented")
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// MarkPeerConnected mock implementation of MarkPeerConnected from server.AccountManager interface
|
2022-02-22 18:18:05 +01:00
|
|
|
func (am *MockAccountManager) MarkPeerConnected(peerKey string, connected bool) error {
|
|
|
|
if am.MarkPeerConnectedFunc != nil {
|
|
|
|
return am.MarkPeerConnectedFunc(peerKey, connected)
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return status.Errorf(codes.Unimplemented, "method MarkPeerConnected is not implemented")
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// GetPeerByIP mock implementation of GetPeerByIP from server.AccountManager interface
|
2022-02-22 18:18:05 +01:00
|
|
|
func (am *MockAccountManager) GetPeerByIP(accountId string, peerIP string) (*server.Peer, error) {
|
|
|
|
if am.GetPeerByIPFunc != nil {
|
|
|
|
return am.GetPeerByIPFunc(accountId, peerIP)
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPeerByIP is not implemented")
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
|
|
|
|
2023-03-16 16:44:05 +01:00
|
|
|
// GetAccountFromPAT mock implementation of GetAccountFromPAT from server.AccountManager interface
|
2023-03-29 15:25:44 +02:00
|
|
|
func (am *MockAccountManager) GetAccountFromPAT(pat string) (*server.Account, *server.User, *server.PersonalAccessToken, error) {
|
2023-03-16 16:44:05 +01:00
|
|
|
if am.GetAccountFromPATFunc != nil {
|
|
|
|
return am.GetAccountFromPATFunc(pat)
|
|
|
|
}
|
2023-03-29 15:25:44 +02:00
|
|
|
return nil, nil, nil, status.Errorf(codes.Unimplemented, "method GetAccountFromPAT is not implemented")
|
2023-03-16 16:44:05 +01:00
|
|
|
}
|
|
|
|
|
2023-03-30 10:54:09 +02:00
|
|
|
// MarkPATUsed mock implementation of MarkPATUsed from server.AccountManager interface
|
|
|
|
func (am *MockAccountManager) MarkPATUsed(pat string) error {
|
|
|
|
if am.MarkPATUsedFunc != nil {
|
|
|
|
return am.MarkPATUsedFunc(pat)
|
|
|
|
}
|
|
|
|
return status.Errorf(codes.Unimplemented, "method MarkPATUsed is not implemented")
|
|
|
|
}
|
|
|
|
|
2023-03-30 13:58:44 +02:00
|
|
|
// CreatePAT mock implementation of GetPAT from server.AccountManager interface
|
2023-05-11 18:09:36 +02:00
|
|
|
func (am *MockAccountManager) CreatePAT(accountID string, initiatorUserID string, targetUserID string, name string, expiresIn int) (*server.PersonalAccessTokenGenerated, error) {
|
2023-03-30 13:58:44 +02:00
|
|
|
if am.CreatePATFunc != nil {
|
2023-05-11 18:09:36 +02:00
|
|
|
return am.CreatePATFunc(accountID, initiatorUserID, targetUserID, name, expiresIn)
|
2023-03-20 16:38:17 +01:00
|
|
|
}
|
2023-03-30 13:58:44 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method CreatePAT is not implemented")
|
2023-03-20 16:38:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeletePAT mock implementation of DeletePAT from server.AccountManager interface
|
2023-05-11 18:09:36 +02:00
|
|
|
func (am *MockAccountManager) DeletePAT(accountID string, initiatorUserID string, targetUserID string, tokenID string) error {
|
2023-03-20 16:38:17 +01:00
|
|
|
if am.DeletePATFunc != nil {
|
2023-05-11 18:09:36 +02:00
|
|
|
return am.DeletePATFunc(accountID, initiatorUserID, targetUserID, tokenID)
|
2023-03-20 16:38:17 +01:00
|
|
|
}
|
|
|
|
return status.Errorf(codes.Unimplemented, "method DeletePAT is not implemented")
|
|
|
|
}
|
|
|
|
|
2023-03-30 13:58:44 +02:00
|
|
|
// GetPAT mock implementation of GetPAT from server.AccountManager interface
|
2023-05-11 18:09:36 +02:00
|
|
|
func (am *MockAccountManager) GetPAT(accountID string, initiatorUserID string, targetUserID string, tokenID string) (*server.PersonalAccessToken, error) {
|
2023-03-30 13:58:44 +02:00
|
|
|
if am.GetPATFunc != nil {
|
2023-05-11 18:09:36 +02:00
|
|
|
return am.GetPATFunc(accountID, initiatorUserID, targetUserID, tokenID)
|
2023-03-30 13:58:44 +02:00
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPAT is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAllPATs mock implementation of GetAllPATs from server.AccountManager interface
|
2023-05-11 18:09:36 +02:00
|
|
|
func (am *MockAccountManager) GetAllPATs(accountID string, initiatorUserID string, targetUserID string) ([]*server.PersonalAccessToken, error) {
|
2023-03-30 13:58:44 +02:00
|
|
|
if am.GetAllPATsFunc != nil {
|
2023-05-11 18:09:36 +02:00
|
|
|
return am.GetAllPATsFunc(accountID, initiatorUserID, targetUserID)
|
2023-03-30 13:58:44 +02:00
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAllPATs is not implemented")
|
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// GetNetworkMap mock implementation of GetNetworkMap from server.AccountManager interface
|
2022-02-22 18:18:05 +01:00
|
|
|
func (am *MockAccountManager) GetNetworkMap(peerKey string) (*server.NetworkMap, error) {
|
|
|
|
if am.GetNetworkMapFunc != nil {
|
|
|
|
return am.GetNetworkMapFunc(peerKey)
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetNetworkMap is not implemented")
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
|
|
|
|
2022-06-24 21:30:51 +02:00
|
|
|
// GetPeerNetwork mock implementation of GetPeerNetwork from server.AccountManager interface
|
|
|
|
func (am *MockAccountManager) GetPeerNetwork(peerKey string) (*server.Network, error) {
|
|
|
|
if am.GetPeerNetworkFunc != nil {
|
|
|
|
return am.GetPeerNetworkFunc(peerKey)
|
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPeerNetwork is not implemented")
|
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// AddPeer mock implementation of AddPeer from server.AccountManager interface
|
2022-05-25 18:26:50 +02:00
|
|
|
func (am *MockAccountManager) AddPeer(
|
|
|
|
setupKey string,
|
|
|
|
userId string,
|
|
|
|
peer *server.Peer,
|
2023-03-03 18:35:38 +01:00
|
|
|
) (*server.Peer, *server.NetworkMap, error) {
|
2022-02-22 18:18:05 +01:00
|
|
|
if am.AddPeerFunc != nil {
|
2022-05-05 20:02:15 +02:00
|
|
|
return am.AddPeerFunc(setupKey, userId, peer)
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
2023-03-03 18:35:38 +01:00
|
|
|
return nil, nil, status.Errorf(codes.Unimplemented, "method AddPeer is not implemented")
|
2022-02-22 18:18:05 +01:00
|
|
|
}
|
2022-05-03 16:02:51 +02:00
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// GetGroup mock implementation of GetGroup from server.AccountManager interface
|
2022-05-03 16:02:51 +02:00
|
|
|
func (am *MockAccountManager) GetGroup(accountID, groupID string) (*server.Group, error) {
|
|
|
|
if am.GetGroupFunc != nil {
|
|
|
|
return am.GetGroupFunc(accountID, groupID)
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetGroup is not implemented")
|
2022-05-03 16:02:51 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// SaveGroup mock implementation of SaveGroup from server.AccountManager interface
|
2023-01-02 15:11:32 +01:00
|
|
|
func (am *MockAccountManager) SaveGroup(accountID, userID string, group *server.Group) error {
|
2022-05-03 16:02:51 +02:00
|
|
|
if am.SaveGroupFunc != nil {
|
2023-01-02 15:11:32 +01:00
|
|
|
return am.SaveGroupFunc(accountID, userID, group)
|
2022-05-03 16:02:51 +02:00
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return status.Errorf(codes.Unimplemented, "method SaveGroup is not implemented")
|
2022-05-03 16:02:51 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// UpdateGroup mock implementation of UpdateGroup from server.AccountManager interface
|
|
|
|
func (am *MockAccountManager) UpdateGroup(accountID string, groupID string, operations []server.GroupUpdateOperation) (*server.Group, error) {
|
|
|
|
if am.UpdateGroupFunc != nil {
|
|
|
|
return am.UpdateGroupFunc(accountID, groupID, operations)
|
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method UpdateGroup not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteGroup mock implementation of DeleteGroup from server.AccountManager interface
|
2022-05-03 16:02:51 +02:00
|
|
|
func (am *MockAccountManager) DeleteGroup(accountID, groupID string) error {
|
|
|
|
if am.DeleteGroupFunc != nil {
|
|
|
|
return am.DeleteGroupFunc(accountID, groupID)
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return status.Errorf(codes.Unimplemented, "method DeleteGroup is not implemented")
|
2022-05-03 16:02:51 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// ListGroups mock implementation of ListGroups from server.AccountManager interface
|
2022-05-03 16:02:51 +02:00
|
|
|
func (am *MockAccountManager) ListGroups(accountID string) ([]*server.Group, error) {
|
|
|
|
if am.ListGroupsFunc != nil {
|
|
|
|
return am.ListGroupsFunc(accountID)
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method ListGroups is not implemented")
|
2022-05-03 16:02:51 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// GroupAddPeer mock implementation of GroupAddPeer from server.AccountManager interface
|
2022-05-03 16:02:51 +02:00
|
|
|
func (am *MockAccountManager) GroupAddPeer(accountID, groupID, peerKey string) error {
|
|
|
|
if am.GroupAddPeerFunc != nil {
|
|
|
|
return am.GroupAddPeerFunc(accountID, groupID, peerKey)
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return status.Errorf(codes.Unimplemented, "method GroupAddPeer is not implemented")
|
2022-05-03 16:02:51 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// GroupDeletePeer mock implementation of GroupDeletePeer from server.AccountManager interface
|
2022-05-03 16:02:51 +02:00
|
|
|
func (am *MockAccountManager) GroupDeletePeer(accountID, groupID, peerKey string) error {
|
|
|
|
if am.GroupDeletePeerFunc != nil {
|
|
|
|
return am.GroupDeletePeerFunc(accountID, groupID, peerKey)
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return status.Errorf(codes.Unimplemented, "method GroupDeletePeer is not implemented")
|
2022-05-03 16:02:51 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// GroupListPeers mock implementation of GroupListPeers from server.AccountManager interface
|
2022-05-03 16:02:51 +02:00
|
|
|
func (am *MockAccountManager) GroupListPeers(accountID, groupID string) ([]*server.Peer, error) {
|
|
|
|
if am.GroupListPeersFunc != nil {
|
|
|
|
return am.GroupListPeersFunc(accountID, groupID)
|
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GroupListPeers is not implemented")
|
2022-05-03 16:02:51 +02:00
|
|
|
}
|
2022-05-21 15:21:39 +02:00
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// GetRule mock implementation of GetRule from server.AccountManager interface
|
2022-11-05 10:24:50 +01:00
|
|
|
func (am *MockAccountManager) GetRule(accountID, ruleID, userID string) (*server.Rule, error) {
|
2022-05-21 15:21:39 +02:00
|
|
|
if am.GetRuleFunc != nil {
|
2022-11-05 10:24:50 +01:00
|
|
|
return am.GetRuleFunc(accountID, ruleID, userID)
|
2022-05-21 15:21:39 +02:00
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetRule is not implemented")
|
2022-05-21 15:21:39 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// SaveRule mock implementation of SaveRule from server.AccountManager interface
|
2023-01-02 15:11:32 +01:00
|
|
|
func (am *MockAccountManager) SaveRule(accountID, userID string, rule *server.Rule) error {
|
2022-05-21 15:21:39 +02:00
|
|
|
if am.SaveRuleFunc != nil {
|
2023-01-02 15:11:32 +01:00
|
|
|
return am.SaveRuleFunc(accountID, userID, rule)
|
2022-05-21 15:21:39 +02:00
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return status.Errorf(codes.Unimplemented, "method SaveRule is not implemented")
|
2022-05-21 15:21:39 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// DeleteRule mock implementation of DeleteRule from server.AccountManager interface
|
2023-01-02 15:11:32 +01:00
|
|
|
func (am *MockAccountManager) DeleteRule(accountID, ruleID, userID string) error {
|
2022-05-21 15:21:39 +02:00
|
|
|
if am.DeleteRuleFunc != nil {
|
2023-01-02 15:11:32 +01:00
|
|
|
return am.DeleteRuleFunc(accountID, ruleID, userID)
|
2022-05-21 15:21:39 +02:00
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return status.Errorf(codes.Unimplemented, "method DeleteRule is not implemented")
|
2022-05-21 15:21:39 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// ListRules mock implementation of ListRules from server.AccountManager interface
|
2022-11-05 10:24:50 +01:00
|
|
|
func (am *MockAccountManager) ListRules(accountID, userID string) ([]*server.Rule, error) {
|
2022-05-21 15:21:39 +02:00
|
|
|
if am.ListRulesFunc != nil {
|
2022-11-05 10:24:50 +01:00
|
|
|
return am.ListRulesFunc(accountID, userID)
|
2022-05-21 15:21:39 +02:00
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method ListRules is not implemented")
|
2022-05-21 15:21:39 +02:00
|
|
|
}
|
2022-05-23 13:03:57 +02:00
|
|
|
|
2023-03-13 15:14:18 +01:00
|
|
|
// GetPolicy mock implementation of GetPolicy from server.AccountManager interface
|
|
|
|
func (am *MockAccountManager) GetPolicy(accountID, policyID, userID string) (*server.Policy, error) {
|
|
|
|
if am.GetPolicyFunc != nil {
|
|
|
|
return am.GetPolicyFunc(accountID, policyID, userID)
|
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPolicy is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// SavePolicy mock implementation of SavePolicy from server.AccountManager interface
|
|
|
|
func (am *MockAccountManager) SavePolicy(accountID, userID string, policy *server.Policy) error {
|
|
|
|
if am.SavePolicyFunc != nil {
|
|
|
|
return am.SavePolicyFunc(accountID, userID, policy)
|
|
|
|
}
|
|
|
|
return status.Errorf(codes.Unimplemented, "method SavePolicy is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeletePolicy mock implementation of DeletePolicy from server.AccountManager interface
|
|
|
|
func (am *MockAccountManager) DeletePolicy(accountID, policyID, userID string) error {
|
|
|
|
if am.DeletePolicyFunc != nil {
|
|
|
|
return am.DeletePolicyFunc(accountID, policyID, userID)
|
|
|
|
}
|
|
|
|
return status.Errorf(codes.Unimplemented, "method DeletePolicy is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListPolicies mock implementation of ListPolicies from server.AccountManager interface
|
|
|
|
func (am *MockAccountManager) ListPolicies(accountID, userID string) ([]*server.Policy, error) {
|
|
|
|
if am.ListPoliciesFunc != nil {
|
|
|
|
return am.ListPoliciesFunc(accountID, userID)
|
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method ListPolicies is not implemented")
|
|
|
|
}
|
|
|
|
|
2022-06-14 10:32:54 +02:00
|
|
|
// UpdatePeerMeta mock implementation of UpdatePeerMeta from server.AccountManager interface
|
2023-02-03 10:33:28 +01:00
|
|
|
func (am *MockAccountManager) UpdatePeerMeta(peerID string, meta server.PeerSystemMeta) error {
|
2022-05-23 13:03:57 +02:00
|
|
|
if am.UpdatePeerMetaFunc != nil {
|
2023-02-03 10:33:28 +01:00
|
|
|
return am.UpdatePeerMetaFunc(peerID, meta)
|
2022-05-23 13:03:57 +02:00
|
|
|
}
|
2022-06-23 17:04:53 +02:00
|
|
|
return status.Errorf(codes.Unimplemented, "method UpdatePeerMetaFunc is not implemented")
|
2022-05-23 13:03:57 +02:00
|
|
|
}
|
2022-05-25 18:26:50 +02:00
|
|
|
|
2023-05-11 18:09:36 +02:00
|
|
|
// GetUser mock implementation of GetUser from server.AccountManager interface
|
|
|
|
func (am *MockAccountManager) GetUser(claims jwtclaims.AuthorizationClaims) (*server.User, error) {
|
|
|
|
if am.GetUserFunc != nil {
|
|
|
|
return am.GetUserFunc(claims)
|
2022-05-25 18:26:50 +02:00
|
|
|
}
|
2023-05-11 18:09:36 +02:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method IsUserGetUserAdmin is not implemented")
|
2022-06-23 17:04:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// UpdatePeerSSHKey mocks UpdatePeerSSHKey function of the account manager
|
2023-02-03 10:33:28 +01:00
|
|
|
func (am *MockAccountManager) UpdatePeerSSHKey(peerID string, sshKey string) error {
|
2022-06-23 17:04:53 +02:00
|
|
|
if am.UpdatePeerSSHKeyFunc != nil {
|
2023-02-03 10:33:28 +01:00
|
|
|
return am.UpdatePeerSSHKeyFunc(peerID, sshKey)
|
2022-06-23 17:04:53 +02:00
|
|
|
}
|
|
|
|
return status.Errorf(codes.Unimplemented, "method UpdatePeerSSHKey is is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdatePeer mocks UpdatePeerFunc function of the account manager
|
2023-01-25 16:29:59 +01:00
|
|
|
func (am *MockAccountManager) UpdatePeer(accountID, userID string, peer *server.Peer) (*server.Peer, error) {
|
2022-06-23 17:04:53 +02:00
|
|
|
if am.UpdatePeerFunc != nil {
|
2023-01-25 16:29:59 +01:00
|
|
|
return am.UpdatePeerFunc(accountID, userID, peer)
|
2022-06-23 17:04:53 +02:00
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method UpdatePeerFunc is is not implemented")
|
2022-05-25 18:26:50 +02:00
|
|
|
}
|
2022-08-18 18:22:15 +02:00
|
|
|
|
|
|
|
// CreateRoute mock implementation of CreateRoute from server.AccountManager interface
|
2023-02-03 10:33:28 +01:00
|
|
|
func (am *MockAccountManager) CreateRoute(accountID string, network, peerID, description, netID string, masquerade bool, metric int, groups []string, enabled bool, userID string) (*route.Route, error) {
|
2022-11-05 10:24:50 +01:00
|
|
|
if am.CreateRouteFunc != nil {
|
2023-02-03 10:33:28 +01:00
|
|
|
return am.CreateRouteFunc(accountID, network, peerID, description, netID, masquerade, metric, groups, enabled, userID)
|
2022-08-18 18:22:15 +02:00
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method CreateRoute is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRoute mock implementation of GetRoute from server.AccountManager interface
|
2022-11-05 10:24:50 +01:00
|
|
|
func (am *MockAccountManager) GetRoute(accountID, routeID, userID string) (*route.Route, error) {
|
2022-08-18 18:22:15 +02:00
|
|
|
if am.GetRouteFunc != nil {
|
2022-11-05 10:24:50 +01:00
|
|
|
return am.GetRouteFunc(accountID, routeID, userID)
|
2022-08-18 18:22:15 +02:00
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetRoute is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveRoute mock implementation of SaveRoute from server.AccountManager interface
|
2023-01-25 16:29:59 +01:00
|
|
|
func (am *MockAccountManager) SaveRoute(accountID, userID string, route *route.Route) error {
|
2022-08-18 18:22:15 +02:00
|
|
|
if am.SaveRouteFunc != nil {
|
2023-01-25 16:29:59 +01:00
|
|
|
return am.SaveRouteFunc(accountID, userID, route)
|
2022-08-18 18:22:15 +02:00
|
|
|
}
|
|
|
|
return status.Errorf(codes.Unimplemented, "method SaveRoute is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateRoute mock implementation of UpdateRoute from server.AccountManager interface
|
2023-01-25 16:29:59 +01:00
|
|
|
func (am *MockAccountManager) UpdateRoute(accountID, ruleID string, operations []server.RouteUpdateOperation) (*route.Route, error) {
|
2022-08-18 18:22:15 +02:00
|
|
|
if am.UpdateRouteFunc != nil {
|
|
|
|
return am.UpdateRouteFunc(accountID, ruleID, operations)
|
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method UpdateRoute not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteRoute mock implementation of DeleteRoute from server.AccountManager interface
|
2023-01-25 16:29:59 +01:00
|
|
|
func (am *MockAccountManager) DeleteRoute(accountID, routeID, userID string) error {
|
2022-08-18 18:22:15 +02:00
|
|
|
if am.DeleteRouteFunc != nil {
|
2023-01-25 16:29:59 +01:00
|
|
|
return am.DeleteRouteFunc(accountID, routeID, userID)
|
2022-08-18 18:22:15 +02:00
|
|
|
}
|
|
|
|
return status.Errorf(codes.Unimplemented, "method DeleteRoute is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListRoutes mock implementation of ListRoutes from server.AccountManager interface
|
2022-11-05 10:24:50 +01:00
|
|
|
func (am *MockAccountManager) ListRoutes(accountID, userID string) ([]*route.Route, error) {
|
2022-08-18 18:22:15 +02:00
|
|
|
if am.ListRoutesFunc != nil {
|
2022-11-05 10:24:50 +01:00
|
|
|
return am.ListRoutesFunc(accountID, userID)
|
2022-08-18 18:22:15 +02:00
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method ListRoutes is not implemented")
|
|
|
|
}
|
2022-09-11 23:16:40 +02:00
|
|
|
|
|
|
|
// SaveSetupKey mocks SaveSetupKey of the AccountManager interface
|
2023-01-02 15:11:32 +01:00
|
|
|
func (am *MockAccountManager) SaveSetupKey(accountID string, key *server.SetupKey, userID string) (*server.SetupKey, error) {
|
2022-09-11 23:16:40 +02:00
|
|
|
if am.SaveSetupKeyFunc != nil {
|
2023-01-02 15:11:32 +01:00
|
|
|
return am.SaveSetupKeyFunc(accountID, key, userID)
|
2022-09-11 23:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method SaveSetupKey is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetSetupKey mocks GetSetupKey of the AccountManager interface
|
2022-11-05 10:24:50 +01:00
|
|
|
func (am *MockAccountManager) GetSetupKey(accountID, userID, keyID string) (*server.SetupKey, error) {
|
2022-09-11 23:16:40 +02:00
|
|
|
if am.GetSetupKeyFunc != nil {
|
2022-11-05 10:24:50 +01:00
|
|
|
return am.GetSetupKeyFunc(accountID, userID, keyID)
|
2022-09-11 23:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetSetupKey is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListSetupKeys mocks ListSetupKeys of the AccountManager interface
|
2022-11-05 10:24:50 +01:00
|
|
|
func (am *MockAccountManager) ListSetupKeys(accountID, userID string) ([]*server.SetupKey, error) {
|
2022-09-11 23:16:40 +02:00
|
|
|
if am.ListSetupKeysFunc != nil {
|
2022-11-05 10:24:50 +01:00
|
|
|
return am.ListSetupKeysFunc(accountID, userID)
|
2022-09-11 23:16:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method ListSetupKeys is not implemented")
|
|
|
|
}
|
2022-09-22 09:06:32 +02:00
|
|
|
|
|
|
|
// SaveUser mocks SaveUser of the AccountManager interface
|
2023-01-02 15:11:32 +01:00
|
|
|
func (am *MockAccountManager) SaveUser(accountID, userID string, user *server.User) (*server.UserInfo, error) {
|
2022-09-22 09:06:32 +02:00
|
|
|
if am.SaveUserFunc != nil {
|
2023-01-02 15:11:32 +01:00
|
|
|
return am.SaveUserFunc(accountID, userID, user)
|
2022-09-22 09:06:32 +02:00
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method SaveUser is not implemented")
|
|
|
|
}
|
2022-09-30 13:47:11 +02:00
|
|
|
|
2023-04-22 12:57:51 +02:00
|
|
|
// DeleteUser mocks DeleteUser of the AccountManager interface
|
2023-05-11 18:09:36 +02:00
|
|
|
func (am *MockAccountManager) DeleteUser(accountID string, initiatorUserID string, targetUserID string) error {
|
2023-04-22 12:57:51 +02:00
|
|
|
if am.DeleteUserFunc != nil {
|
2023-05-11 18:09:36 +02:00
|
|
|
return am.DeleteUserFunc(accountID, initiatorUserID, targetUserID)
|
2023-04-22 12:57:51 +02:00
|
|
|
}
|
|
|
|
return status.Errorf(codes.Unimplemented, "method DeleteUser is not implemented")
|
|
|
|
}
|
|
|
|
|
2022-09-30 13:47:11 +02:00
|
|
|
// GetNameServerGroup mocks GetNameServerGroup of the AccountManager interface
|
|
|
|
func (am *MockAccountManager) GetNameServerGroup(accountID, nsGroupID string) (*nbdns.NameServerGroup, error) {
|
|
|
|
if am.GetNameServerGroupFunc != nil {
|
|
|
|
return am.GetNameServerGroupFunc(accountID, nsGroupID)
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateNameServerGroup mocks CreateNameServerGroup of the AccountManager interface
|
2023-01-25 16:29:59 +01:00
|
|
|
func (am *MockAccountManager) CreateNameServerGroup(accountID string, name, description string, nameServerList []nbdns.NameServer, groups []string, primary bool, domains []string, enabled bool, userID string) (*nbdns.NameServerGroup, error) {
|
2022-09-30 13:47:11 +02:00
|
|
|
if am.CreateNameServerGroupFunc != nil {
|
2023-01-25 16:29:59 +01:00
|
|
|
return am.CreateNameServerGroupFunc(accountID, name, description, nameServerList, groups, primary, domains, enabled, userID)
|
2022-09-30 13:47:11 +02:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveNameServerGroup mocks SaveNameServerGroup of the AccountManager interface
|
2023-01-25 16:29:59 +01:00
|
|
|
func (am *MockAccountManager) SaveNameServerGroup(accountID, userID string, nsGroupToSave *nbdns.NameServerGroup) error {
|
2022-09-30 13:47:11 +02:00
|
|
|
if am.SaveNameServerGroupFunc != nil {
|
2023-01-25 16:29:59 +01:00
|
|
|
return am.SaveNameServerGroupFunc(accountID, userID, nsGroupToSave)
|
2022-09-30 13:47:11 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateNameServerGroup mocks UpdateNameServerGroup of the AccountManager interface
|
2023-01-25 16:29:59 +01:00
|
|
|
func (am *MockAccountManager) UpdateNameServerGroup(accountID, nsGroupID, userID string, operations []server.NameServerGroupUpdateOperation) (*nbdns.NameServerGroup, error) {
|
2022-09-30 13:47:11 +02:00
|
|
|
if am.UpdateNameServerGroupFunc != nil {
|
2023-01-25 16:29:59 +01:00
|
|
|
return am.UpdateNameServerGroupFunc(accountID, nsGroupID, userID, operations)
|
2022-09-30 13:47:11 +02:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteNameServerGroup mocks DeleteNameServerGroup of the AccountManager interface
|
2023-01-25 16:29:59 +01:00
|
|
|
func (am *MockAccountManager) DeleteNameServerGroup(accountID, nsGroupID, userID string) error {
|
2022-09-30 13:47:11 +02:00
|
|
|
if am.DeleteNameServerGroupFunc != nil {
|
2023-01-25 16:29:59 +01:00
|
|
|
return am.DeleteNameServerGroupFunc(accountID, nsGroupID, userID)
|
2022-09-30 13:47:11 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListNameServerGroups mocks ListNameServerGroups of the AccountManager interface
|
|
|
|
func (am *MockAccountManager) ListNameServerGroups(accountID string) ([]*nbdns.NameServerGroup, error) {
|
|
|
|
if am.ListNameServerGroupsFunc != nil {
|
|
|
|
return am.ListNameServerGroupsFunc(accountID)
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-10-13 18:26:31 +02:00
|
|
|
|
|
|
|
// CreateUser mocks CreateUser of the AccountManager interface
|
2023-01-02 15:11:32 +01:00
|
|
|
func (am *MockAccountManager) CreateUser(accountID, userID string, invite *server.UserInfo) (*server.UserInfo, error) {
|
2022-10-13 18:26:31 +02:00
|
|
|
if am.CreateUserFunc != nil {
|
2023-01-02 15:11:32 +01:00
|
|
|
return am.CreateUserFunc(accountID, userID, invite)
|
2022-10-13 18:26:31 +02:00
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method CreateUser is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAccountFromToken mocks GetAccountFromToken of the AccountManager interface
|
2022-11-11 20:36:45 +01:00
|
|
|
func (am *MockAccountManager) GetAccountFromToken(claims jwtclaims.AuthorizationClaims) (*server.Account, *server.User,
|
2023-03-13 15:14:18 +01:00
|
|
|
error,
|
|
|
|
) {
|
2022-10-13 18:26:31 +02:00
|
|
|
if am.GetAccountFromTokenFunc != nil {
|
|
|
|
return am.GetAccountFromTokenFunc(claims)
|
|
|
|
}
|
2022-11-11 20:36:45 +01:00
|
|
|
return nil, nil, status.Errorf(codes.Unimplemented, "method GetAccountFromToken is not implemented")
|
2022-10-13 18:26:31 +02:00
|
|
|
}
|
2022-11-05 10:24:50 +01:00
|
|
|
|
|
|
|
// GetPeers mocks GetPeers of the AccountManager interface
|
|
|
|
func (am *MockAccountManager) GetPeers(accountID, userID string) ([]*server.Peer, error) {
|
|
|
|
if am.GetAccountFromTokenFunc != nil {
|
|
|
|
return am.GetPeersFunc(accountID, userID)
|
|
|
|
}
|
2023-02-28 15:01:24 +01:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAllPeers is not implemented")
|
2022-11-05 10:24:50 +01:00
|
|
|
}
|
2022-11-21 11:14:42 +01:00
|
|
|
|
|
|
|
// GetDNSDomain mocks GetDNSDomain of the AccountManager interface
|
|
|
|
func (am *MockAccountManager) GetDNSDomain() string {
|
|
|
|
if am.GetDNSDomainFunc != nil {
|
|
|
|
return am.GetDNSDomainFunc()
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
2023-01-02 15:11:32 +01:00
|
|
|
|
|
|
|
// GetEvents mocks GetEvents of the AccountManager interface
|
|
|
|
func (am *MockAccountManager) GetEvents(accountID, userID string) ([]*activity.Event, error) {
|
|
|
|
if am.GetEventsFunc != nil {
|
|
|
|
return am.GetEventsFunc(accountID, userID)
|
|
|
|
}
|
2023-02-28 15:01:24 +01:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAllEvents is not implemented")
|
2023-01-02 15:11:32 +01:00
|
|
|
}
|
2023-01-17 17:34:40 +01:00
|
|
|
|
|
|
|
// GetDNSSettings mocks GetDNSSettings of the AccountManager interface
|
|
|
|
func (am *MockAccountManager) GetDNSSettings(accountID string, userID string) (*server.DNSSettings, error) {
|
|
|
|
if am.GetDNSSettingsFunc != nil {
|
|
|
|
return am.GetDNSSettingsFunc(accountID, userID)
|
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetDNSSettings is not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveDNSSettings mocks SaveDNSSettings of the AccountManager interface
|
|
|
|
func (am *MockAccountManager) SaveDNSSettings(accountID string, userID string, dnsSettingsToSave *server.DNSSettings) error {
|
|
|
|
if am.SaveDNSSettingsFunc != nil {
|
|
|
|
return am.SaveDNSSettingsFunc(accountID, userID, dnsSettingsToSave)
|
|
|
|
}
|
|
|
|
return status.Errorf(codes.Unimplemented, "method SaveDNSSettings is not implemented")
|
|
|
|
}
|
2023-02-07 20:11:08 +01:00
|
|
|
|
|
|
|
// GetPeer mocks GetPeer of the AccountManager interface
|
|
|
|
func (am *MockAccountManager) GetPeer(accountID, peerID, userID string) (*server.Peer, error) {
|
|
|
|
if am.GetPeerFunc != nil {
|
|
|
|
return am.GetPeerFunc(accountID, peerID, userID)
|
|
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPeer is not implemented")
|
|
|
|
}
|
2023-02-13 12:21:02 +01:00
|
|
|
|
2023-03-03 18:35:38 +01:00
|
|
|
// UpdateAccountSettings mocks UpdateAccountSettings of the AccountManager interface
|
|
|
|
func (am *MockAccountManager) UpdateAccountSettings(accountID, userID string, newSettings *server.Settings) (*server.Account, error) {
|
|
|
|
if am.UpdateAccountSettingsFunc != nil {
|
|
|
|
return am.UpdateAccountSettingsFunc(accountID, userID, newSettings)
|
2023-02-13 12:21:02 +01:00
|
|
|
}
|
2023-03-03 18:35:38 +01:00
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method UpdateAccountSettings is not implemented")
|
2023-02-13 12:21:02 +01:00
|
|
|
}
|
|
|
|
|
2023-03-03 18:35:38 +01:00
|
|
|
// LoginPeer mocks LoginPeer of the AccountManager interface
|
|
|
|
func (am *MockAccountManager) LoginPeer(login server.PeerLogin) (*server.Peer, *server.NetworkMap, error) {
|
|
|
|
if am.LoginPeerFunc != nil {
|
|
|
|
return am.LoginPeerFunc(login)
|
2023-02-13 12:21:02 +01:00
|
|
|
}
|
2023-03-03 18:35:38 +01:00
|
|
|
return nil, nil, status.Errorf(codes.Unimplemented, "method LoginPeer is not implemented")
|
2023-02-13 12:21:02 +01:00
|
|
|
}
|
2023-02-16 12:00:41 +01:00
|
|
|
|
2023-03-03 18:35:38 +01:00
|
|
|
// SyncPeer mocks SyncPeer of the AccountManager interface
|
|
|
|
func (am *MockAccountManager) SyncPeer(sync server.PeerSync) (*server.Peer, *server.NetworkMap, error) {
|
|
|
|
if am.SyncPeerFunc != nil {
|
|
|
|
return am.SyncPeerFunc(sync)
|
2023-02-16 12:00:41 +01:00
|
|
|
}
|
2023-03-03 18:35:38 +01:00
|
|
|
return nil, nil, status.Errorf(codes.Unimplemented, "method SyncPeer is not implemented")
|
2023-02-16 12:00:41 +01:00
|
|
|
}
|