Fix server merge regression bug

This commit is contained in:
Theodor S. Midtlien
2026-10-20 22:30:08 +02:00
parent 8f952fda06
commit 71732da68e
3 changed files with 9 additions and 5 deletions
+6 -3
View File
@@ -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")
+1 -1
View File
@@ -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)
}
+2 -1
View File
@@ -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,