mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-10 15:39:07 +02:00
* implement certificate posture check * log signal address * add keychain and cert store support * read the console user's keychain through a user session helper A root daemon cannot reach a login keychain: securityd is per session and a key ACL needs a session to prompt in, so dropping uid is not enough. The daemon now answers certificate challenges from the System keychain itself, where MDM installs device identities, and launches "netbird posture cert-proof" into the console user's desktop session with launchctl asuser for the login keychain. Only the signature and the chain cross back, never the private key. The console user comes from SCDynamicStoreCopyConsoleUser, bound with purego like the keychain calls. The login window reports no user, root, or "loginwindow", and all three are treated as no keychain to read, so a Mac at the lock screen sends device proofs alone. Adds info logging across the path: the keychain search list, per class query status and item counts, the chain built per candidate, and the verification error for every rejected candidate. A run that sends nothing now says why. README.md documents the trust model, the console user limitation and how to read the logs. * read the signed-in user's certificate store on Windows A service reads LocalMachine\MY, where AD and Intune enrol device certificates. CurrentUser\MY lives in the signed-in user's registry hive with keys protected against their profile, and a service that opens it does not fail: "current user" resolves to HKU\S-1-5-18, so it silently reads the service account's own empty store. The service therefore reads the machine store itself and launches "netbird posture cert-proof" with the session token for the rest, mirroring the macOS console user helper. Windows lets a privileged service assume a user identity, so the token goes straight into the child process and no external tooling is involved. CREATE_NO_WINDOW keeps a console window from flashing on the desktop every sync. In-process impersonation would also work but is per OS thread while goroutines migrate, so the child process avoids that class of bug. Session selection prefers the physical console and falls back to any active session, so remote desktop and VDI hosts are covered. WTSQueryUserToken needs SE_TCB_NAME, so a user-run client skips the helper and reads the machine store alone. SystemStore takes a store location, gaining NewUserStore alongside NewSystemStore and the per candidate logging macOS already had. The request building and proof merging move to helper_spawn.go, shared by both platforms, and helperStore picks what the helper reads per platform. * start TPM support * split goreleaser to support pkcs11 and exclude on docker * update goreleaser * go mod tidy * add tpm pin to netbird config * split cert and key location and allow key lookup on tpm * add unsupported flag for mobile devices * Isolate the cert proof helper from the service environment and cap its output * Read the PKCS#11 token PIN from NB_TPM_PIN instead of the profile config * Bound certificate proof collection so a stuck token or keychain cannot hold the sync loop * Stop retrying a PKCS#11 PIN the token rejected * Log certificate posture details at debug level * Sign only nonces and peer keys of the size management issues * Skip certificate files whose key belongs to another certificate * Bound PKCS#11 driver sizes, pin template values, and log out only a login the session owns * Never pass NULL to CFRelease and skip unreadable keychain identities * Keep the macOS keychain code out of iOS and the PKCS#11 driver out of Android * Find a chain to each challenge's CAs through every intermediate the store holds * Require a token label whenever a PKCS#11 PIN is set * Read user certificates only from the session of the active profile's owner * Collect certificate proofs again when the owner's session changes and report lost proofs * Test the PKCS#11 build against SoftHSM in CI and warn once where the build has no driver * Document where an inline PKCS#11 PIN is stored and how it is protected * Refuse PKCS#11 URIs that this client cannot honour instead of widening the match * Trust certificate and key files only when no other user can write or redirect them * Explain a Windows certificate whose key only a legacy CryptoAPI provider holds * Use platform absolute module paths in tests and add a real owner session test for Windows * Match the Windows profile owner by name instead of resolving it through the domain controller * Keep the certificate stores and TPM library out of the WebAssembly build * [client] Read TSS2 key files on go-tpm, checked against the library it replaces The TSS2 parser was the only reason this repository depended on a crypto suite whose own build tooling it inherits. The replacement sits on go-tpm, which was already a direct dependency and is in fact what that suite calls underneath, so this removes a wrapper rather than porting onto a different library: the load, the derived storage root key and the signing commands are the same calls. Swapping a parser on the one path a customer actually runs is not something to assert, so the two are held side by side for this commit. One test feeds the replacement bytes the old library wrote and requires the same key type, empty auth flag, parent handle, blobs and decoded public key; the other feeds both the fixtures the tests are built on, so those are the shape the format calls for and not merely the shape the new parser reads. The scaffolding goes away with the dependency in the commit that follows. The encoder behind the fixtures is written out separately from the parser under test, so an encoder bug and a decoder bug cannot cancel each other out. * [client] Drop go.step.sm/crypto and the repo-wide upgrades it imposed The TSS2 parser was the only thing in the repository that used this module, and it brought 302 modules into the graph to do it — 35 of them linters, along with Google Cloud KMS and IAM, the AWS SDK and a terminal styling library. Those are the module's own development dependencies, which minimal version selection turns into floors in ours, and they are the whole reason gRPC, protobuf, the AWS SDK, OpenTelemetry, logrus and five x/ packages had moved. Management, signal, relay and proxy inherited every one of them for a feature none of them runs. Removing the import is not enough, because tidy never downgrades: the raised floors stay written in go.mod. Each one is pinned back to the version main had, then tidy is left to raise again whatever something still genuinely needs. It raised nothing: all 43 are back where they were, and go-tpm was already in the graph at the same version, so the certificate feature now costs no new module at all. The differential tests go with it. They existed to check the swap against the library while both were present, and there is nothing left to compare against. * [client] Clear the lint findings only the macOS and Windows runners see golangci-lint analyses one build at a time, so running it on Linux says nothing about the two platforms CI also lints. Against those builds the feature's packages reported eight findings, and the structural one is Config.dir: it is dead on macOS and Windows because neither reads a directory at all, their collectors take the configuration and discard it. Moving the method beside its only callers makes that visible in the layout instead of in a linter, and leaves the gap itself — no file or token store on those platforms — where it belongs, as something to decide rather than something to silence. An absent key file beside a certificate was reported as a nil signer with a nil error, which the caller then had to recognise by its nilness. It is a sentinel now, so the meaning is in the error rather than in the absence of one. The rest follow the standard library: the elliptic coordinates and the private scalar come from the encoding helpers rather than the deprecated big.Int fields, and an error string loses its trailing colon. Lint is clean on linux, darwin and windows; the hardware TPM path was exercised separately against a real device and passes. * Accept the TSS2 emptyAuth boolean OpenSSL writes and persistent parents on 32-bit builds * Count the certificates field in the peer meta store test * Check the store directory before listing it, refuse group-writable files, and reject a URI with two PIN sources * Share a PKCS#11 login between sessions and send each PIN at most once at a time * Collect certificate proofs again when the meta sync carrying them failed * Use no Windows user store when a domainless owner matches accounts of several domains * Use no user certificate store when the active profile's owner cannot be read * Document the PIN sources on CertPKCS11URI and keep the README PIN example off the command line * Test that the PKCS#11 URI stays out of the debug bundle and run the wrong-PIN test only on a disposable token * Refuse a TPM PSS signature request for the maximum salt length * Add the certificate fields to the network map golden data * Retry posture checks whose meta sync timed out instead of dropping them * Start no system info gathering while a timed-out one is still running * Guard the applied posture checks across goroutines and keep refreshing proofs while a pending update times out * Log what a successful certificate proof helper wrote to stderr * Send recollected certificate proofs to management only when the proven chains changed * Explain a macOS keychain key whose access list does not allow netbird * Kill the whole macOS certificate helper process group when it times out * End sudo option parsing before the macOS certificate helper binary * Hold off system info gathering only while a timed-out one is still running * Collect certificate proofs on the posture watcher instead of under the sync lock * Read the certificate store directory and PKCS#11 URI from the daemon environment, not the profile config * Install the RPM sysconfig file readable by root only and show the certificate posture variables * Move the certificate posture README into the package doc and the docs site * Name NB_CERT_PKCS11_URI in the PIN-without-token error * Keep the file check results of the latest-started system info refresh * Give the full import command for a keychain key netbird may not use, and correct the package doc * Restrict the service environment file to root on every package install * Search only the System keychain in the macOS daemon and only the login keychain in the user helper * Let the certificate proof helper read the PKCS#11 token from the environment on Linux * Ask a macOS user's keychain again only after an hour when it proved nothing * Clear the lint findings in certificate posture * Hold off the keychain helper only after a completed or timed-out run, independent of CA order * Keep free functions out of the method lists of PKCS11Store, URI and Challenger * Name the post-install permission helper in snake case and shorten the sysconfig certificate block * Drop the certificate store directory from certproof.Config, which only NB_CERT_STORE_DIR sets * [management] Renew certificate challenge nonces on quiet accounts A certificate challenge nonce is accepted for its own window and the one before it, and it only reaches a peer attached to a network map. An account where nothing changes sends no map, so after a day the peer re-sends the nonce it still holds, verification rejects its whole proof set, and the certificates stored for it are dropped. It fails the certificate check and loses every policy gated on it until some unrelated change happens to push a map. The outage repairs itself in seconds, which is what makes it expensive: it is intermittent, it only hits stable networks, and it is not reproducible on demand. Push the account's peers an update often enough that the nonce they hold is never close to expiring. Only accounts whose posture checks actually ask for a certificate are tracked, so a deployment without the feature does no extra work. The refresh runs from one goroutine over a map of accounts rather than a timer per account: the period is hours, so one pass every few minutes costs nothing next to it, and there is no timer to re-arm when an account that falls due sooner appears. Each account's first run is offset by a hash of its ID, because the challenge window is global and an instance restart would otherwise arm every account in the same moment. The push carries no administrative change, so it is counted as a refresh rather than an update and stays out of the figures that track what was edited. (cherry picked from commit7ad4a0df37) * [management] Make the certificate challenge window one knob to turn Renewal was timed against the window in two different ways: the period derived from it, the sweep interval did not. Shortening the window to watch a renewal in an end-to-end run would have left the refresher still looking for due accounts every quarter of an hour, so nothing would have been renewed in time and the test would have reported the feature broken. Derive the sweep from the period, within bounds that keep a very short window from spinning and a normal one from checking less often than is useful, and allow the window itself to be set through the environment so a run can take seconds instead of half a day. A value that cannot be parsed or falls outside the bounds keeps the default, because a window nobody intended is a security property nobody chose, and an override is logged at warning level since it sets how long a device keeps passing the check after its key is gone. Every instance has to be given the same value: the window is part of the nonce, so instances that disagree reject each other's. (cherry picked from commit0e38fcf409) * [management] Pin the property that makes per-peer nonce state unnecessary A nonce carries the window it was minted in, not the instant, and is accepted for that window and the one before it. So a peer re-stamped at least once per window can never be left holding one outside the accepted pair, whenever it was last served and however much life its own nonce had left. That is the whole reason management tracks nothing per peer, and it was resting on an argument rather than a test. The phases are part of the property, not decoration: accounts are deliberately given a refresh phase of their own, so the guarantee has to hold off the window boundary too. The negative case shows why that matters — a cadence of exactly two windows lands inside the grace window when it is aligned to the boundary and leaves a gap when it is not. (cherry picked from commitdee68facfd) * [management] Renew challenges only for the peers that answer one The refresh pushed an update to every connected peer of the account, while only the peers a certificate check applies to carry a nonce. On an account where a handful of peers sit behind the check and the rest do not, everyone was woken several times a day to be handed a map that changed nothing for them. Push to the sources of the enabled policies whose posture checks include a certificate check, which is exactly the set that is sent a challenge. Resolving the set the other way round than the gRPC layer does is the risk here: a peer the refresh forgets stops being renewed and falls out of its policies silently, which is the failure this whole mechanism exists to prevent. So the selection is held against processPeerPostureChecks, the per-peer rule that decides who receives a challenge in the first place, by a test that asks both the same question and requires the same answer. (cherry picked from commitdc4d0e0274) * [management] Derive certificate challenge nonces from the stored encryption key The nonce secret came from the server's WireGuard key, which is generated afresh in every process and never persisted. A nonce carries no state, so the only thing that lets one instance verify what another issued is deriving the same secret — and that premise, written in the comment above the challenger, was not met: every instance had its own key. A peer reconnecting after a restart therefore presented a nonce minted under the previous secret, verification failed with a mismatch, its whole proof set was rejected and the certificates stored for it were dropped until it signed again. Reproduced three times on the lab, each one logging "nonce was not issued to this peer", which only a changed secret produces. On a single instance it costs seconds of lost policy access per restart; across instances it is not transient at all, because every reconnect that lands elsewhere is rejected the same way. Derive from the data store encryption key instead: it is generated once, written back to the configuration and read by every instance, so it survives restarts and is shared. Where none is configured the secret falls back to the WireGuard key with a warning — degraded but still unpredictable, which is the property that matters most: a peer able to guess it could mint the nonces of future windows, sign them while its key is present and keep passing after it is gone. The challenger is now built once and passed to the two places that need it, rather than re-derived per message. (cherry picked from commit278f2f3807) * [management] Register an account for renewal where its nonce is issued Renewal was armed when a peer connected or when a posture check was saved, both of which ask the store whether the account has a certificate check. That misses the case it most needs to catch: the check is created through one instance while the peers are connected to another, so the instance serving them never learns it has anything to renew and their nonce expires. It also charged a query to every peer connect in every account, including the ones that will never use the feature, which a fleet reconnecting after a restart pays all at once. Register where the nonce is actually stamped instead. A nonce is verified from a shared secret and so travels between instances, but the renewal that keeps it fresh cannot: only the instance holding a peer's stream can push to it. Issuing and renewing now line up by construction — an instance renews exactly the accounts it has issued nonces for — and an instance that never issues one has nothing to renew, so there is no case left to miss. The registration is a map insert with no store access, which is what lets it sit on a path taken by every login and every initial sync. Reported by Viktor Liu, who also proposed registering at the point of issue. (cherry picked from commit 2d16dd7d7cf54762f2e64c5630ea092f32ef63ab) * [management] Register for renewal on pushed updates, not only on connect Registering where the nonce is stamped only covered the login and the initial sync, which both happen when a peer opens a stream. That left out the path the mechanism exists for. On the cloud the network map controller is wrapped so that an update publishes to an event bus instead of pushing locally: an instance handling a REST change broadcasts, and every instance holding a peer of that account pushes to its own. Those pushes stamp a nonce through the update handler, and nothing there registered, so an instance learned about an account only when one of its peers happened to reconnect. For a quiet fleet that is the original bug: the check is created, the peers are told about it, and nobody renews what they were told. Registering on the pushed update closes it, and is the difference between stamping and marking a peer connected — one happens on every push, the other only when a stream opens. Reported by Viktor Liu; the broadcast that makes it work was pointed out by Pascal Fischer. (cherry picked from commit 59efe8d93e53bacdf57cb546f4ab2c19dc4eddab) * [management] Let the challenge refresh loop stop with the manager that owns it The loop was started on a context explicitly detached from the caller's, so nothing could ever stop it. Production is unaffected either way, since BuildManager is called with context.Background(), but a test that builds a manager leaked a sweeping goroutine for the rest of the run, and a shutdown path added later would have had no way to reach it. Take the manager's context as the request buffer built on the line above already does. The test pins the contract the loop offers, so a detached context cannot come back inside Start either. * [management] Bound one account's challenge refresh so it cannot starve the rest Resolving which peers answer a challenge reads the store three times, and the refresher sweeps accounts one after another on a single goroutine. A read that never returns held the sweep for the life of the process, so every other account on the instance stopped being renewed and its peers fell out of the policies gated on the check: one account's bad luck became an outage for all of them. Give each refresh the sweep interval it is allowed to occupy, capped at 30s so a 12-hour window does not grant minutes to a query that should take milliseconds. A refresh that runs out of time keeps its account tracked, since a deadline says nothing about whether that account still has a certificate check. * [management] Send challenge refreshes down the path the rest of management uses The refresh dispatched through UpdateAffectedPeers, the one variant that takes no reason, so it was missing from the update counters and coalesced with nothing. An administrator editing a policy while the sweep ran made the account's network map twice over, and UpdateOperationRefresh, added for exactly this caller, was never referenced. Buffer it with a posture_check/refresh reason instead. The periodic push is now visible in the metrics as what it is, distinct from an edit, and the send detaches from the sweep deadline on its own, so that deadline bounds the store reads it was meant for. * [management] Keep the certificate challenge comments to what the history does not say Four of these ran to three and four times the comment budget, the longest at 992 characters. Most of the excess argued against designs that were never written or explained a bug that no longer exists in the code, which is what the commit that fixed it is for. What is left is the part a reader cannot recover from the code: that the nonce secret has to be persisted and unpredictable, that stamping and renewing are decided together because only the serving instance can push, and that the target rule is the inverse of processPeerPostureChecks. * Keep the newest posture checks pending whatever made their meta sync fail * Report no lost certificate when the engine stops during a proof collection * Share the proof collection single-flight across engine restarts * Close a PKCS#11 module that loads but cannot be used * Fix the pending checks comments * Renew certificate challenges only for the peers streamed to this instance * Ignore a challenge stamp from an older sync stream of the same peer * Kill the Windows certificate proof helper with its whole process tree * Expect the challenge untrack in the session ownership test * Drop an invalid certificate proof without discarding the valid ones * Start a system info gathering beside one that has been stuck for ten timeouts --------- Co-authored-by: pascal <pascal@netbird.io> Co-authored-by: mlsmaycon <mlsmaycon@gmail.com> Co-authored-by: riccardom <riccardomanfrin@gmail.com>
1179 lines
64 KiB
Go
1179 lines
64 KiB
Go
package mock_server
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/netip"
|
|
"time"
|
|
|
|
"github.com/netbirdio/netbird/shared/auth"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
nbdns "github.com/netbirdio/netbird/dns"
|
|
"github.com/netbirdio/netbird/management/internals/modules/reverseproxy/service"
|
|
"github.com/netbirdio/netbird/management/server/account"
|
|
"github.com/netbirdio/netbird/management/server/activity"
|
|
"github.com/netbirdio/netbird/management/server/affectedpeers"
|
|
"github.com/netbirdio/netbird/management/server/idp"
|
|
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
|
"github.com/netbirdio/netbird/management/server/posture"
|
|
"github.com/netbirdio/netbird/management/server/store"
|
|
"github.com/netbirdio/netbird/management/server/types"
|
|
"github.com/netbirdio/netbird/management/server/users"
|
|
"github.com/netbirdio/netbird/route"
|
|
"github.com/netbirdio/netbird/shared/management/domain"
|
|
"github.com/netbirdio/netbird/shared/management/networkmap/nmdata"
|
|
)
|
|
|
|
var _ account.Manager = (*MockAccountManager)(nil)
|
|
|
|
type MockAccountManager struct {
|
|
GetOrCreateAccountByUserFunc func(ctx context.Context, userAuth auth.UserAuth) (*types.Account, error)
|
|
GetAccountFunc func(ctx context.Context, accountID string) (*types.Account, error)
|
|
CreateSetupKeyFunc func(ctx context.Context, accountId string, keyName string, keyType types.SetupKeyType,
|
|
expiresIn time.Duration, autoGroups []string, usageLimit int, userID string, ephemeral bool, allowExtraDNSLabels bool) (*types.SetupKey, error)
|
|
GetSetupKeyFunc func(ctx context.Context, accountID, userID, keyID string) (*types.SetupKey, error)
|
|
AccountExistsFunc func(ctx context.Context, accountID string) (bool, error)
|
|
GetAccountIDByUserIdFunc func(ctx context.Context, userAuth auth.UserAuth) (string, error)
|
|
GetUserFromUserAuthFunc func(ctx context.Context, userAuth auth.UserAuth) (*types.User, error)
|
|
ListUsersFunc func(ctx context.Context, accountID string) ([]*types.User, error)
|
|
GetPeersFunc func(ctx context.Context, accountID, userID, nameFilter, ipFilter, macFilter string) ([]*nbpeer.Peer, error)
|
|
MarkPeerConnectedFunc func(ctx context.Context, peerKey string, accountID string, sessionStartedAt int64, nmap *types.NetworkMap) error
|
|
MarkPeerDisconnectedFunc func(ctx context.Context, peerKey string, accountID string, sessionStartedAt int64) error
|
|
SyncAndMarkPeerFunc func(ctx context.Context, accountID string, peerPubKey string, meta nbpeer.PeerSystemMeta, realIP net.IP, syncTime time.Time) (*nbpeer.Peer, *types.NetworkMap, []*nmdata.PostureChecks, int64, error)
|
|
DeletePeerFunc func(ctx context.Context, accountID, peerKey, userID string) error
|
|
GetNetworkMapFunc func(ctx context.Context, peerKey string) (*types.NetworkMap, error)
|
|
GetPeerNetworkFunc func(ctx context.Context, peerKey string) (*types.Network, error)
|
|
AddPeerFunc func(ctx context.Context, accountID string, setupKey string, userId string, peer *nbpeer.Peer, temporary bool) (*nbpeer.Peer, *types.Network, []*nmdata.PostureChecks, bool, error)
|
|
GetGroupFunc func(ctx context.Context, accountID, groupID, userID string) (*types.Group, error)
|
|
GetAllGroupsFunc func(ctx context.Context, accountID, userID string) ([]*types.Group, error)
|
|
GetGroupByNameFunc func(ctx context.Context, groupName, accountID, userID string) (*types.Group, error)
|
|
SaveGroupFunc func(ctx context.Context, accountID, userID string, group *types.Group, create bool) error
|
|
SaveGroupsFunc func(ctx context.Context, accountID, userID string, groups []*types.Group, create bool) error
|
|
DeleteGroupFunc func(ctx context.Context, accountID, userId, groupID string) error
|
|
DeleteGroupsFunc func(ctx context.Context, accountId, userId string, groupIDs []string) error
|
|
GroupAddPeerFunc func(ctx context.Context, accountID, groupID, peerID string) error
|
|
GroupDeletePeerFunc func(ctx context.Context, accountID, groupID, peerID string) error
|
|
GetPeerGroupsFunc func(ctx context.Context, accountID, peerID string) ([]*types.Group, error)
|
|
DeleteRuleFunc func(ctx context.Context, accountID, ruleID, userID string) error
|
|
GetPolicyFunc func(ctx context.Context, accountID, policyID, userID string) (*types.Policy, error)
|
|
SavePolicyFunc func(ctx context.Context, accountID, userID string, policy *types.Policy, create bool) (*types.Policy, error)
|
|
DeletePolicyFunc func(ctx context.Context, accountID, policyID, userID string) error
|
|
ListPoliciesFunc func(ctx context.Context, accountID, userID string) ([]*types.Policy, error)
|
|
GetUsersFromAccountFunc func(ctx context.Context, accountID, userID string) (map[string]*types.UserInfo, error)
|
|
UpdatePeerMetaFunc func(ctx context.Context, peerID string, meta nbpeer.PeerSystemMeta) error
|
|
UpdatePeerFunc func(ctx context.Context, accountID, userID string, peer *nbpeer.Peer) (*nbpeer.Peer, error)
|
|
UpdatePeerIPFunc func(ctx context.Context, accountID, userID, peerID string, newIP netip.Addr) error
|
|
UpdatePeerIPv6Func func(ctx context.Context, accountID, userID, peerID string, newIPv6 netip.Addr) error
|
|
CreateRouteFunc func(ctx context.Context, accountID string, prefix netip.Prefix, networkType route.NetworkType, domains domain.List, peer string, peerGroups []string, description string, netID route.NetID, masquerade bool, metric int, groups, accessControlGroupIDs []string, enabled bool, userID string, keepRoute bool, isSelected bool) (*route.Route, error)
|
|
GetRouteFunc func(ctx context.Context, accountID string, routeID route.ID, userID string) (*route.Route, error)
|
|
SaveRouteFunc func(ctx context.Context, accountID string, userID string, route *route.Route) error
|
|
DeleteRouteFunc func(ctx context.Context, accountID string, routeID route.ID, userID string) error
|
|
ListRoutesFunc func(ctx context.Context, accountID, userID string) ([]*route.Route, error)
|
|
SaveSetupKeyFunc func(ctx context.Context, accountID string, key *types.SetupKey, userID string) (*types.SetupKey, error)
|
|
ListSetupKeysFunc func(ctx context.Context, accountID, userID string) ([]*types.SetupKey, error)
|
|
SaveUserFunc func(ctx context.Context, accountID, userID string, user *types.User) (*types.UserInfo, error)
|
|
SaveOrAddUserFunc func(ctx context.Context, accountID, userID string, user *types.User, addIfNotExists bool) (*types.UserInfo, error)
|
|
SaveOrAddUsersFunc func(ctx context.Context, accountID, initiatorUserID string, update []*types.User, addIfNotExists bool) ([]*types.UserInfo, error)
|
|
DeleteUserFunc func(ctx context.Context, accountID string, initiatorUserID string, targetUserID string) error
|
|
DeleteRegularUsersFunc func(ctx context.Context, accountID, initiatorUserID string, targetUserIDs []string, userInfos map[string]*types.UserInfo) error
|
|
UpdateUserPasswordFunc func(ctx context.Context, accountID, currentUserID, targetUserID string, oldPassword, newPassword string) error
|
|
CreatePATFunc func(ctx context.Context, accountID string, initiatorUserID string, targetUserId string, tokenName string, expiresIn int) (*types.PersonalAccessTokenGenerated, error)
|
|
DeletePATFunc func(ctx context.Context, accountID string, initiatorUserID string, targetUserId string, tokenID string) error
|
|
GetPATFunc func(ctx context.Context, accountID string, initiatorUserID string, targetUserId string, tokenID string) (*types.PersonalAccessToken, error)
|
|
GetAllPATsFunc func(ctx context.Context, accountID string, initiatorUserID string, targetUserId string) ([]*types.PersonalAccessToken, error)
|
|
GetNameServerGroupFunc func(ctx context.Context, accountID, userID, nsGroupID string) (*nbdns.NameServerGroup, error)
|
|
CreateNameServerGroupFunc func(ctx context.Context, accountID string, name, description string, nameServerList []nbdns.NameServer, groups []string, primary bool, domains []string, enabled bool, userID string, searchDomainsEnabled bool) (*nbdns.NameServerGroup, error)
|
|
SaveNameServerGroupFunc func(ctx context.Context, accountID, userID string, nsGroupToSave *nbdns.NameServerGroup) error
|
|
DeleteNameServerGroupFunc func(ctx context.Context, accountID, nsGroupID, userID string) error
|
|
ListNameServerGroupsFunc func(ctx context.Context, accountID string, userID string) ([]*nbdns.NameServerGroup, error)
|
|
CreateUserFunc func(ctx context.Context, accountID, userID string, key *types.UserInfo) (*types.UserInfo, error)
|
|
GetAccountIDFromUserAuthFunc func(ctx context.Context, userAuth auth.UserAuth) (string, string, error)
|
|
DeleteAccountFunc func(ctx context.Context, accountID, userID string) error
|
|
GetDNSDomainFunc func(settings *types.Settings) string
|
|
StoreEventFunc func(ctx context.Context, initiatorID, targetID, accountID string, activityID activity.ActivityDescriber, meta map[string]any)
|
|
GetEventsFunc func(ctx context.Context, accountID, userID string) ([]*activity.Event, error)
|
|
GetDNSSettingsFunc func(ctx context.Context, accountID, userID string) (*types.DNSSettings, error)
|
|
SaveDNSSettingsFunc func(ctx context.Context, accountID, userID string, dnsSettingsToSave *types.DNSSettings) error
|
|
GetPeerFunc func(ctx context.Context, accountID, peerID, userID string) (*nbpeer.Peer, error)
|
|
UpdateAccountSettingsFunc func(ctx context.Context, accountID, userID string, newSettings *types.Settings) (*types.Settings, error)
|
|
LoginPeerFunc func(ctx context.Context, login types.PeerLogin) (*nbpeer.Peer, *types.Network, []*nmdata.PostureChecks, bool, error)
|
|
ExtendPeerSessionFunc func(ctx context.Context, peerPubKey, userID string) (time.Time, error)
|
|
SyncPeerFunc func(ctx context.Context, sync types.PeerSync, accountID string) (*nbpeer.Peer, *types.NetworkMap, []*nmdata.PostureChecks, int64, error)
|
|
InviteUserFunc func(ctx context.Context, accountID string, initiatorUserID string, targetUserEmail string) error
|
|
ApproveUserFunc func(ctx context.Context, accountID, initiatorUserID, targetUserID string) (*types.UserInfo, error)
|
|
RejectUserFunc func(ctx context.Context, accountID, initiatorUserID, targetUserID string) error
|
|
GetAllConnectedPeersFunc func() (map[string]struct{}, error)
|
|
HasConnectedChannelFunc func(peerID string) bool
|
|
GetExternalCacheManagerFunc func() account.ExternalCacheManager
|
|
GetPostureChecksFunc func(ctx context.Context, accountID, postureChecksID, userID string) (*posture.Checks, error)
|
|
SavePostureChecksFunc func(ctx context.Context, accountID, userID string, postureChecks *posture.Checks, create bool) (*posture.Checks, error)
|
|
DeletePostureChecksFunc func(ctx context.Context, accountID, postureChecksID, userID string) error
|
|
ListPostureChecksFunc func(ctx context.Context, accountID, userID string) ([]*posture.Checks, error)
|
|
GetIdpManagerFunc func() idp.Manager
|
|
UpdateIntegratedValidatorFunc func(ctx context.Context, accountID, userID, validator string, groups []string) error
|
|
GroupValidationFunc func(ctx context.Context, accountId string, groups []string) (bool, error)
|
|
SyncPeerMetaFunc func(ctx context.Context, peerPubKey string, meta nbpeer.PeerSystemMeta, realIP net.IP) error
|
|
FindExistingPostureCheckFunc func(accountID string, checks *posture.ChecksDefinition) (*posture.Checks, error)
|
|
GetAccountIDForPeerKeyFunc func(ctx context.Context, peerKey string) (string, error)
|
|
GetAccountByIDFunc func(ctx context.Context, accountID string, userID string) (*types.Account, error)
|
|
GetUserByIDFunc func(ctx context.Context, id string) (*types.User, error)
|
|
GetAccountSettingsFunc func(ctx context.Context, accountID string, userID string) (*types.Settings, error)
|
|
DeleteSetupKeyFunc func(ctx context.Context, accountID, userID, keyID string) error
|
|
BuildUserInfosForAccountFunc func(ctx context.Context, accountID, initiatorUserID string, accountUsers []*types.User) (map[string]*types.UserInfo, error)
|
|
GetStoreFunc func() store.Store
|
|
UpdateToPrimaryAccountFunc func(ctx context.Context, accountId string) error
|
|
GetOwnerInfoFunc func(ctx context.Context, accountID string) (*types.UserInfo, error)
|
|
GetCurrentUserInfoFunc func(ctx context.Context, userAuth auth.UserAuth) (*users.UserInfoWithPermissions, error)
|
|
GetAccountMetaFunc func(ctx context.Context, accountID, userID string) (*types.AccountMeta, error)
|
|
GetAccountOnboardingFunc func(ctx context.Context, accountID, userID string) (*types.AccountOnboarding, error)
|
|
UpdateAccountOnboardingFunc func(ctx context.Context, accountID, userID string, onboarding *types.AccountOnboarding) (*types.AccountOnboarding, error)
|
|
GetOrCreateAccountByPrivateDomainFunc func(ctx context.Context, initiatorId, domain string) (*types.Account, bool, error)
|
|
|
|
AllowSyncFunc func(string, uint64) bool
|
|
TrackCertificateChallengesFunc func(ctx context.Context, accountID, peerID string, streamStart time.Time)
|
|
UpdateAccountPeersFunc func(ctx context.Context, accountID string, reason types.UpdateReason)
|
|
ExpandAndUpdateAffectedFunc func(ctx context.Context, accountID string, snap *affectedpeers.Snapshot, change affectedpeers.Change)
|
|
BufferUpdateAccountPeersFunc func(ctx context.Context, accountID string, reason types.UpdateReason)
|
|
RecalculateNetworkMapCacheFunc func(ctx context.Context, accountId string) error
|
|
|
|
GetIdentityProviderFunc func(ctx context.Context, accountID, idpID, userID string) (*types.IdentityProvider, error)
|
|
GetIdentityProvidersFunc func(ctx context.Context, accountID, userID string) ([]*types.IdentityProvider, error)
|
|
CreateIdentityProviderFunc func(ctx context.Context, accountID, userID string, idp *types.IdentityProvider) (*types.IdentityProvider, error)
|
|
UpdateIdentityProviderFunc func(ctx context.Context, accountID, idpID, userID string, idp *types.IdentityProvider) (*types.IdentityProvider, error)
|
|
DeleteIdentityProviderFunc func(ctx context.Context, accountID, idpID, userID string) error
|
|
CreatePeerJobFunc func(ctx context.Context, accountID, peerID, userID string, job *types.Job) error
|
|
GetAllPeerJobsFunc func(ctx context.Context, accountID, userID, peerID string) ([]*types.Job, error)
|
|
GetPeerJobByIDFunc func(ctx context.Context, accountID, userID, peerID, jobID string) (*types.Job, error)
|
|
CreateUserInviteFunc func(ctx context.Context, accountID, initiatorUserID string, invite *types.UserInfo, expiresIn int) (*types.UserInvite, error)
|
|
AcceptUserInviteFunc func(ctx context.Context, token, password string) error
|
|
RegenerateUserInviteFunc func(ctx context.Context, accountID, initiatorUserID, inviteID string, expiresIn int) (*types.UserInvite, error)
|
|
GetUserInviteInfoFunc func(ctx context.Context, token string) (*types.UserInviteInfo, error)
|
|
ListUserInvitesFunc func(ctx context.Context, accountID, initiatorUserID string) ([]*types.UserInvite, error)
|
|
DeleteUserInviteFunc func(ctx context.Context, accountID, initiatorUserID, inviteID string) error
|
|
}
|
|
|
|
func (am *MockAccountManager) SetServiceManager(serviceManager service.Manager) {
|
|
// Mock implementation - no-op
|
|
}
|
|
|
|
func (am *MockAccountManager) CreatePeerJob(ctx context.Context, accountID, peerID, userID string, job *types.Job) error {
|
|
if am.CreatePeerJobFunc != nil {
|
|
return am.CreatePeerJobFunc(ctx, accountID, peerID, userID, job)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method CreatePeerJob is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) GetAllPeerJobs(ctx context.Context, accountID, userID, peerID string) ([]*types.Job, error) {
|
|
if am.GetAllPeerJobsFunc != nil {
|
|
return am.GetAllPeerJobsFunc(ctx, accountID, userID, peerID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAllPeerJobs is not implemented")
|
|
}
|
|
func (am *MockAccountManager) GetPeerJobByID(ctx context.Context, accountID, userID, peerID, jobID string) (*types.Job, error) {
|
|
if am.GetPeerJobByIDFunc != nil {
|
|
return am.GetPeerJobByIDFunc(ctx, accountID, userID, peerID, jobID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPeerJobByID is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) CreateGroup(ctx context.Context, accountID, userID string, group *types.Group) error {
|
|
if am.SaveGroupFunc != nil {
|
|
return am.SaveGroupFunc(ctx, accountID, userID, group, true)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method CreateGroup is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) UpdateGroup(ctx context.Context, accountID, userID string, group *types.Group) error {
|
|
if am.SaveGroupFunc != nil {
|
|
return am.SaveGroupFunc(ctx, accountID, userID, group, false)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method UpdateGroup is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) CreateGroups(ctx context.Context, accountID, userID string, newGroups []*types.Group) error {
|
|
if am.SaveGroupsFunc != nil {
|
|
return am.SaveGroupsFunc(ctx, accountID, userID, newGroups, true)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method CreateGroups is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) UpdateGroups(ctx context.Context, accountID, userID string, newGroups []*types.Group) error {
|
|
if am.SaveGroupsFunc != nil {
|
|
return am.SaveGroupsFunc(ctx, accountID, userID, newGroups, false)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method UpdateGroups is not implemented")
|
|
}
|
|
|
|
// TrackCertificateChallenges mocks TrackCertificateChallenges of the account manager.
|
|
func (am *MockAccountManager) TrackCertificateChallenges(ctx context.Context, accountID, peerID string, streamStart time.Time) {
|
|
if am.TrackCertificateChallengesFunc != nil {
|
|
am.TrackCertificateChallengesFunc(ctx, accountID, peerID, streamStart)
|
|
}
|
|
}
|
|
|
|
// UntrackCertificateChallenges mocks UntrackCertificateChallenges of the account manager.
|
|
func (am *MockAccountManager) UntrackCertificateChallenges(string, string, time.Time) {}
|
|
|
|
func (am *MockAccountManager) UpdateAccountPeers(ctx context.Context, accountID string, reason types.UpdateReason) {
|
|
if am.UpdateAccountPeersFunc != nil {
|
|
am.UpdateAccountPeersFunc(ctx, accountID, reason)
|
|
}
|
|
}
|
|
|
|
func (am *MockAccountManager) ExpandAndUpdateAffected(ctx context.Context, accountID string, snap *affectedpeers.Snapshot, change affectedpeers.Change) {
|
|
if am.ExpandAndUpdateAffectedFunc != nil {
|
|
am.ExpandAndUpdateAffectedFunc(ctx, accountID, snap, change)
|
|
}
|
|
}
|
|
|
|
func (am *MockAccountManager) BufferUpdateAccountPeers(ctx context.Context, accountID string, reason types.UpdateReason) {
|
|
if am.BufferUpdateAccountPeersFunc != nil {
|
|
am.BufferUpdateAccountPeersFunc(ctx, accountID, reason)
|
|
}
|
|
}
|
|
|
|
func (am *MockAccountManager) DeleteSetupKey(ctx context.Context, accountID, userID, keyID string) error {
|
|
if am.DeleteSetupKeyFunc != nil {
|
|
return am.DeleteSetupKeyFunc(ctx, accountID, userID, keyID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeleteSetupKey is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) SyncAndMarkPeer(ctx context.Context, accountID string, peerPubKey string, meta nbpeer.PeerSystemMeta, realIP net.IP, syncTime time.Time) (*nbpeer.Peer, *types.NetworkMap, []*nmdata.PostureChecks, int64, error) {
|
|
if am.SyncAndMarkPeerFunc != nil {
|
|
return am.SyncAndMarkPeerFunc(ctx, accountID, peerPubKey, meta, realIP, syncTime)
|
|
}
|
|
return nil, nil, nil, 0, status.Errorf(codes.Unimplemented, "method MarkPeerConnected is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) OnPeerDisconnected(ctx context.Context, accountID string, peerPubKey string, streamStartTime time.Time) error {
|
|
// Mirror DefaultAccountManager.OnPeerDisconnected: drive the fencing
|
|
// hook so tests that inject MarkPeerDisconnectedFunc actually observe
|
|
// disconnect events. Falls through to nil when no hook is set, which
|
|
// is the original behaviour.
|
|
if am.MarkPeerDisconnectedFunc != nil {
|
|
return am.MarkPeerDisconnectedFunc(ctx, peerPubKey, accountID, streamStartTime.UnixNano())
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (am *MockAccountManager) GetValidatedPeers(ctx context.Context, accountID string) (map[string]struct{}, map[string]string, error) {
|
|
account, err := am.GetAccountFunc(ctx, accountID)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
approvedPeers := make(map[string]struct{})
|
|
for id := range account.Peers {
|
|
approvedPeers[id] = struct{}{}
|
|
}
|
|
return approvedPeers, nil, nil
|
|
}
|
|
|
|
// GetGroup mock implementation of GetGroup from server.AccountManager interface
|
|
func (am *MockAccountManager) GetGroup(ctx context.Context, accountId, groupID, userID string) (*types.Group, error) {
|
|
if am.GetGroupFunc != nil {
|
|
return am.GetGroupFunc(ctx, accountId, groupID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetGroup is not implemented")
|
|
}
|
|
|
|
// GetAllGroups mock implementation of GetAllGroups from server.AccountManager interface
|
|
func (am *MockAccountManager) GetAllGroups(ctx context.Context, accountID, userID string) ([]*types.Group, error) {
|
|
if am.GetAllGroupsFunc != nil {
|
|
return am.GetAllGroupsFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAllGroups is not implemented")
|
|
}
|
|
|
|
// GetUsersFromAccount mock implementation of GetUsersFromAccount from server.AccountManager interface
|
|
func (am *MockAccountManager) GetUsersFromAccount(ctx context.Context, accountID string, userID string) (map[string]*types.UserInfo, error) {
|
|
if am.GetUsersFromAccountFunc != nil {
|
|
return am.GetUsersFromAccountFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetUsersFromAccount is not implemented")
|
|
}
|
|
|
|
// DeletePeer mock implementation of DeletePeer from server.AccountManager interface
|
|
func (am *MockAccountManager) DeletePeer(ctx context.Context, accountID, peerID, userID string) error {
|
|
if am.DeletePeerFunc != nil {
|
|
return am.DeletePeerFunc(ctx, accountID, peerID, userID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeletePeer is not implemented")
|
|
}
|
|
|
|
// GetOrCreateAccountByUser mock implementation of GetOrCreateAccountByUser from server.AccountManager interface
|
|
func (am *MockAccountManager) GetOrCreateAccountByUser(
|
|
ctx context.Context, userAuth auth.UserAuth,
|
|
) (*types.Account, error) {
|
|
if am.GetOrCreateAccountByUserFunc != nil {
|
|
return am.GetOrCreateAccountByUserFunc(ctx, userAuth)
|
|
}
|
|
return nil, status.Errorf(
|
|
codes.Unimplemented,
|
|
"method GetOrCreateAccountByUser is not implemented",
|
|
)
|
|
}
|
|
|
|
// CreateSetupKey mock implementation of CreateSetupKey from server.AccountManager interface
|
|
func (am *MockAccountManager) CreateSetupKey(
|
|
ctx context.Context,
|
|
accountID string,
|
|
keyName string,
|
|
keyType types.SetupKeyType,
|
|
expiresIn time.Duration,
|
|
autoGroups []string,
|
|
usageLimit int,
|
|
userID string,
|
|
ephemeral bool,
|
|
allowExtraDNSLabels bool,
|
|
) (*types.SetupKey, error) {
|
|
if am.CreateSetupKeyFunc != nil {
|
|
return am.CreateSetupKeyFunc(ctx, accountID, keyName, keyType, expiresIn, autoGroups, usageLimit, userID, ephemeral, allowExtraDNSLabels)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method CreateSetupKey is not implemented")
|
|
}
|
|
|
|
// AccountExists mock implementation of AccountExists from server.AccountManager interface
|
|
func (am *MockAccountManager) AccountExists(ctx context.Context, accountID string) (bool, error) {
|
|
if am.AccountExistsFunc != nil {
|
|
return am.AccountExistsFunc(ctx, accountID)
|
|
}
|
|
return false, status.Errorf(codes.Unimplemented, "method AccountExists is not implemented")
|
|
}
|
|
|
|
// GetAccountIDByUserID mock implementation of GetAccountIDByUserID from server.AccountManager interface
|
|
func (am *MockAccountManager) GetAccountIDByUserID(ctx context.Context, userAuth auth.UserAuth) (string, error) {
|
|
if am.GetAccountIDByUserIdFunc != nil {
|
|
return am.GetAccountIDByUserIdFunc(ctx, userAuth)
|
|
}
|
|
return "", status.Errorf(
|
|
codes.Unimplemented,
|
|
"method GetAccountIDByUserID is not implemented",
|
|
)
|
|
}
|
|
|
|
// MarkPeerConnected mock implementation of MarkPeerConnected from server.AccountManager interface
|
|
func (am *MockAccountManager) MarkPeerConnected(ctx context.Context, peerKey string, accountID string, sessionStartedAt int64, nmap *types.NetworkMap) error {
|
|
if am.MarkPeerConnectedFunc != nil {
|
|
return am.MarkPeerConnectedFunc(ctx, peerKey, accountID, sessionStartedAt, nmap)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method MarkPeerConnected is not implemented")
|
|
}
|
|
|
|
// MarkPeerDisconnected mock implementation of MarkPeerDisconnected from server.AccountManager interface
|
|
func (am *MockAccountManager) MarkPeerDisconnected(ctx context.Context, peerKey string, accountID string, sessionStartedAt int64) error {
|
|
if am.MarkPeerDisconnectedFunc != nil {
|
|
return am.MarkPeerDisconnectedFunc(ctx, peerKey, accountID, sessionStartedAt)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method MarkPeerDisconnected is not implemented")
|
|
}
|
|
|
|
// DeleteAccount mock implementation of DeleteAccount from server.AccountManager interface
|
|
func (am *MockAccountManager) DeleteAccount(ctx context.Context, accountID, userID string) error {
|
|
if am.DeleteAccountFunc != nil {
|
|
return am.DeleteAccountFunc(ctx, accountID, userID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeleteAccount is not implemented")
|
|
}
|
|
|
|
// CreatePAT mock implementation of GetPAT from server.AccountManager interface
|
|
func (am *MockAccountManager) CreatePAT(ctx context.Context, accountID string, initiatorUserID string, targetUserID string, name string, expiresIn int) (*types.PersonalAccessTokenGenerated, error) {
|
|
if am.CreatePATFunc != nil {
|
|
return am.CreatePATFunc(ctx, accountID, initiatorUserID, targetUserID, name, expiresIn)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method CreatePAT is not implemented")
|
|
}
|
|
|
|
// DeletePAT mock implementation of DeletePAT from server.AccountManager interface
|
|
func (am *MockAccountManager) DeletePAT(ctx context.Context, accountID string, initiatorUserID string, targetUserID string, tokenID string) error {
|
|
if am.DeletePATFunc != nil {
|
|
return am.DeletePATFunc(ctx, accountID, initiatorUserID, targetUserID, tokenID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeletePAT is not implemented")
|
|
}
|
|
|
|
// GetPAT mock implementation of GetPAT from server.AccountManager interface
|
|
func (am *MockAccountManager) GetPAT(ctx context.Context, accountID string, initiatorUserID string, targetUserID string, tokenID string) (*types.PersonalAccessToken, error) {
|
|
if am.GetPATFunc != nil {
|
|
return am.GetPATFunc(ctx, accountID, initiatorUserID, targetUserID, tokenID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPAT is not implemented")
|
|
}
|
|
|
|
// GetAllPATs mock implementation of GetAllPATs from server.AccountManager interface
|
|
func (am *MockAccountManager) GetAllPATs(ctx context.Context, accountID string, initiatorUserID string, targetUserID string) ([]*types.PersonalAccessToken, error) {
|
|
if am.GetAllPATsFunc != nil {
|
|
return am.GetAllPATsFunc(ctx, accountID, initiatorUserID, targetUserID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAllPATs is not implemented")
|
|
}
|
|
|
|
// GetNetworkMap mock implementation of GetNetworkMap from server.AccountManager interface
|
|
func (am *MockAccountManager) GetNetworkMap(ctx context.Context, peerKey string) (*types.NetworkMap, error) {
|
|
if am.GetNetworkMapFunc != nil {
|
|
return am.GetNetworkMapFunc(ctx, peerKey)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetNetworkMap is not implemented")
|
|
}
|
|
|
|
// GetPeerNetwork mock implementation of GetPeerNetwork from server.AccountManager interface
|
|
func (am *MockAccountManager) GetPeerNetwork(ctx context.Context, peerKey string) (*types.Network, error) {
|
|
if am.GetPeerNetworkFunc != nil {
|
|
return am.GetPeerNetworkFunc(ctx, peerKey)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPeerNetwork is not implemented")
|
|
}
|
|
|
|
// AddPeer mock implementation of AddPeer from server.AccountManager interface
|
|
func (am *MockAccountManager) AddPeer(
|
|
ctx context.Context,
|
|
accountID string,
|
|
setupKey string,
|
|
userId string,
|
|
peer *nbpeer.Peer,
|
|
temporary bool,
|
|
) (*nbpeer.Peer, *types.Network, []*nmdata.PostureChecks, bool, error) {
|
|
if am.AddPeerFunc != nil {
|
|
return am.AddPeerFunc(ctx, accountID, setupKey, userId, peer, temporary)
|
|
}
|
|
return nil, nil, nil, false, status.Errorf(codes.Unimplemented, "method AddPeer is not implemented")
|
|
}
|
|
|
|
// GetGroupByName mock implementation of GetGroupByName from server.AccountManager interface
|
|
func (am *MockAccountManager) GetGroupByName(ctx context.Context, groupName, accountID, userID string) (*types.Group, error) {
|
|
if am.GetGroupByNameFunc != nil {
|
|
return am.GetGroupByNameFunc(ctx, groupName, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetGroupByName is not implemented")
|
|
}
|
|
|
|
// SaveGroup mock implementation of SaveGroup from server.AccountManager interface
|
|
func (am *MockAccountManager) SaveGroup(ctx context.Context, accountID, userID string, group *types.Group, create bool) error {
|
|
if am.SaveGroupFunc != nil {
|
|
return am.SaveGroupFunc(ctx, accountID, userID, group, create)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method SaveGroup is not implemented")
|
|
}
|
|
|
|
// SaveGroups mock implementation of SaveGroups from server.AccountManager interface
|
|
func (am *MockAccountManager) SaveGroups(ctx context.Context, accountID, userID string, groups []*types.Group, create bool) error {
|
|
if am.SaveGroupsFunc != nil {
|
|
return am.SaveGroupsFunc(ctx, accountID, userID, groups, create)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method SaveGroups is not implemented")
|
|
}
|
|
|
|
// DeleteGroup mock implementation of DeleteGroup from server.AccountManager interface
|
|
func (am *MockAccountManager) DeleteGroup(ctx context.Context, accountId, userId, groupID string) error {
|
|
if am.DeleteGroupFunc != nil {
|
|
return am.DeleteGroupFunc(ctx, accountId, userId, groupID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeleteGroup is not implemented")
|
|
}
|
|
|
|
// DeleteGroups mock implementation of DeleteGroups from server.AccountManager interface
|
|
func (am *MockAccountManager) DeleteGroups(ctx context.Context, accountId, userId string, groupIDs []string) error {
|
|
if am.DeleteGroupsFunc != nil {
|
|
return am.DeleteGroupsFunc(ctx, accountId, userId, groupIDs)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeleteGroups is not implemented")
|
|
}
|
|
|
|
// GroupAddPeer mock implementation of GroupAddPeer from server.AccountManager interface
|
|
func (am *MockAccountManager) GroupAddPeer(ctx context.Context, accountID, groupID, peerID string) error {
|
|
if am.GroupAddPeerFunc != nil {
|
|
return am.GroupAddPeerFunc(ctx, accountID, groupID, peerID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method GroupAddPeer is not implemented")
|
|
}
|
|
|
|
// GroupDeletePeer mock implementation of GroupDeletePeer from server.AccountManager interface
|
|
func (am *MockAccountManager) GroupDeletePeer(ctx context.Context, accountID, groupID, peerID string) error {
|
|
if am.GroupDeletePeerFunc != nil {
|
|
return am.GroupDeletePeerFunc(ctx, accountID, groupID, peerID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method GroupDeletePeer is not implemented")
|
|
}
|
|
|
|
// DeleteRule mock implementation of DeleteRule from server.AccountManager interface
|
|
func (am *MockAccountManager) DeleteRule(ctx context.Context, accountID, ruleID, userID string) error {
|
|
if am.DeleteRuleFunc != nil {
|
|
return am.DeleteRuleFunc(ctx, accountID, ruleID, userID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeletePeerRule is not implemented")
|
|
}
|
|
|
|
// GetPolicy mock implementation of GetPolicy from server.AccountManager interface
|
|
func (am *MockAccountManager) GetPolicy(ctx context.Context, accountID, policyID, userID string) (*types.Policy, error) {
|
|
if am.GetPolicyFunc != nil {
|
|
return am.GetPolicyFunc(ctx, 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(ctx context.Context, accountID, userID string, policy *types.Policy, create bool) (*types.Policy, error) {
|
|
if am.SavePolicyFunc != nil {
|
|
return am.SavePolicyFunc(ctx, accountID, userID, policy, create)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method SavePolicy is not implemented")
|
|
}
|
|
|
|
// DeletePolicy mock implementation of DeletePolicy from server.AccountManager interface
|
|
func (am *MockAccountManager) DeletePolicy(ctx context.Context, accountID, policyID, userID string) error {
|
|
if am.DeletePolicyFunc != nil {
|
|
return am.DeletePolicyFunc(ctx, 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(ctx context.Context, accountID, userID string) ([]*types.Policy, error) {
|
|
if am.ListPoliciesFunc != nil {
|
|
return am.ListPoliciesFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method ListPolicies is not implemented")
|
|
}
|
|
|
|
// UpdatePeerMeta mock implementation of UpdatePeerMeta from server.AccountManager interface
|
|
func (am *MockAccountManager) UpdatePeerMeta(ctx context.Context, peerID string, meta nbpeer.PeerSystemMeta) error {
|
|
if am.UpdatePeerMetaFunc != nil {
|
|
return am.UpdatePeerMetaFunc(ctx, peerID, meta)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method UpdatePeerMeta is not implemented")
|
|
}
|
|
|
|
// GetUser mock implementation of GetUser from server.AccountManager interface
|
|
func (am *MockAccountManager) GetUserFromUserAuth(ctx context.Context, userAuth auth.UserAuth) (*types.User, error) {
|
|
if am.GetUserFromUserAuthFunc != nil {
|
|
return am.GetUserFromUserAuthFunc(ctx, userAuth)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetUserFromUserAuth is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) ListUsers(ctx context.Context, accountID string) ([]*types.User, error) {
|
|
if am.ListUsersFunc != nil {
|
|
return am.ListUsersFunc(ctx, accountID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method ListUsers is not implemented")
|
|
}
|
|
|
|
// UpdatePeer mocks UpdatePeerFunc function of the account manager
|
|
func (am *MockAccountManager) UpdatePeer(ctx context.Context, accountID, userID string, peer *nbpeer.Peer) (*nbpeer.Peer, error) {
|
|
if am.UpdatePeerFunc != nil {
|
|
return am.UpdatePeerFunc(ctx, accountID, userID, peer)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method UpdatePeer is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) UpdatePeerIP(ctx context.Context, accountID, userID, peerID string, newIP netip.Addr) error {
|
|
if am.UpdatePeerIPFunc != nil {
|
|
return am.UpdatePeerIPFunc(ctx, accountID, userID, peerID, newIP)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method UpdatePeerIP is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) UpdatePeerIPv6(ctx context.Context, accountID, userID, peerID string, newIPv6 netip.Addr) error {
|
|
if am.UpdatePeerIPv6Func != nil {
|
|
return am.UpdatePeerIPv6Func(ctx, accountID, userID, peerID, newIPv6)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method UpdatePeerIPv6 is not implemented")
|
|
}
|
|
|
|
// CreateRoute mock implementation of CreateRoute from server.AccountManager interface
|
|
func (am *MockAccountManager) CreateRoute(ctx context.Context, accountID string, prefix netip.Prefix, networkType route.NetworkType, domains domain.List, peerID string, peerGroupIDs []string, description string, netID route.NetID, masquerade bool, metric int, groups, accessControlGroupID []string, enabled bool, userID string, keepRoute bool, isSelected bool) (*route.Route, error) {
|
|
if am.CreateRouteFunc != nil {
|
|
return am.CreateRouteFunc(ctx, accountID, prefix, networkType, domains, peerID, peerGroupIDs, description, netID, masquerade, metric, groups, accessControlGroupID, enabled, userID, keepRoute, isSelected)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method CreateRoute is not implemented")
|
|
}
|
|
|
|
// GetRoute mock implementation of GetRoute from server.AccountManager interface
|
|
func (am *MockAccountManager) GetRoute(ctx context.Context, accountID string, routeID route.ID, userID string) (*route.Route, error) {
|
|
if am.GetRouteFunc != nil {
|
|
return am.GetRouteFunc(ctx, accountID, routeID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetRoute is not implemented")
|
|
}
|
|
|
|
// SaveRoute mock implementation of SaveRoute from server.AccountManager interface
|
|
func (am *MockAccountManager) SaveRoute(ctx context.Context, accountID string, userID string, route *route.Route) error {
|
|
if am.SaveRouteFunc != nil {
|
|
return am.SaveRouteFunc(ctx, accountID, userID, route)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method SaveRoute is not implemented")
|
|
}
|
|
|
|
// DeleteRoute mock implementation of DeleteRoute from server.AccountManager interface
|
|
func (am *MockAccountManager) DeleteRoute(ctx context.Context, accountID string, routeID route.ID, userID string) error {
|
|
if am.DeleteRouteFunc != nil {
|
|
return am.DeleteRouteFunc(ctx, accountID, routeID, userID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeleteRoute is not implemented")
|
|
}
|
|
|
|
// ListRoutes mock implementation of ListRoutes from server.AccountManager interface
|
|
func (am *MockAccountManager) ListRoutes(ctx context.Context, accountID, userID string) ([]*route.Route, error) {
|
|
if am.ListRoutesFunc != nil {
|
|
return am.ListRoutesFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method ListRoutes is not implemented")
|
|
}
|
|
|
|
// SaveSetupKey mocks SaveSetupKey of the AccountManager interface
|
|
func (am *MockAccountManager) SaveSetupKey(ctx context.Context, accountID string, key *types.SetupKey, userID string) (*types.SetupKey, error) {
|
|
if am.SaveSetupKeyFunc != nil {
|
|
return am.SaveSetupKeyFunc(ctx, accountID, key, userID)
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method SaveSetupKey is not implemented")
|
|
}
|
|
|
|
// GetSetupKey mocks GetSetupKey of the AccountManager interface
|
|
func (am *MockAccountManager) GetSetupKey(ctx context.Context, accountID, userID, keyID string) (*types.SetupKey, error) {
|
|
if am.GetSetupKeyFunc != nil {
|
|
return am.GetSetupKeyFunc(ctx, accountID, userID, keyID)
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetSetupKey is not implemented")
|
|
}
|
|
|
|
// ListSetupKeys mocks ListSetupKeys of the AccountManager interface
|
|
func (am *MockAccountManager) ListSetupKeys(ctx context.Context, accountID, userID string) ([]*types.SetupKey, error) {
|
|
if am.ListSetupKeysFunc != nil {
|
|
return am.ListSetupKeysFunc(ctx, accountID, userID)
|
|
}
|
|
|
|
return nil, status.Errorf(codes.Unimplemented, "method ListSetupKeys is not implemented")
|
|
}
|
|
|
|
// SaveUser mocks SaveUser of the AccountManager interface
|
|
func (am *MockAccountManager) SaveUser(ctx context.Context, accountID, userID string, user *types.User) (*types.UserInfo, error) {
|
|
if am.SaveUserFunc != nil {
|
|
return am.SaveUserFunc(ctx, accountID, userID, user)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method SaveUser is not implemented")
|
|
}
|
|
|
|
// SaveOrAddUser mocks SaveOrAddUser of the AccountManager interface
|
|
func (am *MockAccountManager) SaveOrAddUser(ctx context.Context, accountID, userID string, user *types.User, addIfNotExists bool) (*types.UserInfo, error) {
|
|
if am.SaveOrAddUserFunc != nil {
|
|
return am.SaveOrAddUserFunc(ctx, accountID, userID, user, addIfNotExists)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method SaveOrAddUser is not implemented")
|
|
}
|
|
|
|
// SaveOrAddUsers mocks SaveOrAddUsers of the AccountManager interface
|
|
func (am *MockAccountManager) SaveOrAddUsers(ctx context.Context, accountID, userID string, users []*types.User, addIfNotExists bool) ([]*types.UserInfo, error) {
|
|
if am.SaveOrAddUsersFunc != nil {
|
|
return am.SaveOrAddUsersFunc(ctx, accountID, userID, users, addIfNotExists)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method SaveOrAddUsers is not implemented")
|
|
}
|
|
|
|
// DeleteUser mocks DeleteUser of the AccountManager interface
|
|
func (am *MockAccountManager) DeleteUser(ctx context.Context, accountID string, initiatorUserID string, targetUserID string) error {
|
|
if am.DeleteUserFunc != nil {
|
|
return am.DeleteUserFunc(ctx, accountID, initiatorUserID, targetUserID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeleteUser is not implemented")
|
|
}
|
|
|
|
// DeleteRegularUsers mocks DeleteRegularUsers of the AccountManager interface
|
|
func (am *MockAccountManager) DeleteRegularUsers(ctx context.Context, accountID, initiatorUserID string, targetUserIDs []string, userInfos map[string]*types.UserInfo) error {
|
|
if am.DeleteRegularUsersFunc != nil {
|
|
return am.DeleteRegularUsersFunc(ctx, accountID, initiatorUserID, targetUserIDs, userInfos)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeleteRegularUsers is not implemented")
|
|
}
|
|
|
|
// UpdateUserPassword mocks UpdateUserPassword of the AccountManager interface
|
|
func (am *MockAccountManager) UpdateUserPassword(ctx context.Context, accountID, currentUserID, targetUserID string, oldPassword, newPassword string) error {
|
|
if am.UpdateUserPasswordFunc != nil {
|
|
return am.UpdateUserPasswordFunc(ctx, accountID, currentUserID, targetUserID, oldPassword, newPassword)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method UpdateUserPassword is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) InviteUser(ctx context.Context, accountID string, initiatorUserID string, targetUserID string) error {
|
|
if am.InviteUserFunc != nil {
|
|
return am.InviteUserFunc(ctx, accountID, initiatorUserID, targetUserID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method InviteUser is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) ApproveUser(ctx context.Context, accountID, initiatorUserID, targetUserID string) (*types.UserInfo, error) {
|
|
if am.ApproveUserFunc != nil {
|
|
return am.ApproveUserFunc(ctx, accountID, initiatorUserID, targetUserID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method ApproveUser is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) RejectUser(ctx context.Context, accountID, initiatorUserID, targetUserID string) error {
|
|
if am.RejectUserFunc != nil {
|
|
return am.RejectUserFunc(ctx, accountID, initiatorUserID, targetUserID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method RejectUser is not implemented")
|
|
}
|
|
|
|
// GetNameServerGroup mocks GetNameServerGroup of the AccountManager interface
|
|
func (am *MockAccountManager) GetNameServerGroup(ctx context.Context, accountID, userID, nsGroupID string) (*nbdns.NameServerGroup, error) {
|
|
if am.GetNameServerGroupFunc != nil {
|
|
return am.GetNameServerGroupFunc(ctx, accountID, userID, nsGroupID)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
// CreateNameServerGroup mocks CreateNameServerGroup of the AccountManager interface
|
|
func (am *MockAccountManager) CreateNameServerGroup(ctx context.Context, accountID string, name, description string, nameServerList []nbdns.NameServer, groups []string, primary bool, domains []string, enabled bool, userID string, searchDomainsEnabled bool) (*nbdns.NameServerGroup, error) {
|
|
if am.CreateNameServerGroupFunc != nil {
|
|
return am.CreateNameServerGroupFunc(ctx, accountID, name, description, nameServerList, groups, primary, domains, enabled, userID, searchDomainsEnabled)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
// SaveNameServerGroup mocks SaveNameServerGroup of the AccountManager interface
|
|
func (am *MockAccountManager) SaveNameServerGroup(ctx context.Context, accountID, userID string, nsGroupToSave *nbdns.NameServerGroup) error {
|
|
if am.SaveNameServerGroupFunc != nil {
|
|
return am.SaveNameServerGroupFunc(ctx, accountID, userID, nsGroupToSave)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// DeleteNameServerGroup mocks DeleteNameServerGroup of the AccountManager interface
|
|
func (am *MockAccountManager) DeleteNameServerGroup(ctx context.Context, accountID, nsGroupID, userID string) error {
|
|
if am.DeleteNameServerGroupFunc != nil {
|
|
return am.DeleteNameServerGroupFunc(ctx, accountID, nsGroupID, userID)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ListNameServerGroups mocks ListNameServerGroups of the AccountManager interface
|
|
func (am *MockAccountManager) ListNameServerGroups(ctx context.Context, accountID string, userID string) ([]*nbdns.NameServerGroup, error) {
|
|
if am.ListNameServerGroupsFunc != nil {
|
|
return am.ListNameServerGroupsFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
// CreateUser mocks CreateUser of the AccountManager interface
|
|
func (am *MockAccountManager) CreateUser(ctx context.Context, accountID, userID string, invite *types.UserInfo) (*types.UserInfo, error) {
|
|
if am.CreateUserFunc != nil {
|
|
return am.CreateUserFunc(ctx, accountID, userID, invite)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method CreateUser is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) CreateUserInvite(ctx context.Context, accountID, initiatorUserID string, invite *types.UserInfo, expiresIn int) (*types.UserInvite, error) {
|
|
if am.CreateUserInviteFunc != nil {
|
|
return am.CreateUserInviteFunc(ctx, accountID, initiatorUserID, invite, expiresIn)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method CreateUserInvite is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) AcceptUserInvite(ctx context.Context, token, password string) error {
|
|
if am.AcceptUserInviteFunc != nil {
|
|
return am.AcceptUserInviteFunc(ctx, token, password)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method AcceptUserInvite is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) RegenerateUserInvite(ctx context.Context, accountID, initiatorUserID, inviteID string, expiresIn int) (*types.UserInvite, error) {
|
|
if am.RegenerateUserInviteFunc != nil {
|
|
return am.RegenerateUserInviteFunc(ctx, accountID, initiatorUserID, inviteID, expiresIn)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method RegenerateUserInvite is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) GetUserInviteInfo(ctx context.Context, token string) (*types.UserInviteInfo, error) {
|
|
if am.GetUserInviteInfoFunc != nil {
|
|
return am.GetUserInviteInfoFunc(ctx, token)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetUserInviteInfo is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) ListUserInvites(ctx context.Context, accountID, initiatorUserID string) ([]*types.UserInvite, error) {
|
|
if am.ListUserInvitesFunc != nil {
|
|
return am.ListUserInvitesFunc(ctx, accountID, initiatorUserID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method ListUserInvites is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) DeleteUserInvite(ctx context.Context, accountID, initiatorUserID, inviteID string) error {
|
|
if am.DeleteUserInviteFunc != nil {
|
|
return am.DeleteUserInviteFunc(ctx, accountID, initiatorUserID, inviteID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeleteUserInvite is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) GetAccountIDFromUserAuth(ctx context.Context, userAuth auth.UserAuth) (string, string, error) {
|
|
if am.GetAccountIDFromUserAuthFunc != nil {
|
|
return am.GetAccountIDFromUserAuthFunc(ctx, userAuth)
|
|
}
|
|
return "", "", status.Errorf(codes.Unimplemented, "method GetAccountIDFromUserAuth is not implemented")
|
|
}
|
|
|
|
// GetPeers mocks GetPeers of the AccountManager interface
|
|
func (am *MockAccountManager) GetPeers(ctx context.Context, accountID, userID, nameFilter, ipFilter, macFilter string) ([]*nbpeer.Peer, error) {
|
|
if am.GetPeersFunc != nil {
|
|
return am.GetPeersFunc(ctx, accountID, userID, nameFilter, ipFilter, macFilter)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPeers is not implemented")
|
|
}
|
|
|
|
// GetDNSDomain mocks GetDNSDomain of the AccountManager interface
|
|
func (am *MockAccountManager) GetDNSDomain(settings *types.Settings) string {
|
|
if am.GetDNSDomainFunc != nil {
|
|
return am.GetDNSDomainFunc(settings)
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// GetEvents mocks GetEvents of the AccountManager interface
|
|
func (am *MockAccountManager) GetEvents(ctx context.Context, accountID, userID string) ([]*activity.Event, error) {
|
|
if am.GetEventsFunc != nil {
|
|
return am.GetEventsFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetEvents is not implemented")
|
|
}
|
|
|
|
// GetDNSSettings mocks GetDNSSettings of the AccountManager interface
|
|
func (am *MockAccountManager) GetDNSSettings(ctx context.Context, accountID string, userID string) (*types.DNSSettings, error) {
|
|
if am.GetDNSSettingsFunc != nil {
|
|
return am.GetDNSSettingsFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetDNSSettings is not implemented")
|
|
}
|
|
|
|
// SaveDNSSettings mocks SaveDNSSettings of the AccountManager interface
|
|
func (am *MockAccountManager) SaveDNSSettings(ctx context.Context, accountID string, userID string, dnsSettingsToSave *types.DNSSettings) error {
|
|
if am.SaveDNSSettingsFunc != nil {
|
|
return am.SaveDNSSettingsFunc(ctx, accountID, userID, dnsSettingsToSave)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method SaveDNSSettings is not implemented")
|
|
}
|
|
|
|
// GetPeer mocks GetPeer of the AccountManager interface
|
|
func (am *MockAccountManager) GetPeer(ctx context.Context, accountID, peerID, userID string) (*nbpeer.Peer, error) {
|
|
if am.GetPeerFunc != nil {
|
|
return am.GetPeerFunc(ctx, accountID, peerID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPeer is not implemented")
|
|
}
|
|
|
|
// UpdateAccountSettings mocks UpdateAccountSettings of the AccountManager interface
|
|
func (am *MockAccountManager) UpdateAccountSettings(ctx context.Context, accountID, userID string, newSettings *types.Settings) (*types.Settings, error) {
|
|
if am.UpdateAccountSettingsFunc != nil {
|
|
return am.UpdateAccountSettingsFunc(ctx, accountID, userID, newSettings)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method UpdateAccountSettings is not implemented")
|
|
}
|
|
|
|
// LoginPeer mocks LoginPeer of the AccountManager interface
|
|
func (am *MockAccountManager) LoginPeer(ctx context.Context, login types.PeerLogin) (*nbpeer.Peer, *types.Network, []*nmdata.PostureChecks, bool, error) {
|
|
if am.LoginPeerFunc != nil {
|
|
return am.LoginPeerFunc(ctx, login)
|
|
}
|
|
return nil, nil, nil, false, status.Errorf(codes.Unimplemented, "method LoginPeer is not implemented")
|
|
}
|
|
|
|
// ExtendPeerSession mocks ExtendPeerSession of the AccountManager interface
|
|
func (am *MockAccountManager) ExtendPeerSession(ctx context.Context, peerPubKey, userID string) (time.Time, error) {
|
|
if am.ExtendPeerSessionFunc != nil {
|
|
return am.ExtendPeerSessionFunc(ctx, peerPubKey, userID)
|
|
}
|
|
return time.Time{}, status.Errorf(codes.Unimplemented, "method ExtendPeerSession is not implemented")
|
|
}
|
|
|
|
// SyncPeer mocks SyncPeer of the AccountManager interface
|
|
func (am *MockAccountManager) SyncPeer(ctx context.Context, sync types.PeerSync, accountID string) (*nbpeer.Peer, *types.NetworkMap, []*nmdata.PostureChecks, int64, error) {
|
|
if am.SyncPeerFunc != nil {
|
|
return am.SyncPeerFunc(ctx, sync, accountID)
|
|
}
|
|
return nil, nil, nil, 0, status.Errorf(codes.Unimplemented, "method SyncPeer is not implemented")
|
|
}
|
|
|
|
// GetAllConnectedPeers mocks GetAllConnectedPeers of the AccountManager interface
|
|
func (am *MockAccountManager) GetAllConnectedPeers() (map[string]struct{}, error) {
|
|
if am.GetAllConnectedPeersFunc != nil {
|
|
return am.GetAllConnectedPeersFunc()
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAllConnectedPeers is not implemented")
|
|
}
|
|
|
|
// HasConnectedChannel mocks HasConnectedChannel of the AccountManager interface
|
|
func (am *MockAccountManager) HasConnectedChannel(peerID string) bool {
|
|
if am.HasConnectedChannelFunc != nil {
|
|
return am.HasConnectedChannelFunc(peerID)
|
|
}
|
|
return false
|
|
}
|
|
|
|
// StoreEvent mocks StoreEvent of the AccountManager interface
|
|
func (am *MockAccountManager) StoreEvent(ctx context.Context, initiatorID, targetID, accountID string, activityID activity.ActivityDescriber, meta map[string]any) {
|
|
if am.StoreEventFunc != nil {
|
|
am.StoreEventFunc(ctx, initiatorID, targetID, accountID, activityID, meta)
|
|
}
|
|
}
|
|
|
|
// GetExternalCacheManager mocks GetExternalCacheManager of the AccountManager interface
|
|
func (am *MockAccountManager) GetExternalCacheManager() account.ExternalCacheManager {
|
|
if am.GetExternalCacheManagerFunc() != nil {
|
|
return am.GetExternalCacheManagerFunc()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetPostureChecks mocks GetPostureChecks of the AccountManager interface
|
|
func (am *MockAccountManager) GetPostureChecks(ctx context.Context, accountID, postureChecksID, userID string) (*posture.Checks, error) {
|
|
if am.GetPostureChecksFunc != nil {
|
|
return am.GetPostureChecksFunc(ctx, accountID, postureChecksID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPostureChecks is not implemented")
|
|
|
|
}
|
|
|
|
// SavePostureChecks mocks SavePostureChecks of the AccountManager interface
|
|
func (am *MockAccountManager) SavePostureChecks(ctx context.Context, accountID, userID string, postureChecks *posture.Checks, create bool) (*posture.Checks, error) {
|
|
if am.SavePostureChecksFunc != nil {
|
|
return am.SavePostureChecksFunc(ctx, accountID, userID, postureChecks, create)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method SavePostureChecks is not implemented")
|
|
}
|
|
|
|
// DeletePostureChecks mocks DeletePostureChecks of the AccountManager interface
|
|
func (am *MockAccountManager) DeletePostureChecks(ctx context.Context, accountID, postureChecksID, userID string) error {
|
|
if am.DeletePostureChecksFunc != nil {
|
|
return am.DeletePostureChecksFunc(ctx, accountID, postureChecksID, userID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeletePostureChecks is not implemented")
|
|
|
|
}
|
|
|
|
// ListPostureChecks mocks ListPostureChecks of the AccountManager interface
|
|
func (am *MockAccountManager) ListPostureChecks(ctx context.Context, accountID, userID string) ([]*posture.Checks, error) {
|
|
if am.ListPostureChecksFunc != nil {
|
|
return am.ListPostureChecksFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method ListPostureChecks is not implemented")
|
|
}
|
|
|
|
// GetIdpManager mocks GetIdpManager of the AccountManager interface
|
|
func (am *MockAccountManager) GetIdpManager() idp.Manager {
|
|
if am.GetIdpManagerFunc != nil {
|
|
return am.GetIdpManagerFunc()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UpdateIntegratedValidator mocks UpdateIntegratedApprovalGroups of the AccountManager interface
|
|
func (am *MockAccountManager) UpdateIntegratedValidator(ctx context.Context, accountID, userID, validator string, groups []string) error {
|
|
if am.UpdateIntegratedValidatorFunc != nil {
|
|
return am.UpdateIntegratedValidatorFunc(ctx, accountID, userID, validator, groups)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method UpdateIntegratedValidatorGroups is not implemented")
|
|
}
|
|
|
|
// GroupValidation mocks GroupValidation of the AccountManager interface
|
|
func (am *MockAccountManager) GroupValidation(ctx context.Context, accountId string, groups []string) (bool, error) {
|
|
if am.GroupValidationFunc != nil {
|
|
return am.GroupValidationFunc(ctx, accountId, groups)
|
|
}
|
|
return false, status.Errorf(codes.Unimplemented, "method GroupValidation is not implemented")
|
|
}
|
|
|
|
// SyncPeerMeta mocks SyncPeerMeta of the AccountManager interface
|
|
func (am *MockAccountManager) SyncPeerMeta(ctx context.Context, peerPubKey string, meta nbpeer.PeerSystemMeta, realIP net.IP) error {
|
|
if am.SyncPeerMetaFunc != nil {
|
|
return am.SyncPeerMetaFunc(ctx, peerPubKey, meta, realIP)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method SyncPeerMeta is not implemented")
|
|
}
|
|
|
|
// FindExistingPostureCheck mocks FindExistingPostureCheck of the AccountManager interface
|
|
func (am *MockAccountManager) FindExistingPostureCheck(accountID string, checks *posture.ChecksDefinition) (*posture.Checks, error) {
|
|
if am.FindExistingPostureCheckFunc != nil {
|
|
return am.FindExistingPostureCheckFunc(accountID, checks)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method FindExistingPostureCheck is not implemented")
|
|
}
|
|
|
|
// GetAccountIDForPeerKey mocks GetAccountIDForPeerKey of the AccountManager interface
|
|
func (am *MockAccountManager) GetAccountIDForPeerKey(ctx context.Context, peerKey string) (string, error) {
|
|
if am.GetAccountIDForPeerKeyFunc != nil {
|
|
return am.GetAccountIDForPeerKeyFunc(ctx, peerKey)
|
|
}
|
|
return "", status.Errorf(codes.Unimplemented, "method GetAccountIDForPeerKey is not implemented")
|
|
}
|
|
|
|
// GetAccountByID mocks GetAccountByID of the AccountManager interface
|
|
func (am *MockAccountManager) GetAccountByID(ctx context.Context, accountID string, userID string) (*types.Account, error) {
|
|
if am.GetAccountByIDFunc != nil {
|
|
return am.GetAccountByIDFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAccountByID is not implemented")
|
|
}
|
|
|
|
// GetAccountByID mocks GetAccountByID of the AccountManager interface
|
|
func (am *MockAccountManager) GetAccountMeta(ctx context.Context, accountID string, userID string) (*types.AccountMeta, error) {
|
|
if am.GetAccountMetaFunc != nil {
|
|
return am.GetAccountMetaFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAccountMeta is not implemented")
|
|
}
|
|
|
|
// GetAccountOnboarding mocks GetAccountOnboarding of the AccountManager interface
|
|
func (am *MockAccountManager) GetAccountOnboarding(ctx context.Context, accountID string, userID string) (*types.AccountOnboarding, error) {
|
|
if am.GetAccountOnboardingFunc != nil {
|
|
return am.GetAccountOnboardingFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAccountOnboarding is not implemented")
|
|
}
|
|
|
|
// UpdateAccountOnboarding mocks UpdateAccountOnboarding of the AccountManager interface
|
|
func (am *MockAccountManager) UpdateAccountOnboarding(ctx context.Context, accountID string, userID string, onboarding *types.AccountOnboarding) (*types.AccountOnboarding, error) {
|
|
if am.UpdateAccountOnboardingFunc != nil {
|
|
return am.UpdateAccountOnboardingFunc(ctx, accountID, userID, onboarding)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method UpdateAccountOnboarding is not implemented")
|
|
}
|
|
|
|
// GetUserByID mocks GetUserByID of the AccountManager interface
|
|
func (am *MockAccountManager) GetUserByID(ctx context.Context, id string) (*types.User, error) {
|
|
if am.GetUserByIDFunc != nil {
|
|
return am.GetUserByIDFunc(ctx, id)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetUserByID is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) GetAccountSettings(ctx context.Context, accountID string, userID string) (*types.Settings, error) {
|
|
if am.GetAccountSettingsFunc != nil {
|
|
return am.GetAccountSettingsFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAccountSettings is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) GetAccount(ctx context.Context, accountID string) (*types.Account, error) {
|
|
if am.GetAccountFunc != nil {
|
|
return am.GetAccountFunc(ctx, accountID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetAccount is not implemented")
|
|
}
|
|
|
|
// GetPeerGroups mocks GetPeerGroups of the AccountManager interface
|
|
func (am *MockAccountManager) GetPeerGroups(ctx context.Context, accountID, peerID string) ([]*types.Group, error) {
|
|
if am.GetPeerGroupsFunc != nil {
|
|
return am.GetPeerGroupsFunc(ctx, accountID, peerID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetPeerGroups is not implemented")
|
|
}
|
|
|
|
// BuildUserInfosForAccount mocks BuildUserInfosForAccount of the AccountManager interface
|
|
func (am *MockAccountManager) BuildUserInfosForAccount(ctx context.Context, accountID, initiatorUserID string, accountUsers []*types.User) (map[string]*types.UserInfo, error) {
|
|
if am.BuildUserInfosForAccountFunc != nil {
|
|
return am.BuildUserInfosForAccountFunc(ctx, accountID, initiatorUserID, accountUsers)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method BuildUserInfosForAccount is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) SyncUserJWTGroups(ctx context.Context, userAuth auth.UserAuth) error {
|
|
return status.Errorf(codes.Unimplemented, "method SyncUserJWTGroups is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) GetStore() store.Store {
|
|
if am.GetStoreFunc != nil {
|
|
return am.GetStoreFunc()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (am *MockAccountManager) GetOrCreateAccountByPrivateDomain(ctx context.Context, initiatorId, domain string) (*types.Account, bool, error) {
|
|
if am.GetOrCreateAccountByPrivateDomainFunc != nil {
|
|
return am.GetOrCreateAccountByPrivateDomainFunc(ctx, initiatorId, domain)
|
|
}
|
|
return nil, false, status.Errorf(codes.Unimplemented, "method GetOrCreateAccountByPrivateDomainFunc is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) UpdateToPrimaryAccount(ctx context.Context, accountId string) error {
|
|
if am.UpdateToPrimaryAccountFunc != nil {
|
|
return am.UpdateToPrimaryAccountFunc(ctx, accountId)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method UpdateToPrimaryAccount is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) GetOwnerInfo(ctx context.Context, accountId string) (*types.UserInfo, error) {
|
|
if am.GetOwnerInfoFunc != nil {
|
|
return am.GetOwnerInfoFunc(ctx, accountId)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetOwnerInfo is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) GetCurrentUserInfo(ctx context.Context, userAuth auth.UserAuth) (*users.UserInfoWithPermissions, error) {
|
|
if am.GetCurrentUserInfoFunc != nil {
|
|
return am.GetCurrentUserInfoFunc(ctx, userAuth)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetCurrentUserInfo is not implemented")
|
|
}
|
|
|
|
func (am *MockAccountManager) AllowSync(key string, hash uint64) bool {
|
|
if am.AllowSyncFunc != nil {
|
|
return am.AllowSyncFunc(key, hash)
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (am *MockAccountManager) RecalculateNetworkMapCache(ctx context.Context, accountID string) error {
|
|
if am.RecalculateNetworkMapCacheFunc != nil {
|
|
return am.RecalculateNetworkMapCacheFunc(ctx, accountID)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (am *MockAccountManager) GetUserIDByPeerKey(ctx context.Context, peerKey string) (string, error) {
|
|
return "something", nil
|
|
}
|
|
|
|
// GetIdentityProvider mocks GetIdentityProvider of the AccountManager interface
|
|
func (am *MockAccountManager) GetIdentityProvider(ctx context.Context, accountID, idpID, userID string) (*types.IdentityProvider, error) {
|
|
if am.GetIdentityProviderFunc != nil {
|
|
return am.GetIdentityProviderFunc(ctx, accountID, idpID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetIdentityProvider is not implemented")
|
|
}
|
|
|
|
// GetIdentityProviders mocks GetIdentityProviders of the AccountManager interface
|
|
func (am *MockAccountManager) GetIdentityProviders(ctx context.Context, accountID, userID string) ([]*types.IdentityProvider, error) {
|
|
if am.GetIdentityProvidersFunc != nil {
|
|
return am.GetIdentityProvidersFunc(ctx, accountID, userID)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method GetIdentityProviders is not implemented")
|
|
}
|
|
|
|
// CreateIdentityProvider mocks CreateIdentityProvider of the AccountManager interface
|
|
func (am *MockAccountManager) CreateIdentityProvider(ctx context.Context, accountID, userID string, idp *types.IdentityProvider) (*types.IdentityProvider, error) {
|
|
if am.CreateIdentityProviderFunc != nil {
|
|
return am.CreateIdentityProviderFunc(ctx, accountID, userID, idp)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method CreateIdentityProvider is not implemented")
|
|
}
|
|
|
|
// UpdateIdentityProvider mocks UpdateIdentityProvider of the AccountManager interface
|
|
func (am *MockAccountManager) UpdateIdentityProvider(ctx context.Context, accountID, idpID, userID string, idp *types.IdentityProvider) (*types.IdentityProvider, error) {
|
|
if am.UpdateIdentityProviderFunc != nil {
|
|
return am.UpdateIdentityProviderFunc(ctx, accountID, idpID, userID, idp)
|
|
}
|
|
return nil, status.Errorf(codes.Unimplemented, "method UpdateIdentityProvider is not implemented")
|
|
}
|
|
|
|
// DeleteIdentityProvider mocks DeleteIdentityProvider of the AccountManager interface
|
|
func (am *MockAccountManager) DeleteIdentityProvider(ctx context.Context, accountID, idpID, userID string) error {
|
|
if am.DeleteIdentityProviderFunc != nil {
|
|
return am.DeleteIdentityProviderFunc(ctx, accountID, idpID, userID)
|
|
}
|
|
return status.Errorf(codes.Unimplemented, "method DeleteIdentityProvider is not implemented")
|
|
}
|