From 71732da68ec95bff1dc565396a7600d95ad63af2 Mon Sep 17 00:00:00 2001 From: "Theodor S. Midtlien" Date: Tue, 20 Oct 2026 22:30:08 +0200 Subject: [PATCH] Fix server merge regression bug --- client/server/login_account_test.go | 9 ++++++--- client/server/server.go | 2 +- client/server/update_settings_gate_test.go | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/server/login_account_test.go b/client/server/login_account_test.go index 6198a00bc..538175b2f 100644 --- a/client/server/login_account_test.go +++ b/client/server/login_account_test.go @@ -152,6 +152,7 @@ func TestLogin_ProfileSwitchDropsAccountPromptAndPendingFlow(t *testing.T) { _, err := profilemanager.UpdateOrCreateConfig(profilemanager.ConfigInput{ ConfigPath: otherPath, ManagementURL: "https://api.netbird.io:443", + Owner: testProfileOwner(), }) require.NoError(t, err) breakProfilePrivateKey(t, otherPath) @@ -170,7 +171,7 @@ func TestLogin_ProfileSwitchDropsAccountPromptAndPendingFlow(t *testing.T) { generation := s.jwtCache.currentGeneration() - _, err = s.Login(userCtx(), &proto.LoginRequest{ProfileName: &other, Username: &username}) + _, err = s.Login(withTarget(userCtx(), otherPath), &proto.LoginRequest{ProfileName: &other, Username: &username}) require.Error(t, err, "the broken key must stop the login before a flow is built") active, err := s.profileManager.GetActiveProfileState() @@ -197,9 +198,11 @@ func TestLogin_ProfileSwitchRejectsJWTObtainedUnderPreviousConfig(t *testing.T) } other := "other-profile" + otherPath := filepath.Join(filepath.Dir(cfgPath), other+".json") _, err := profilemanager.UpdateOrCreateConfig(profilemanager.ConfigInput{ - ConfigPath: filepath.Join(filepath.Dir(cfgPath), other+".json"), + ConfigPath: otherPath, ManagementURL: "https://api.netbird.io:443", + Owner: testProfileOwner(), }) require.NoError(t, err) @@ -212,7 +215,7 @@ func TestLogin_ProfileSwitchRejectsJWTObtainedUnderPreviousConfig(t *testing.T) fetcher := &jwtStoringMDMFetcher{cache: s.jwtCache, caller: unprivilegedIdentity()} s.mdmLoader = mdm.NewLoader(fetcher) - _, err = s.Login(userCtx(), &proto.LoginRequest{ProfileName: &other, Username: &username}) + _, err = s.Login(withTarget(userCtx(), otherPath), &proto.LoginRequest{ProfileName: &other, Username: &username}) require.Error(t, err) require.Greater(t, fetcher.generation, generation, "the token was not cached after the switch dropped the previous profile's state") diff --git a/client/server/server.go b/client/server/server.go index 2e4a9fd9f..9d0fe7698 100644 --- a/client/server/server.go +++ b/client/server/server.go @@ -3070,7 +3070,7 @@ func (s *Server) authorizeAndPrepareLogin(callerCtx context.Context, msg *proto. if err != nil { return nil, nil, false, err } - switched, err := s.switchProfileIfNeeded(resolved, activeProf) + switched, err = s.switchProfileIfNeeded(resolved, activeProf) if err != nil { return nil, nil, false, fmt.Errorf("switch profile: %w", err) } diff --git a/client/server/update_settings_gate_test.go b/client/server/update_settings_gate_test.go index 0d2cd8810..424fec4a7 100644 --- a/client/server/update_settings_gate_test.go +++ b/client/server/update_settings_gate_test.go @@ -328,6 +328,7 @@ func TestLogin_ChangeThatAppearsMidRequestIsRefused(t *testing.T) { _, err := profilemanager.UpdateOrCreateConfig(profilemanager.ConfigInput{ ConfigPath: targetPath, ManagementURL: storedManagementURL, + Owner: testProfileOwner(), }) require.NoError(t, err) @@ -347,7 +348,7 @@ func TestLogin_ChangeThatAppearsMidRequestIsRefused(t *testing.T) { } t.Cleanup(func() { afterLoginPreCheck = nil }) - _, err = s.Login(userCtx(), &proto.LoginRequest{ + _, err = s.Login(withTarget(userCtx(), targetPath), &proto.LoginRequest{ ProfileName: &target, Username: &username, ManagementUrl: storedManagementURL,