Other: Ensure logout works when offline

This commit is contained in:
James Houlahan
2022-11-02 21:17:06 +01:00
parent 039d1b7f99
commit af542a2fc1
2 changed files with 13 additions and 3 deletions

View File

@ -491,10 +491,11 @@ func TestBridge_LoginLogoutRepeated(t *testing.T) {
func TestBridge_LogoutOffline(t *testing.T) {
withEnv(t, func(ctx context.Context, s *server.Server, netCtl *liteapi.NetCtl, locator bridge.Locator, storeKey []byte) {
var userID string
withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) {
// Login the user.
userID, err := bridge.LoginFull(ctx, username, password, nil, nil)
require.NoError(t, err)
userID = must(bridge.LoginFull(ctx, username, password, nil, nil))
// The user is now connected.
require.Equal(t, []string{userID}, bridge.GetUserIDs())
@ -510,6 +511,15 @@ func TestBridge_LogoutOffline(t *testing.T) {
require.Equal(t, []string{userID}, bridge.GetUserIDs())
require.Empty(t, getConnectedUserIDs(t, bridge))
})
// Go back online.
netCtl.Enable()
withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) {
// The user is still disconnected.
require.Equal(t, []string{userID}, bridge.GetUserIDs())
require.Empty(t, getConnectedUserIDs(t, bridge))
})
})
}

View File

@ -562,7 +562,7 @@ func (user *User) Logout(ctx context.Context, withAPI bool) error {
if withAPI {
if err := user.client.AuthDelete(ctx); err != nil {
return fmt.Errorf("failed to delete auth: %w", err)
user.log.WithError(err).Warn("Failed to delete auth")
}
}