mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-26 08:39:06 +02:00
[management] handle nil ptr in sendInitialSync() when the peer is deleted (#7315)
* fix a nil-ptr error occuring in sendInitialSync when the peer being synced is deleted Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io> * handle a nil ptr in GetPeerNetworkMapComponents Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io> --------- Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"github.com/netbirdio/netbird/management/server/types"
|
||||
)
|
||||
|
||||
//go:generate go tool mockgen -package=account -source=./request_buffer.go -destination=request_buffer_mock.go
|
||||
|
||||
type RequestBuffer interface {
|
||||
GetAccountWithBackpressure(ctx context.Context, accountID string) (*types.Account, error)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: ./request_buffer.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -package=account -source=./request_buffer.go -destination=request_buffer_mock.go
|
||||
//
|
||||
|
||||
// Package account is a generated GoMock package.
|
||||
package account
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
types "github.com/netbirdio/netbird/management/server/types"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockRequestBuffer is a mock of RequestBuffer interface.
|
||||
type MockRequestBuffer struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockRequestBufferMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockRequestBufferMockRecorder is the mock recorder for MockRequestBuffer.
|
||||
type MockRequestBufferMockRecorder struct {
|
||||
mock *MockRequestBuffer
|
||||
}
|
||||
|
||||
// NewMockRequestBuffer creates a new mock instance.
|
||||
func NewMockRequestBuffer(ctrl *gomock.Controller) *MockRequestBuffer {
|
||||
mock := &MockRequestBuffer{ctrl: ctrl}
|
||||
mock.recorder = &MockRequestBufferMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockRequestBuffer) EXPECT() *MockRequestBufferMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// GetAccountWithBackpressure mocks base method.
|
||||
func (m *MockRequestBuffer) GetAccountWithBackpressure(ctx context.Context, accountID string) (*types.Account, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetAccountWithBackpressure", ctx, accountID)
|
||||
ret0, _ := ret[0].(*types.Account)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetAccountWithBackpressure indicates an expected call of GetAccountWithBackpressure.
|
||||
func (mr *MockRequestBufferMockRecorder) GetAccountWithBackpressure(ctx, accountID any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccountWithBackpressure", reflect.TypeOf((*MockRequestBuffer)(nil).GetAccountWithBackpressure), ctx, accountID)
|
||||
}
|
||||
@@ -112,8 +112,6 @@ func (a *Account) GetPeerNetworkMapComponents(
|
||||
return EmptyNetworkMapComponents(&NetworkMapComponents{
|
||||
PeerID: peerID,
|
||||
Network: a.Network.Copy(),
|
||||
// must include the target peer as it's required on the client
|
||||
Peers: map[string]*ComponentPeer{peerID: peer.ToComponent()},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/netbirdio/netbird/dns"
|
||||
"github.com/netbirdio/netbird/shared/management/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetPeerNetworkMapComponents_PeerMissingFromAcount(t *testing.T) {
|
||||
account := Account{Network: NewNetwork()}
|
||||
nmapcomponets := account.GetPeerNetworkMapComponents(context.TODO(), "missing-peer", dns.CustomZone{}, nil, nil, nil, nil, nil)
|
||||
|
||||
assert.Equal(t, EmptyNetworkMapComponents(&types.NetworkMapComponents{
|
||||
PeerID: "missing-peer",
|
||||
Network: account.Network,
|
||||
}), nmapcomponets)
|
||||
}
|
||||
Reference in New Issue
Block a user