Fix ServiceManager.AddProfile signature

This commit is contained in:
Theodor S. Midtlien
2026-09-03 14:10:41 +02:00
parent 70f075806b
commit 36ba4ef091
7 changed files with 20 additions and 21 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ func TestUpDaemon(t *testing.T) {
}
sm := profilemanager.ServiceManager{}
created, err := sm.AddProfile("test1", currUser.Username)
created, err := sm.AddProfile("test1", currUser.Username, nil)
if err != nil {
t.Fatalf("failed to add profile: %v", err)
return
+1
View File
@@ -846,6 +846,7 @@ func TestAddConfig_AllFieldsCovered(t *testing.T) {
"Name": "non-config: profile name is not needed for debug purposes",
"policy": "non-config: in-memory MDM policy snapshot, surfaced via Config.Policy() / GetConfigResponse.MDMManagedFields",
"DebugBundleUploadURL": "sensitive: MDM-provided upload URL may carry credentials or query tokens; kept out of the shared bundle",
"Owner": "non-config: owner information is not needed for debug purposes",
}
mURL, _ := url.Parse("https://api.example.com:443")
+5 -6
View File
@@ -6,7 +6,6 @@ import (
"path/filepath"
"testing"
"github.com/netbirdio/netbird/client/internal/ipcauth"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -18,7 +17,7 @@ type testPrefsSection struct {
func TestProfilePrefs_RoundTrip(t *testing.T) {
withTestSM(t, func(sm *ServiceManager, username string) {
created, err := sm.AddProfile("work", username, ipcauth.Identity{})
created, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
prefs, err := sm.ProfilePrefs(created.ID, username)
@@ -43,7 +42,7 @@ func TestProfilePrefs_RoundTrip(t *testing.T) {
func TestProfilePrefs_GetMissingNamespace(t *testing.T) {
withTestSM(t, func(sm *ServiceManager, username string) {
created, err := sm.AddProfile("work", username, ipcauth.Identity{})
created, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
prefs, err := sm.ProfilePrefs(created.ID, username)
@@ -58,7 +57,7 @@ func TestProfilePrefs_GetMissingNamespace(t *testing.T) {
func TestProfilePrefs_RemoveNamespace(t *testing.T) {
withTestSM(t, func(sm *ServiceManager, username string) {
created, err := sm.AddProfile("work", username, ipcauth.Identity{})
created, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
prefs, err := sm.ProfilePrefs(created.ID, username)
@@ -91,7 +90,7 @@ func TestProfilePrefs_RejectsInvalidID(t *testing.T) {
func TestProfilePrefs_RejectsEmptyNamespace(t *testing.T) {
withTestSM(t, func(sm *ServiceManager, username string) {
created, err := sm.AddProfile("work", username, ipcauth.Identity{})
created, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
prefs, err := sm.ProfilePrefs(created.ID, username)
@@ -119,7 +118,7 @@ func TestProfilePrefs_DefaultProfile(t *testing.T) {
func TestRemoveProfile_DeletesPrefsFile(t *testing.T) {
withTestSM(t, func(sm *ServiceManager, username string) {
created, err := sm.AddProfile("work", username, ipcauth.Identity{})
created, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
prefs, err := sm.ProfilePrefs(created.ID, username)
+2 -2
View File
@@ -301,7 +301,7 @@ func (s *ServiceManager) DefaultProfilePath() string {
// The returned Profile carries the freshly-generated ID so callers can
// show it to the user (and so the gRPC AddProfileResponse can include
// it).
func (s *ServiceManager) AddProfile(displayName string, username string, callerId ipcauth.Identity) (*Profile, error) {
func (s *ServiceManager) AddProfile(displayName string, username string, callerId *ipcauth.Identity) (*Profile, error) {
configDir, err := s.getConfigDir(username)
if err != nil {
return nil, fmt.Errorf("failed to get config directory: %w", err)
@@ -318,7 +318,7 @@ func (s *ServiceManager) AddProfile(displayName string, username string, callerI
}
profPath := filepath.Join(configDir, id.String()+".json")
cfg, err := createNewConfig(ConfigInput{ConfigPath: profPath, Owner: &callerId})
cfg, err := createNewConfig(ConfigInput{ConfigPath: profPath, Owner: callerId})
if err != nil {
return nil, fmt.Errorf("failed to create new config: %w", err)
}
+9 -10
View File
@@ -12,7 +12,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/netbirdio/netbird/client/internal/ipcauth"
"github.com/netbirdio/netbird/util"
)
@@ -33,7 +32,7 @@ func withTestSM(t *testing.T, fn func(sm *ServiceManager, username string)) {
func TestServiceProfile_ExactID(t *testing.T) {
withTestSM(t, func(sm *ServiceManager, username string) {
created, err := sm.AddProfile("work", username, ipcauth.Identity{})
created, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
got, err := sm.ResolveProfile(created.ID.String(), username)
@@ -45,7 +44,7 @@ func TestServiceProfile_ExactID(t *testing.T) {
func TestServiceProfile_IDPrefix(t *testing.T) {
withTestSM(t, func(sm *ServiceManager, username string) {
created, err := sm.AddProfile("work", username, ipcauth.Identity{})
created, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
prefix := created.ID[:4]
@@ -76,7 +75,7 @@ func TestServiceProfile_AmbiguousPrefix(t *testing.T) {
func TestServiceProfile_ExactNameUnique(t *testing.T) {
withTestSM(t, func(sm *ServiceManager, username string) {
_, err := sm.AddProfile("work", username, ipcauth.Identity{})
_, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
got, err := sm.ResolveProfile("work", username)
@@ -87,9 +86,9 @@ func TestServiceProfile_ExactNameUnique(t *testing.T) {
func TestServiceProfile_AmbiguousName(t *testing.T) {
withTestSM(t, func(sm *ServiceManager, username string) {
_, err := sm.AddProfile("work", username, ipcauth.Identity{})
_, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
_, err = sm.AddProfile("work", username, ipcauth.Identity{})
_, err = sm.AddProfile("work", username, nil)
require.NoError(t, err)
_, err = sm.ResolveProfile("work", username)
@@ -134,10 +133,10 @@ func TestServiceProfile_LegacyFilenameCoexists(t *testing.T) {
func TestAddProfile_AllowsDuplicateWithFlag(t *testing.T) {
withTestSM(t, func(sm *ServiceManager, username string) {
first, err := sm.AddProfile("work", username, ipcauth.Identity{})
first, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
second, err := sm.AddProfile("work", username, ipcauth.Identity{})
second, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
assert.NotEqual(t, first.ID, second.ID)
assert.Equal(t, "work", second.Name)
@@ -152,7 +151,7 @@ func TestAddProfile_RejectsInvalidNames(t *testing.T) {
strings.Repeat("a", maxProfileNameLen+1), // too long
}
for _, name := range cases {
_, err := sm.AddProfile(name, username, ipcauth.Identity{})
_, err := sm.AddProfile(name, username, nil)
assert.Error(t, err, "expected error for %q", name)
}
})
@@ -216,7 +215,7 @@ func TestIsValidProfileFilenameStem(t *testing.T) {
func TestRemoveProfile_DeletesStateFile(t *testing.T) {
withTestSM(t, func(sm *ServiceManager, username string) {
created, err := sm.AddProfile("work", username, ipcauth.Identity{})
created, err := sm.AddProfile("work", username, nil)
require.NoError(t, err)
configDir, err := sm.getConfigDir(username)
+1 -1
View File
@@ -141,7 +141,7 @@ func (pm *ProfileManager) SwitchProfile(id string) error {
// AddProfile creates a new profile with the given display name and a
// generated ID. It returns the created profile so the caller learns the ID.
func (pm *ProfileManager) AddProfile(displayName string) (*Profile, error) {
profile, err := pm.serviceMgr.AddProfile(displayName, pm.username)
profile, err := pm.serviceMgr.AddProfile(displayName, pm.username, nil)
if err != nil {
return nil, fmt.Errorf("add profile: %w", err)
}
+1 -1
View File
@@ -2289,7 +2289,7 @@ func (s *Server) AddProfile(ctx context.Context, msg *proto.AddProfileRequest) (
if !ok {
return nil, fmt.Errorf("failed to get identity from context")
}
created, err := s.profileManager.AddProfile(msg.ProfileName, msg.Username, callerId)
created, err := s.profileManager.AddProfile(msg.ProfileName, msg.Username, &callerId)
if err != nil {
log.Errorf("failed to create profile: %v", err)
return nil, fmt.Errorf("failed to create profile: %w", err)