mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-28 07:19:08 +01:00
[client] Drop the pending session extend on a profile switch
The profile-switch cleanup dropped the pending login flow and the account-prompt flag, but left extendAuthSessionFlow untouched. Its device code was issued by the previous profile's IdP client, so a WaitExtendAuthSession still parked on the browser leg would submit the resulting token against the new profile's engine.
This commit is contained in:
@@ -103,12 +103,20 @@ func TestSwitchProfile_DropsAccountPromptAndPendingFlow(t *testing.T) {
|
|||||||
waitCancel: func() { cancelled = true },
|
waitCancel: func() { cancelled = true },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extendCancelled := false
|
||||||
|
s.extendAuthSessionFlow.Set(&stubOAuthFlow{}, auth.AuthFlowInfo{DeviceCode: "device"})
|
||||||
|
s.extendAuthSessionFlow.SetWaitCancel(func() { extendCancelled = true })
|
||||||
|
|
||||||
_, err := s.SwitchProfile(ctx, nil)
|
_, err := s.SwitchProfile(ctx, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, s.forceAccountPrompt, "the prompt flag leaked across a profile switch")
|
require.False(t, s.forceAccountPrompt, "the prompt flag leaked across a profile switch")
|
||||||
require.Nil(t, s.oauthAuthFlow.flow, "the previous profile's flow leaked across a profile switch")
|
require.Nil(t, s.oauthAuthFlow.flow, "the previous profile's flow leaked across a profile switch")
|
||||||
require.Empty(t, s.oauthAuthFlow.hint)
|
require.Empty(t, s.oauthAuthFlow.hint)
|
||||||
require.True(t, cancelled, "the pending wait was not cancelled")
|
require.True(t, cancelled, "the pending wait was not cancelled")
|
||||||
|
|
||||||
|
require.True(t, extendCancelled, "the pending extend wait was not cancelled")
|
||||||
|
_, _, pending := s.extendAuthSessionFlow.Get()
|
||||||
|
require.False(t, pending, "the previous profile's extend flow leaked across a profile switch")
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSSOTestServer(t *testing.T, hint string, accountPrompted bool, tokenEmail string) *Server {
|
func newSSOTestServer(t *testing.T, hint string, accountPrompted bool, tokenEmail string) *Server {
|
||||||
|
|||||||
@@ -1286,6 +1286,12 @@ func (s *Server) SwitchProfile(callerCtx context.Context, msg *proto.SwitchProfi
|
|||||||
s.oauthAuthFlow = oauthAuthFlow{}
|
s.oauthAuthFlow = oauthAuthFlow{}
|
||||||
s.forceAccountPrompt = false
|
s.forceAccountPrompt = false
|
||||||
|
|
||||||
|
// A pending session extend belongs to the previous profile too: its device
|
||||||
|
// code was issued by that profile's IdP client, and WaitExtendAuthSession
|
||||||
|
// would submit the resulting token against the new profile's engine.
|
||||||
|
s.extendAuthSessionFlow.CancelWait()
|
||||||
|
s.extendAuthSessionFlow.Clear()
|
||||||
|
|
||||||
if msg != nil && msg.ProfileName != nil {
|
if msg != nil && msg.ProfileName != nil {
|
||||||
s.publishProfileListChanged(*msg.ProfileName)
|
s.publishProfileListChanged(*msg.ProfileName)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user