mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-09 16:31:29 +02:00
* Gather fresh system info on every management sync stream connect The engine collected the peer meta once at start and reused the same Info for every Sync stream reconnect, so a mobile network switch that redials management kept reporting the old local network addresses. The peer network range posture check was then evaluated against stale data until the client restarted. Sync now takes a gatherer that runs at each stream connect. The gatherer is cheap: GetInfo plus the cached posture check file results, kept in the new system.InfoSource, which the engine refreshes whenever the checks list changes. No process enumeration runs on the reconnect path. Also fix the management mock server calling itself instead of SyncFunc. * Evaluate the login response posture checks before the first sync connect The engine starts with the checks the login response carried, and the first sync stream request used to send their evaluated file results. After moving the gather into InfoSource, the stream opened with an empty cache and the first sync response did not refill it, because its checks equal the ones the engine already holds. Desktop peers therefore never reported process or file posture results. Seed the cache once before the first connect, where the old gather ran, so a timed out evaluation still falls through to the address-only info. * Harden the sync info source against nil callbacks and shared slices A nil getInfo opens the stream without metadata, as a nil sysInfo did before. The cached posture results are a copy, so the Info returned by Refresh cannot alias the snapshot later Current calls report. The exclusion test asserts the remaining address count so it cannot pass vacuously on a single-address host. * Retry a posture check refresh that timed out or failed to sync The checks list was recorded before the gather ran, so once the gather timed out or SyncMeta failed, the next sync response carrying the same list matched the recorded one and nothing retried. The peer kept reporting the previous posture results until the list changed again. Record the checks only after the meta reached management, so a failed cycle is repeated on the next sync response. * Log the skipped posture refresh, let the mock Sync return errors and deflake the reconnect test * Drop the nil guard around the sync info callback * Send the refreshed info on the first sync connect instead of gathering it twice
139 lines
4.3 KiB
Go
139 lines
4.3 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/netbirdio/netbird/client/system"
|
|
"github.com/netbirdio/netbird/shared/management/domain"
|
|
"github.com/netbirdio/netbird/shared/management/proto"
|
|
)
|
|
|
|
// MockClient is a mock implementation of the Client interface for testing.
|
|
type MockClient struct {
|
|
CloseFunc func() error
|
|
SyncFunc func(ctx context.Context, getInfo func(ctx context.Context) *system.Info, msgHandler func(msg *proto.SyncResponse) error) error
|
|
RegisterFunc func(setupKey string, jwtToken string, info *system.Info, sshKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error)
|
|
LoginFunc func(info *system.Info, sshKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error)
|
|
ExtendAuthSessionFunc func(info *system.Info, jwtToken string) (*proto.ExtendAuthSessionResponse, error)
|
|
GetDeviceAuthorizationFlowFunc func() (*proto.DeviceAuthorizationFlow, error)
|
|
GetPKCEAuthorizationFlowFunc func() (*proto.PKCEAuthorizationFlow, error)
|
|
GetServerURLFunc func() string
|
|
HealthCheckFunc func() error
|
|
SyncMetaFunc func(sysInfo *system.Info) error
|
|
LogoutFunc func() error
|
|
JobFunc func(ctx context.Context, msgHandler func(msg *proto.JobRequest) *proto.JobResponse) error
|
|
CreateExposeFunc func(ctx context.Context, req ExposeRequest) (*ExposeResponse, error)
|
|
RenewExposeFunc func(ctx context.Context, domain string) error
|
|
StopExposeFunc func(ctx context.Context, domain string) error
|
|
}
|
|
|
|
func (m *MockClient) IsHealthy() bool {
|
|
return true
|
|
}
|
|
|
|
func (m *MockClient) Close() error {
|
|
if m.CloseFunc == nil {
|
|
return nil
|
|
}
|
|
return m.CloseFunc()
|
|
}
|
|
|
|
func (m *MockClient) Sync(ctx context.Context, getInfo func(ctx context.Context) *system.Info, msgHandler func(msg *proto.SyncResponse) error) error {
|
|
if m.SyncFunc == nil {
|
|
return nil
|
|
}
|
|
return m.SyncFunc(ctx, getInfo, msgHandler)
|
|
}
|
|
|
|
func (m *MockClient) Job(ctx context.Context, msgHandler func(msg *proto.JobRequest) *proto.JobResponse) error {
|
|
if m.JobFunc == nil {
|
|
return nil
|
|
}
|
|
return m.JobFunc(ctx, msgHandler)
|
|
}
|
|
|
|
func (m *MockClient) Register(setupKey string, jwtToken string, info *system.Info, sshKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error) {
|
|
if m.RegisterFunc == nil {
|
|
return nil, nil
|
|
}
|
|
return m.RegisterFunc(setupKey, jwtToken, info, sshKey, dnsLabels)
|
|
}
|
|
|
|
func (m *MockClient) Login(info *system.Info, sshKey []byte, dnsLabels domain.List) (*proto.LoginResponse, error) {
|
|
if m.LoginFunc == nil {
|
|
return nil, nil
|
|
}
|
|
return m.LoginFunc(info, sshKey, dnsLabels)
|
|
}
|
|
|
|
func (m *MockClient) ExtendAuthSession(info *system.Info, jwtToken string) (*proto.ExtendAuthSessionResponse, error) {
|
|
if m.ExtendAuthSessionFunc == nil {
|
|
return nil, nil
|
|
}
|
|
return m.ExtendAuthSessionFunc(info, jwtToken)
|
|
}
|
|
|
|
func (m *MockClient) GetDeviceAuthorizationFlow() (*proto.DeviceAuthorizationFlow, error) {
|
|
if m.GetDeviceAuthorizationFlowFunc == nil {
|
|
return nil, nil
|
|
}
|
|
return m.GetDeviceAuthorizationFlowFunc()
|
|
}
|
|
|
|
func (m *MockClient) GetPKCEAuthorizationFlow() (*proto.PKCEAuthorizationFlow, error) {
|
|
if m.GetPKCEAuthorizationFlowFunc == nil {
|
|
return nil, nil
|
|
}
|
|
return m.GetPKCEAuthorizationFlowFunc()
|
|
}
|
|
|
|
func (m *MockClient) HealthCheck() error {
|
|
if m.HealthCheckFunc == nil {
|
|
return nil
|
|
}
|
|
return m.HealthCheckFunc()
|
|
}
|
|
|
|
// GetServerURL mock implementation of GetServerURL from mgm.Client interface
|
|
func (m *MockClient) GetServerURL() string {
|
|
if m.GetServerURLFunc == nil {
|
|
return ""
|
|
}
|
|
return m.GetServerURLFunc()
|
|
}
|
|
|
|
func (m *MockClient) SyncMeta(sysInfo *system.Info) error {
|
|
if m.SyncMetaFunc == nil {
|
|
return nil
|
|
}
|
|
return m.SyncMetaFunc(sysInfo)
|
|
}
|
|
|
|
func (m *MockClient) Logout() error {
|
|
if m.LogoutFunc == nil {
|
|
return nil
|
|
}
|
|
return m.LogoutFunc()
|
|
}
|
|
|
|
func (m *MockClient) CreateExpose(ctx context.Context, req ExposeRequest) (*ExposeResponse, error) {
|
|
if m.CreateExposeFunc == nil {
|
|
return nil, nil
|
|
}
|
|
return m.CreateExposeFunc(ctx, req)
|
|
}
|
|
|
|
func (m *MockClient) RenewExpose(ctx context.Context, domain string) error {
|
|
if m.RenewExposeFunc == nil {
|
|
return nil
|
|
}
|
|
return m.RenewExposeFunc(ctx, domain)
|
|
}
|
|
|
|
func (m *MockClient) StopExpose(ctx context.Context, domain string) error {
|
|
if m.StopExposeFunc == nil {
|
|
return nil
|
|
}
|
|
return m.StopExposeFunc(ctx, domain)
|
|
}
|