diff --git a/.golangci.yml b/.golangci.yml index 001a5391..72d651cd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,11 +2,12 @@ run: timeout: 10m skip-dirs: - - pkg/mime - - extern issues: exclude-use-default: false + exclude-dirs: + - pkg/mime + - extern exclude: - Using the variable on range scope `tt` in function literal # For now we are missing a lot of comments. diff --git a/Makefile b/Makefile index ae56ef97..18c4163a 100644 --- a/Makefile +++ b/Makefile @@ -189,7 +189,7 @@ ${RESOURCE_FILE}: ./dist/info.rc ./dist/${SRC_ICO} .FORCE ## Dev dependencies .PHONY: install-devel-tools install-linter install-go-mod-outdated install-git-hooks -LINTVER:="v1.55.2" +LINTVER:="v1.59.1" LINTSRC:="https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh" install-dev-dependencies: install-devel-tools install-linter install-go-mod-outdated diff --git a/internal/bridge/bridge.go b/internal/bridge/bridge.go index 7334de89..d0744aef 100644 --- a/internal/bridge/bridge.go +++ b/internal/bridge/bridge.go @@ -550,9 +550,9 @@ func (bridge *Bridge) onStatusDown(ctx context.Context) { func (bridge *Bridge) Repair() { var wg sync.WaitGroup - userIDS := bridge.GetUserIDs() + userIDs := bridge.GetUserIDs() - for _, userID := range userIDS { + for _, userID := range userIDs { logPkg.Info("Initiating repair for userID:", userID) userInfo, err := bridge.GetUserInfo(userID) diff --git a/internal/bridge/bridge_test.go b/internal/bridge/bridge_test.go index d3db2b67..9f3d0d2a 100644 --- a/internal/bridge/bridge_test.go +++ b/internal/bridge/bridge_test.go @@ -76,7 +76,7 @@ func init() { func TestBridge_ConnStatus(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, vaultKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Get a stream of connection status events. eventCh, done := bridge.GetEvents(events.ConnStatusUp{}, events.ConnStatusDown{}) defer done() @@ -125,7 +125,7 @@ func TestBridge_TLSIssue(t *testing.T) { func TestBridge_Focus(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, vaultKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Get a stream of TLS issue events. raiseCh, done := bridge.GetEvents(events.Raise{}) defer done() @@ -156,7 +156,7 @@ func TestBridge_UserAgent(t *testing.T) { calls = append(calls, call) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Set the platform to something other than the default. bridge.SetCurrentPlatform("platform") @@ -183,7 +183,7 @@ func TestBridge_UserAgent_Persistence(t *testing.T) { _, _, err := s.CreateUser(otherUser, otherPassword) require.NoError(t, err) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, _ *bridge.Mocks) { currentUserAgent := b.GetCurrentUserAgent() require.Contains(t, currentUserAgent, useragent.DefaultUserAgent) @@ -211,7 +211,7 @@ func TestBridge_UserAgent_Persistence(t *testing.T) { require.Contains(t, b.GetCurrentUserAgent(), "MyFancyClient/0.1.2") }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { currentUserAgent := bridge.GetCurrentUserAgent() require.Contains(t, currentUserAgent, "MyFancyClient/0.1.2") }) @@ -225,7 +225,7 @@ func TestBridge_UserAgentFromUnknownClient(t *testing.T) { _, _, err := s.CreateUser(otherUser, otherPassword) require.NoError(t, err) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, _ *bridge.Mocks) { currentUserAgent := b.GetCurrentUserAgent() require.Contains(t, currentUserAgent, useragent.DefaultUserAgent) @@ -255,7 +255,7 @@ func TestBridge_UserAgentFromSMTPClient(t *testing.T) { _, _, err := s.CreateUser(otherUser, otherPassword) require.NoError(t, err) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, _ *bridge.Mocks) { currentUserAgent := b.GetCurrentUserAgent() require.Contains(t, currentUserAgent, useragent.DefaultUserAgent) @@ -305,7 +305,7 @@ func TestBridge_UserAgentFromIMAPID(t *testing.T) { _, _, err := s.CreateUser(otherUser, otherPassword) require.NoError(t, err) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, _ *bridge.Mocks) { require.NoError(t, getErr(b.LoginFull(ctx, otherUser, otherPassword, nil, nil))) imapClient, err := eventuallyDial(fmt.Sprintf("%v:%v", constants.Host, b.GetIMAPPort())) @@ -365,13 +365,13 @@ func TestBridge_Cookies(t *testing.T) { }) // Start bridge and add a user so that API assigns us a session ID via cookie. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { _, err := bridge.LoginFull(context.Background(), username, password, nil, nil) require.NoError(t, err) }) // Start bridge again and check that it uses the same session ID. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(_ *bridge.Bridge, _ *bridge.Mocks) { // ... }) @@ -484,7 +484,7 @@ func TestBridge_ManualUpdate(t *testing.T) { func TestBridge_ForceUpdate(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, vaultKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Get a stream of update events. updateCh, done := bridge.GetEvents(events.UpdateForced{}) defer done() @@ -507,7 +507,7 @@ func TestBridge_BadVaultKey(t *testing.T) { var userID string // Login a user. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { newUserID, err := bridge.LoginFull(context.Background(), username, password, nil, nil) require.NoError(t, err) @@ -515,17 +515,17 @@ func TestBridge_BadVaultKey(t *testing.T) { }) // Start bridge with the correct vault key -- it should load the users correctly. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.ElementsMatch(t, []string{userID}, bridge.GetUserIDs()) }) // Start bridge with a bad vault key, the vault will be wiped and bridge will show no users. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, []byte("bad"), func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, []byte("bad"), func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.Empty(t, bridge.GetUserIDs()) }) // Start bridge with a nil vault key, the vault will be wiped and bridge will show no users. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, nil, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, nil, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.Empty(t, bridge.GetUserIDs()) }) }) @@ -535,7 +535,7 @@ func TestBridge_MissingGluonStore(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, vaultKey []byte) { var gluonDir string - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { _, err := bridge.LoginFull(context.Background(), username, password, nil, nil) require.NoError(t, err) @@ -550,7 +550,7 @@ func TestBridge_MissingGluonStore(t *testing.T) { require.NoError(t, os.RemoveAll(gluonDir)) // Bridge starts but can't find the gluon store dir; there should be no error. - withBridgeWaitForServers(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridgeWaitForServers(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(_ *bridge.Bridge, _ *bridge.Mocks) { // ... }) }) @@ -560,7 +560,7 @@ func TestBridge_MissingGluonDatabase(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, vaultKey []byte) { var gluonDir string - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { _, err := bridge.LoginFull(context.Background(), username, password, nil, nil) require.NoError(t, err) @@ -573,7 +573,7 @@ func TestBridge_MissingGluonDatabase(t *testing.T) { require.NoError(t, os.RemoveAll(gluonDir)) // Bridge starts but can't find the gluon database dir; there should be no error. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(_ *bridge.Bridge, _ *bridge.Mocks) { // ... }) }) @@ -587,7 +587,7 @@ func TestBridge_AddressWithoutKeys(t *testing.T) { ) defer m.Close() - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Watch for sync finished event. syncCh, done := chToType[events.Event, events.SyncFinished](bridge.GetEvents(events.SyncFinished{})) defer done() @@ -663,7 +663,7 @@ func TestBridge_FactoryReset(t *testing.T) { func TestBridge_InitGluonDirectory(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, vaultKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, _ *bridge.Mocks) { configDir, err := b.GetGluonDataDir() require.NoError(t, err) @@ -678,7 +678,7 @@ func TestBridge_InitGluonDirectory(t *testing.T) { func TestBridge_LoginFailed(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, vaultKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { failCh, done := chToType[events.Event, events.IMAPLoginFailed](bridge.GetEvents(events.IMAPLoginFailed{})) defer done() @@ -706,7 +706,7 @@ func TestBridge_ChangeCacheDirectory(t *testing.T) { createNumMessages(ctx, t, c, addrID, labelID, 10) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, _ *bridge.Mocks) { newCacheDir := t.TempDir() currentCacheDir := b.GetGluonCacheDir() configDir, err := b.GetGluonDataDir() @@ -772,7 +772,7 @@ func TestBridge_ChangeAddressOrder(t *testing.T) { createNumMessages(ctx, t, c, addrID, proton.InboxLabel, 10) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, _ *bridge.Mocks) { // Log the user in with its first address. syncCh, done := chToType[events.Event, events.SyncFinished](b.GetEvents(events.SyncFinished{})) defer done() @@ -800,7 +800,7 @@ func TestBridge_ChangeAddressOrder(t *testing.T) { require.NoError(t, c.OrderAddresses(ctx, proton.OrderAddressesReq{AddressIDs: []string{aliasID, addrID}})) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(b *bridge.Bridge, _ *bridge.Mocks) { // We should still see 10 messages in the inbox. info, err := b.GetUserInfo(userID) require.NoError(t, err) diff --git a/internal/bridge/server_manager_test.go b/internal/bridge/server_manager_test.go index ee39590e..798b667c 100644 --- a/internal/bridge/server_manager_test.go +++ b/internal/bridge/server_manager_test.go @@ -34,7 +34,7 @@ import ( func TestServerManager_ServersStartWithBridge(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { imapClient, err := eventuallyDial(fmt.Sprintf("%v:%v", constants.Host, bridge.GetIMAPPort())) require.NoError(t, err) require.NoError(t, imapClient.Logout()) @@ -48,7 +48,7 @@ func TestServerManager_ServersStartWithBridge(t *testing.T) { func TestServerManager_ServersKeepsRunningfterUserLogsOut(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userID, err := bridge.LoginFull(ctx, username, password, nil, nil) require.NoError(t, err) @@ -72,7 +72,7 @@ func TestServerManager_ServersDoNotStopWhenThereIsStillOneActiveUser(t *testing. _, _, err := s.CreateUser(otherUser, otherPassword) require.NoError(t, err) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { _, err := bridge.LoginFull(ctx, username, password, nil, nil) require.NoError(t, err) @@ -99,7 +99,7 @@ func TestServerManager_ServersDoNotStopWhenThereIsStillOneActiveUser(t *testing. func TestServerManager_NetworkLossStopsServers(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { imapWaiter := waitForIMAPServerReady(bridge) defer imapWaiter.Done() diff --git a/internal/bridge/settings_test.go b/internal/bridge/settings_test.go index 072ffd0e..f5c0b949 100644 --- a/internal/bridge/settings_test.go +++ b/internal/bridge/settings_test.go @@ -31,7 +31,7 @@ import ( func TestBridge_Settings_GluonDir(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Create a user. _, err := bridge.LoginFull(context.Background(), username, password, nil, nil) require.NoError(t, err) @@ -57,7 +57,7 @@ func TestBridge_Settings_GluonDirWithOnGoingEvents(t *testing.T) { userID, addrID, err := s.CreateUser("imap", password) require.NoError(t, err) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { syncCh, done := chToType[events.Event, events.SyncFinished](bridge.GetEvents(events.SyncFinished{})) defer done() @@ -74,7 +74,7 @@ func TestBridge_Settings_GluonDirWithOnGoingEvents(t *testing.T) { createNumMessages(ctx, t, c, addrID, labelID, 200) }) - withBridgeWaitForServers(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridgeWaitForServers(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Create a new location for the Gluon data. newGluonDir := t.TempDir() @@ -93,7 +93,7 @@ func TestBridge_Settings_GluonDirWithOnGoingEvents(t *testing.T) { func TestBridge_Settings_IMAPPort(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { curPort := bridge.GetIMAPPort() // Set the port to 1144. @@ -110,7 +110,7 @@ func TestBridge_Settings_IMAPPort(t *testing.T) { func TestBridge_Settings_IMAPSSL(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // By default, IMAP SSL is disabled. require.False(t, bridge.GetIMAPSSL()) @@ -125,7 +125,7 @@ func TestBridge_Settings_IMAPSSL(t *testing.T) { func TestBridge_Settings_SMTPPort(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { curPort := bridge.GetSMTPPort() // Set the port to 1024. @@ -142,7 +142,7 @@ func TestBridge_Settings_SMTPPort(t *testing.T) { func TestBridge_Settings_SMTPSSL(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // By default, SMTP SSL is disabled. require.False(t, bridge.GetSMTPSSL()) @@ -198,7 +198,7 @@ func TestBridge_Settings_Autostart(t *testing.T) { func TestBridge_Settings_FirstStart(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // By default, first start is true. require.True(t, bridge.GetFirstStart()) diff --git a/internal/bridge/sync_test.go b/internal/bridge/sync_test.go index e91d5323..c9a42084 100644 --- a/internal/bridge/sync_test.go +++ b/internal/bridge/sync_test.go @@ -232,7 +232,7 @@ func TestBridge_SyncWithOngoingEvents(t *testing.T) { var total uint64 // The initial user should be fully synced. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { syncCh, done := chToType[events.Event, events.SyncFinished](bridge.GetEvents(events.SyncFinished{})) defer done() @@ -246,7 +246,7 @@ func TestBridge_SyncWithOngoingEvents(t *testing.T) { }) // Now let's remove the user and stop the network at 2/3 of the data. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.NoError(t, bridge.DeleteUser(ctx, userID)) }) @@ -254,7 +254,7 @@ func TestBridge_SyncWithOngoingEvents(t *testing.T) { netCtl.SetReadLimit(2 * total / 3) // Login the user; its sync should fail. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(b *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(b *bridge.Bridge, _ *bridge.Mocks) { syncCh, done := chToType[events.Event, events.SyncFinished](b.GetEvents(events.SyncFinished{})) defer done() @@ -592,7 +592,7 @@ func TestBridge_CorruptedVaultClearsPreviousIMAPSyncState(t *testing.T) { createNumMessages(ctx, t, c, addrID, labelID, 100) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { syncCh, done := chToType[events.Event, events.SyncFinished](bridge.GetEvents(events.SyncFinished{})) defer done() @@ -625,7 +625,7 @@ func TestBridge_CorruptedVaultClearsPreviousIMAPSyncState(t *testing.T) { require.NoError(t, os.WriteFile(filepath.Join(settingsPath, "vault.enc"), []byte("Trash!"), 0o600)) // Bridge starts but can't find the gluon database dir; there should be no error. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { _, err := bridge.LoginFull(context.Background(), "imap", password, nil, nil) require.NoError(t, err) }) diff --git a/internal/bridge/user_event_test.go b/internal/bridge/user_event_test.go index 09d39afb..1823ff06 100644 --- a/internal/bridge/user_event_test.go +++ b/internal/bridge/user_event_test.go @@ -62,7 +62,7 @@ func TestBridge_User_RefreshEvent(t *testing.T) { messageIDs = createNumMessages(ctx, t, c, addrID, labelID, 10) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userLoginAndSync(ctx, t, bridge, "user", password) }) @@ -73,7 +73,7 @@ func TestBridge_User_RefreshEvent(t *testing.T) { require.NoError(t, s.RefreshUser(userID, proton.RefreshMail)) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { syncCh, closeCh := chToType[events.Event, events.SyncFinished](bridge.GetEvents(events.SyncFinished{})) require.Equal(t, userID, (<-syncCh).UserID) @@ -82,7 +82,7 @@ func TestBridge_User_RefreshEvent(t *testing.T) { userContinueEventProcess(ctx, t, s, bridge) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { withClient(ctx, t, s, "user", password, func(ctx context.Context, c *proton.Client) { createNumMessages(ctx, t, c, addrID, labelID, 10) }) @@ -191,7 +191,7 @@ func TestBridge_User_BadMessage_NoBadEvent(t *testing.T) { createNumMessages(ctx, t, c, addrID, proton.InboxLabel, 10) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userLoginAndSync(ctx, t, bridge, "user", password) var messageIDs []string @@ -368,7 +368,7 @@ func TestBridge_User_Network_NoBadEvents(t *testing.T) { _, addrID, err := s.CreateUser("user", password) require.NoError(t, err) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userLoginAndSync(ctx, t, bridge, "user", password) // Create 10 more messages for the user, generating events. @@ -454,7 +454,7 @@ func TestBridge_User_UpdateDraft(t *testing.T) { require.NoError(t, err) // Initially sync the user. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userLoginAndSync(ctx, t, bridge, "user", password) }) @@ -487,7 +487,7 @@ func TestBridge_User_UpdateDraft(t *testing.T) { require.Empty(t, draft.ReplyTos) // Process those events - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userContinueEventProcess(ctx, t, s, bridge) }) @@ -513,7 +513,7 @@ func TestBridge_User_UpdateDraftAndCreateOtherMessage(t *testing.T) { require.NoError(t, err) // Initially sync the user. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userLoginAndSync(ctx, t, bridge, "user", password) }) @@ -545,7 +545,7 @@ func TestBridge_User_UpdateDraftAndCreateOtherMessage(t *testing.T) { require.NoError(t, err) // Process those events - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userContinueEventProcess(ctx, t, s, bridge) }) @@ -573,7 +573,7 @@ func TestBridge_User_UpdateDraftAndCreateOtherMessage(t *testing.T) { require.NoError(t, err) // Process those events. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userContinueEventProcess(ctx, t, s, bridge) }) @@ -581,7 +581,7 @@ func TestBridge_User_UpdateDraftAndCreateOtherMessage(t *testing.T) { require.NoError(t, c.MarkMessagesUnread(ctx, res[0].MessageID)) // Process those events. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userContinueEventProcess(ctx, t, s, bridge) }) }) @@ -595,7 +595,7 @@ func TestBridge_User_SendDraftRemoveDraftFlag(t *testing.T) { require.NoError(t, err) // Initially sync the user. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userLoginAndSync(ctx, t, bridge, "user", password) }) @@ -628,7 +628,7 @@ func TestBridge_User_SendDraftRemoveDraftFlag(t *testing.T) { require.NoError(t, err) // Process those events - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userContinueEventProcess(ctx, t, s, bridge) info, err := bridge.QueryUserInfo("user") @@ -667,7 +667,7 @@ func TestBridge_User_SendDraftRemoveDraftFlag(t *testing.T) { } // Process those events; the draft will move to the sent folder and lose the draft flag. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userContinueEventProcess(ctx, t, s, bridge) info, err := bridge.QueryUserInfo("user") @@ -697,7 +697,7 @@ func TestBridge_User_DisableEnableAddress(t *testing.T) { aliasID, err := s.CreateAddress(userID, "alias@"+s.GetDomain(), password) require.NoError(t, err) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.NoError(t, getErr(bridge.LoginFull(ctx, "user", password, nil, nil))) // Initially we should list the address. @@ -711,7 +711,7 @@ func TestBridge_User_DisableEnableAddress(t *testing.T) { require.NoError(t, c.DisableAddress(ctx, aliasID)) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Eventually we shouldn't list the address. require.Eventually(t, func() bool { info, err := bridge.QueryUserInfo("user") @@ -726,7 +726,7 @@ func TestBridge_User_DisableEnableAddress(t *testing.T) { require.NoError(t, c.EnableAddress(ctx, aliasID)) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Eventually we should list the address. require.Eventually(t, func() bool { info, err := bridge.QueryUserInfo("user") @@ -753,7 +753,7 @@ func TestBridge_User_CreateDisabledAddress(t *testing.T) { require.NoError(t, c.DisableAddress(ctx, aliasID)) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.NoError(t, getErr(bridge.LoginFull(ctx, "user", password, nil, nil))) // Initially we shouldn't list the address. @@ -766,7 +766,7 @@ func TestBridge_User_CreateDisabledAddress(t *testing.T) { func TestBridge_User_HandleParentLabelRename(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.NoError(t, getErr(bridge.LoginFull(ctx, username, password, nil, nil))) info, err := bridge.QueryUserInfo(username) diff --git a/internal/bridge/user_test.go b/internal/bridge/user_test.go index 8faba2eb..2e66df4d 100644 --- a/internal/bridge/user_test.go +++ b/internal/bridge/user_test.go @@ -35,12 +35,12 @@ import ( func TestBridge_WithoutUsers(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.Empty(t, bridge.GetUserIDs()) require.Empty(t, getConnectedUserIDs(t, bridge)) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.Empty(t, bridge.GetUserIDs()) require.Empty(t, getConnectedUserIDs(t, bridge)) }) @@ -49,7 +49,7 @@ func TestBridge_WithoutUsers(t *testing.T) { func TestBridge_Login(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID, err := bridge.LoginFull(ctx, username, password, nil, nil) require.NoError(t, err) @@ -69,7 +69,7 @@ func TestBridge_Login_DropConn(t *testing.T) { defer func() { _ = dropListener.Close() }() withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID, err := bridge.LoginFull(ctx, username, password, nil, nil) require.NoError(t, err) @@ -96,7 +96,7 @@ func TestBridge_Login_DropConn(t *testing.T) { return 0, false }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // The user is eventually connected. require.Eventually(t, func() bool { return len(bridge.GetUserIDs()) == 1 && len(getConnectedUserIDs(t, bridge)) == 1 @@ -107,7 +107,7 @@ func TestBridge_Login_DropConn(t *testing.T) { func TestBridge_LoginTwice(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID, err := bridge.LoginFull(ctx, username, password, nil, nil) require.NoError(t, err) @@ -125,7 +125,7 @@ func TestBridge_LoginTwice(t *testing.T) { func TestBridge_LoginLogoutLogin(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID := must(bridge.LoginFull(ctx, username, password, nil, nil)) @@ -153,7 +153,7 @@ func TestBridge_LoginLogoutLogin(t *testing.T) { func TestBridge_LoginDeleteLogin(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID := must(bridge.LoginFull(ctx, username, password, nil, nil)) @@ -181,7 +181,7 @@ func TestBridge_LoginDeleteLogin(t *testing.T) { func TestBridge_LoginDeauthLogin(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID := must(bridge.LoginFull(ctx, username, password, nil, nil)) @@ -215,7 +215,7 @@ func TestBridge_LoginDeauthRestartLogin(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { var userID string - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID = must(bridge.LoginFull(ctx, username, password, nil, nil)) @@ -235,7 +235,7 @@ func TestBridge_LoginDeauthRestartLogin(t *testing.T) { require.IsType(t, events.UserDeauth{}, <-eventCh) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // The user should be disconnected at startup. require.Equal(t, []string{userID}, bridge.GetUserIDs()) require.Empty(t, getConnectedUserIDs(t, bridge)) @@ -257,7 +257,7 @@ func TestBridge_LoginExpireLogin(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { s.SetAuthLife(authLife) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. Its auth will only be valid for a short time. userID := must(bridge.LoginFull(ctx, username, password, nil, nil)) @@ -275,7 +275,7 @@ func TestBridge_FailToLoad(t *testing.T) { var userID string // Login the user. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userID = must(bridge.LoginFull(ctx, username, password, nil, nil)) }) @@ -283,7 +283,7 @@ func TestBridge_FailToLoad(t *testing.T) { require.NoError(t, s.RevokeUser(userID)) // When bridge starts, the user will not be logged in. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.Equal(t, []string{userID}, bridge.GetUserIDs()) require.Empty(t, getConnectedUserIDs(t, bridge)) }) @@ -295,7 +295,7 @@ func TestBridge_LoadWithoutInternet(t *testing.T) { var userID string // Login the user. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userID = must(bridge.LoginFull(ctx, username, password, nil, nil)) }) @@ -303,7 +303,7 @@ func TestBridge_LoadWithoutInternet(t *testing.T) { netCtl.Disable() // Start bridge without internet. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Initially, users are not connected. require.Equal(t, []string{userID}, bridge.GetUserIDs()) require.Empty(t, getConnectedUserIDs(t, bridge)) @@ -325,11 +325,11 @@ func TestBridge_LoginRestart(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { var userID string - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { userID = must(bridge.LoginFull(ctx, username, password, nil, nil)) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.Equal(t, []string{userID}, bridge.GetUserIDs()) require.Equal(t, []string{userID}, getConnectedUserIDs(t, bridge)) }) @@ -340,7 +340,7 @@ func TestBridge_LoginLogoutRestart(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { var userID string - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID = must(bridge.LoginFull(ctx, username, password, nil, nil)) @@ -348,7 +348,7 @@ func TestBridge_LoginLogoutRestart(t *testing.T) { require.NoError(t, bridge.LogoutUser(ctx, userID)) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // The user is still disconnected. require.Equal(t, []string{userID}, bridge.GetUserIDs()) require.Empty(t, getConnectedUserIDs(t, bridge)) @@ -360,7 +360,7 @@ func TestBridge_LoginDeleteRestart(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { var userID string - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID = must(bridge.LoginFull(ctx, username, password, nil, nil)) @@ -368,7 +368,7 @@ func TestBridge_LoginDeleteRestart(t *testing.T) { require.NoError(t, bridge.DeleteUser(ctx, userID)) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // The user is still gone. require.Empty(t, bridge.GetUserIDs()) require.Empty(t, getConnectedUserIDs(t, bridge)) @@ -384,7 +384,7 @@ func TestBridge_FailLoginRecover(t *testing.T) { // Log the user in, wait for it to sync, then log it out. // (We don't want to count message sync data in the test.) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { syncCh, done := chToType[events.Event, events.SyncFinished](bridge.GetEvents(events.SyncFinished{})) defer done() @@ -396,7 +396,7 @@ func TestBridge_FailLoginRecover(t *testing.T) { var total uint64 // Now that the user is synced, we can measure exactly how much data is needed during login. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { total = countBytesRead(netCtl, func() { must(bridge.LoginFull(ctx, username, password, nil, nil)) }) @@ -405,7 +405,7 @@ func TestBridge_FailLoginRecover(t *testing.T) { }) // Now simulate failing to login. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Simulate a partial read. netCtl.SetReadLimit(i * total / 10) @@ -421,7 +421,7 @@ func TestBridge_FailLoginRecover(t *testing.T) { netCtl.SetReadLimit(0) // We should now be able to log the user in. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.NoError(t, getErr(bridge.LoginFull(ctx, username, password, nil, nil))) // The user should be there, now connected. @@ -441,7 +441,7 @@ func TestBridge_FailLoadRecover(t *testing.T) { // Log the user in and wait for it to sync. // (We don't want to count message sync data in the test.) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { syncCh, done := chToType[events.Event, events.SyncFinished](bridge.GetEvents(events.SyncFinished{})) defer done() @@ -451,7 +451,7 @@ func TestBridge_FailLoadRecover(t *testing.T) { // See how much data it takes to load the user at startup. total := countBytesRead(netCtl, func() { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(_ *bridge.Bridge, _ *bridge.Mocks) { // ... }) }) @@ -460,7 +460,7 @@ func TestBridge_FailLoadRecover(t *testing.T) { netCtl.SetReadLimit(i * total / 10) // We should fail to load the user; it should be listed but disconnected. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.Equal(t, []string{userID}, bridge.GetUserIDs()) require.Empty(t, getConnectedUserIDs(t, bridge)) }) @@ -469,7 +469,7 @@ func TestBridge_FailLoadRecover(t *testing.T) { netCtl.SetReadLimit(0) // We should now be able to load the user. - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { require.Equal(t, []string{userID}, bridge.GetUserIDs()) require.Equal(t, []string{userID}, getConnectedUserIDs(t, bridge)) }) @@ -484,7 +484,7 @@ func TestBridge_BridgePass(t *testing.T) { var pass []byte - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID = must(bridge.LoginFull(ctx, username, password, nil, nil)) @@ -501,7 +501,7 @@ func TestBridge_BridgePass(t *testing.T) { require.Equal(t, pass, pass) }) - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // The bridge should load the user. require.Equal(t, []string{userID}, bridge.GetUserIDs()) require.Equal(t, []string{userID}, getConnectedUserIDs(t, bridge)) @@ -514,7 +514,7 @@ func TestBridge_BridgePass(t *testing.T) { func TestBridge_AddressMode(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID, err := bridge.LoginFull(ctx, username, password, nil, nil) require.NoError(t, err) @@ -552,7 +552,7 @@ func TestBridge_AddressMode(t *testing.T) { func TestBridge_LoginLogoutRepeated(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { for i := 0; i < 10; i++ { // Log the user in. userID := must(bridge.LoginFull(ctx, username, password, nil, nil)) @@ -568,7 +568,7 @@ func TestBridge_LogoutOffline(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { var userID string - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID = must(bridge.LoginFull(ctx, username, password, nil, nil)) @@ -590,7 +590,7 @@ func TestBridge_LogoutOffline(t *testing.T) { // Go back online. netCtl.Enable() - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // The user is still disconnected. require.Equal(t, []string{userID}, bridge.GetUserIDs()) require.Empty(t, getConnectedUserIDs(t, bridge)) @@ -600,7 +600,7 @@ func TestBridge_LogoutOffline(t *testing.T) { func TestBridge_DeleteDisconnected(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID, err := bridge.LoginFull(ctx, username, password, nil, nil) require.NoError(t, err) @@ -628,7 +628,7 @@ func TestBridge_DeleteDisconnected(t *testing.T) { func TestBridge_DeleteOffline(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, storeKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, storeKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Login the user. userID, err := bridge.LoginFull(ctx, username, password, nil, nil) require.NoError(t, err) @@ -652,7 +652,7 @@ func TestBridge_DeleteOffline(t *testing.T) { func TestBridge_UserInfo_Alias(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, vaultKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Create a new user. userID, _, err := s.CreateUser("primary", []byte("password")) require.NoError(t, err) @@ -675,7 +675,7 @@ func TestBridge_UserInfo_Alias(t *testing.T) { func TestBridge_User_Refresh(t *testing.T) { withEnv(t, func(ctx context.Context, s *server.Server, netCtl *proton.NetCtl, locator bridge.Locator, vaultKey []byte) { - withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, mocks *bridge.Mocks) { + withBridge(ctx, t, s.GetHostURL(), netCtl, locator, vaultKey, func(bridge *bridge.Bridge, _ *bridge.Mocks) { // Get a channel of sync started events. syncStartCh, done := chToType[events.Event, events.SyncStarted](bridge.GetEvents(events.SyncStarted{})) defer done() diff --git a/internal/cookies/jar_test.go b/internal/cookies/jar_test.go index 78329980..a0ee8686 100644 --- a/internal/cookies/jar_test.go +++ b/internal/cookies/jar_test.go @@ -151,7 +151,7 @@ func getClientWithJar(t *testing.T, persister Persister) (*http.Client, *Jar) { func getTestServer(t *testing.T, wantCookies []testCookie) *httptest.Server { mux := http.NewServeMux() - mux.HandleFunc("/set", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/set", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { for _, cookie := range wantCookies { http.SetCookie(w, &http.Cookie{ Name: cookie.name, diff --git a/internal/crash/actions.go b/internal/crash/actions.go index e5aa9106..4a63f84c 100644 --- a/internal/crash/actions.go +++ b/internal/crash/actions.go @@ -26,7 +26,7 @@ import ( // ShowErrorNotification shows a system notification that the app with the given appName has crashed. // NOTE: Icons shouldn't be hardcoded. func ShowErrorNotification(appName string) RecoveryAction { - return func(r interface{}) error { + return func(_ interface{}) error { notify := notificator.New(notificator.Options{ DefaultIcon: "../frontend/ui/icon/icon.png", AppName: appName, diff --git a/internal/dialer/dialer_pinning_reporter_test.go b/internal/dialer/dialer_pinning_reporter_test.go index efab4f1c..c236420e 100644 --- a/internal/dialer/dialer_pinning_reporter_test.go +++ b/internal/dialer/dialer_pinning_reporter_test.go @@ -31,7 +31,7 @@ import ( func TestTLSReporter_DoubleReport(t *testing.T) { reportCounter := 0 - reportServer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + reportServer := httptest.NewTLSServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) { reportCounter++ })) diff --git a/internal/dialer/dialer_proxy_provider_test.go b/internal/dialer/dialer_proxy_provider_test.go index b7c30192..818721db 100644 --- a/internal/dialer/dialer_proxy_provider_test.go +++ b/internal/dialer/dialer_proxy_provider_test.go @@ -33,7 +33,7 @@ func TestProxyProvider_FindProxy(t *testing.T) { defer closeServer(proxy) p := newProxyProvider(NewBasicTLSDialer(""), "", []string{"not used"}, async.NoopPanicHandler{}) - p.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { return []string{proxy.URL}, nil } + p.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{proxy.URL}, nil } url, err := p.findReachableServer() r.NoError(t, err) @@ -49,7 +49,7 @@ func TestProxyProvider_FindProxy_ChooseReachableProxy(t *testing.T) { closeServer(unreachableProxy) p := newProxyProvider(NewBasicTLSDialer(""), "", []string{"not used"}, async.NoopPanicHandler{}) - p.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { + p.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{reachableProxy.URL, unreachableProxy.URL}, nil } @@ -70,7 +70,7 @@ func TestProxyProvider_FindProxy_ChooseTrustedProxy(t *testing.T) { dialer := NewPinningTLSDialer(NewBasicTLSDialer(""), reporter, checker) p := newProxyProvider(dialer, "", []string{"not used"}, async.NoopPanicHandler{}) - p.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { + p.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{untrustedProxy.URL, trustedProxy.URL}, nil } @@ -87,7 +87,7 @@ func TestProxyProvider_FindProxy_FailIfNoneReachable(t *testing.T) { closeServer(unreachableProxy2) p := newProxyProvider(NewBasicTLSDialer(""), "", []string{"not used"}, async.NoopPanicHandler{}) - p.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { + p.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{unreachableProxy1.URL, unreachableProxy2.URL}, nil } @@ -107,7 +107,7 @@ func TestProxyProvider_FindProxy_FailIfNoneTrusted(t *testing.T) { dialer := NewPinningTLSDialer(NewBasicTLSDialer(""), reporter, checker) p := newProxyProvider(dialer, "", []string{"not used"}, async.NoopPanicHandler{}) - p.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { + p.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{untrustedProxy1.URL, untrustedProxy2.URL}, nil } @@ -118,7 +118,7 @@ func TestProxyProvider_FindProxy_FailIfNoneTrusted(t *testing.T) { func TestProxyProvider_FindProxy_RefreshCacheTimeout(t *testing.T) { p := newProxyProvider(NewBasicTLSDialer(""), "", []string{"not used"}, async.NoopPanicHandler{}) p.cacheRefreshTimeout = 1 * time.Second - p.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { time.Sleep(2 * time.Second); return nil, nil } + p.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { time.Sleep(2 * time.Second); return nil, nil } // We should fail to refresh the proxy cache because the doh provider // takes 2 seconds to respond but we timeout after just 1 second. @@ -135,7 +135,7 @@ func TestProxyProvider_FindProxy_CanReachTimeout(t *testing.T) { p := newProxyProvider(NewBasicTLSDialer(""), "", []string{"not used"}, async.NoopPanicHandler{}) p.canReachTimeout = 1 * time.Second - p.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { return []string{slowProxy.URL}, nil } + p.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{slowProxy.URL}, nil } // We should fail to reach the returned proxy because it takes 2 seconds // to reach it and we only allow 1. diff --git a/internal/dialer/dialer_proxy_test.go b/internal/dialer/dialer_proxy_test.go index b092b3f6..a170858b 100644 --- a/internal/dialer/dialer_proxy_test.go +++ b/internal/dialer/dialer_proxy_test.go @@ -112,7 +112,7 @@ vwRMog6lPhlRhHh/FZ43Cg== // getUntrustedServer returns a server but it doesn't add its public key to the list of pinned ones. func getUntrustedServer() *httptest.Server { - server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) + server := httptest.NewUnstartedServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})) cert, err := tls.X509KeyPair([]byte(servercrt), []byte(serverkey)) if err != nil { @@ -145,7 +145,7 @@ func TestProxyDialer_UseProxy(t *testing.T) { provider := newProxyProvider(NewBasicTLSDialer(""), "", DoHProviders, async.NoopPanicHandler{}) d := NewProxyTLSDialer(NewBasicTLSDialer(""), "", async.NoopPanicHandler{}) d.proxyProvider = provider - provider.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { return []string{trustedProxy.URL}, nil } + provider.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{trustedProxy.URL}, nil } err := d.switchToReachableServer() require.NoError(t, err) @@ -163,7 +163,7 @@ func TestProxyDialer_UseProxy_MultipleTimes(t *testing.T) { provider := newProxyProvider(NewBasicTLSDialer(""), "", DoHProviders, async.NoopPanicHandler{}) d := NewProxyTLSDialer(NewBasicTLSDialer(""), "", async.NoopPanicHandler{}) d.proxyProvider = provider - provider.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { return []string{proxy1.URL}, nil } + provider.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{proxy1.URL}, nil } err := d.switchToReachableServer() require.NoError(t, err) @@ -172,7 +172,7 @@ func TestProxyDialer_UseProxy_MultipleTimes(t *testing.T) { // Have to wait so as to not get rejected. time.Sleep(proxyLookupWait) - provider.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { return []string{proxy2.URL}, nil } + provider.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{proxy2.URL}, nil } err = d.switchToReachableServer() require.NoError(t, err) require.Equal(t, formatAsAddress(proxy2.URL), d.proxyAddress) @@ -180,7 +180,7 @@ func TestProxyDialer_UseProxy_MultipleTimes(t *testing.T) { // Have to wait so as to not get rejected. time.Sleep(proxyLookupWait) - provider.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { return []string{proxy3.URL}, nil } + provider.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{proxy3.URL}, nil } err = d.switchToReachableServer() require.NoError(t, err) require.Equal(t, formatAsAddress(proxy3.URL), d.proxyAddress) @@ -195,7 +195,7 @@ func TestProxyDialer_UseProxy_RevertAfterTime(t *testing.T) { d.proxyProvider = provider d.proxyUseDuration = time.Second - provider.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { return []string{trustedProxy.URL}, nil } + provider.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{trustedProxy.URL}, nil } err := d.switchToReachableServer() require.NoError(t, err) @@ -216,7 +216,7 @@ func TestProxyDialer_UseProxy_RevertIfProxyStopsWorkingAndOriginalAPIIsReachable provider := newProxyProvider(NewBasicTLSDialer(""), "", DoHProviders, async.NoopPanicHandler{}) d := NewProxyTLSDialer(NewBasicTLSDialer(""), "", async.NoopPanicHandler{}) d.proxyProvider = provider - provider.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { return []string{trustedProxy.URL}, nil } + provider.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{trustedProxy.URL}, nil } err := d.switchToReachableServer() require.NoError(t, err) @@ -246,7 +246,7 @@ func TestProxyDialer_UseProxy_FindSecondAlternativeIfFirstFailsAndAPIIsStillBloc provider := newProxyProvider(NewBasicTLSDialer(""), "", DoHProviders, async.NoopPanicHandler{}) d := NewProxyTLSDialer(NewBasicTLSDialer(""), "", async.NoopPanicHandler{}) d.proxyProvider = provider - provider.dohLookup = func(ctx context.Context, q, p string) ([]string, error) { return []string{proxy1.URL, proxy2.URL}, nil } + provider.dohLookup = func(_ context.Context, _, _ string) ([]string, error) { return []string{proxy1.URL, proxy2.URL}, nil } err := d.switchToReachableServer() require.NoError(t, err) diff --git a/internal/frontend/grpc/service.go b/internal/frontend/grpc/service.go index 3b482eaf..833c3658 100644 --- a/internal/frontend/grpc/service.go +++ b/internal/frontend/grpc/service.go @@ -581,7 +581,7 @@ func validateServerToken(ctx context.Context, wantToken string) error { // newUnaryTokenValidator checks the server token for every unary gRPC call. func newUnaryTokenValidator(wantToken string) grpc.UnaryServerInterceptor { - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { + return func(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { if err := validateServerToken(ctx, wantToken); err != nil { return nil, err } @@ -592,7 +592,7 @@ func newUnaryTokenValidator(wantToken string) grpc.UnaryServerInterceptor { // newStreamTokenValidator checks the server token for every gRPC stream request. func newStreamTokenValidator(wantToken string) grpc.StreamServerInterceptor { - return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { + return func(srv interface{}, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error { if err := validateServerToken(stream.Context(), wantToken); err != nil { return err } @@ -626,9 +626,7 @@ func (s *Service) monitorParentPID() { go func() { defer async.HandlePanic(s.panicHandler) - if err := s.quit(); err != nil { - logrus.WithError(err).Error("Error on quit") - } + s.quit() }() } diff --git a/internal/frontend/grpc/service_methods.go b/internal/frontend/grpc/service_methods.go index 34aec694..778bbc13 100644 --- a/internal/frontend/grpc/service_methods.go +++ b/internal/frontend/grpc/service_methods.go @@ -110,10 +110,11 @@ func (s *Service) GuiReady(_ context.Context, _ *emptypb.Empty) (*GuiReadyRespon func (s *Service) Quit(_ context.Context, _ *emptypb.Empty) (*emptypb.Empty, error) { defer async.HandlePanic(s.panicHandler) s.log.Debug("Quit") - return &emptypb.Empty{}, s.quit() + s.quit() + return &emptypb.Empty{}, nil } -func (s *Service) quit() error { +func (s *Service) quit() { // Windows is notably slow at Quitting. We do it in a goroutine to speed things up a bit. go func() { defer async.HandlePanic(s.panicHandler) @@ -132,8 +133,6 @@ func (s *Service) quit() error { // The following call is launched as a goroutine, as it will wait for current calls to end, including this one. s.grpcServer.GracefulStop() // gRPC does clean up and remove the file socket if used. }() - - return nil } // Restart implement the Restart gRPC service call. diff --git a/internal/frontend/grpc/service_stream.go b/internal/frontend/grpc/service_stream.go index 990d5733..03685483 100644 --- a/internal/frontend/grpc/service_stream.go +++ b/internal/frontend/grpc/service_stream.go @@ -76,7 +76,8 @@ func (s *Service) RunEventStream(request *EventStreamRequest, server Bridge_RunE } case <-server.Context().Done(): s.log.Debug("Client closed the stream, exiting") - return s.quit() + s.quit() + return nil } } } diff --git a/internal/legacy/credentials/credentials_test.go b/internal/legacy/credentials/credentials_test.go index 99843461..87288197 100644 --- a/internal/legacy/credentials/credentials_test.go +++ b/internal/legacy/credentials/credentials_test.go @@ -78,7 +78,7 @@ func FuzzUnmarshal(f *testing.F) { str := strings.Join(items, sep) f.Add([]byte(str)) - f.Fuzz(func(t *testing.T, secret []byte) { + f.Fuzz(func(_ *testing.T, secret []byte) { encodedSecret := base64.StdEncoding.EncodeToString(secret) creds := &Credentials{} diff --git a/internal/logging/rotator_test.go b/internal/logging/rotator_test.go index 4642c6ca..23816414 100644 --- a/internal/logging/rotator_test.go +++ b/internal/logging/rotator_test.go @@ -172,7 +172,7 @@ func benchRotate(b *testing.B, logSize int64, getFile func(index int) (io.WriteC } func getTestFile(b *testing.B, dir string, length int) func(int) (io.WriteCloser, error) { - return func(index int) (io.WriteCloser, error) { + return func(_ int) (io.WriteCloser, error) { b.StopTimer() defer b.StartTimer() diff --git a/internal/services/syncservice/stage_build.go b/internal/services/syncservice/stage_build.go index 55f9fd75..ac966e67 100644 --- a/internal/services/syncservice/stage_build.go +++ b/internal/services/syncservice/stage_build.go @@ -136,7 +136,7 @@ func (b *BuildStage) run(ctx context.Context) { return nil } - result, err := parallel.MapContext(ctx, maxMessagesInParallel, chunk, func(ctx context.Context, msg proton.FullMessage) (BuildResult, error) { + result, err := parallel.MapContext(ctx, maxMessagesInParallel, chunk, func(_ context.Context, msg proton.FullMessage) (BuildResult, error) { defer async.HandlePanic(b.panicHandler) kr, ok := addrKRs[msg.AddressID] diff --git a/internal/services/syncservice/stage_build_test.go b/internal/services/syncservice/stage_build_test.go index 4169a1e1..9f0201d6 100644 --- a/internal/services/syncservice/stage_build_test.go +++ b/internal/services/syncservice/stage_build_test.go @@ -253,7 +253,7 @@ func TestBuildStage_OtherErrorsFailJob(t *testing.T) { expectedErr := errors.New("something went wrong") - tj.messageBuilder.EXPECT().WithKeys(gomock.Any()).DoAndReturn(func(f func(*crypto.KeyRing, map[string]*crypto.KeyRing) error) error { + tj.messageBuilder.EXPECT().WithKeys(gomock.Any()).DoAndReturn(func(_ func(*crypto.KeyRing, map[string]*crypto.KeyRing) error) error { return expectedErr }) diff --git a/internal/services/syncservice/stage_download_test.go b/internal/services/syncservice/stage_download_test.go index 27fda594..8ebfeac2 100644 --- a/internal/services/syncservice/stage_download_test.go +++ b/internal/services/syncservice/stage_download_test.go @@ -119,12 +119,12 @@ func TestAutoDownloadScale_429or500x(t *testing.T) { for _, d := range data { switch d { case "m7": - call429 := client.EXPECT().GetMessage(gomock.Any(), gomock.Eq("m7")).DoAndReturn(func(_ context.Context, id string) (proton.Message, error) { + call429 := client.EXPECT().GetMessage(gomock.Any(), gomock.Eq("m7")).DoAndReturn(func(_ context.Context, _ string) (proton.Message, error) { return proton.Message{}, &proton.APIError{Status: 429} }) client.EXPECT().GetMessage(gomock.Any(), gomock.Eq("m7")).After(call429).DoAndReturn(autoDownloadScaleClientDoAndReturn) case "m23": - call503 := client.EXPECT().GetMessage(gomock.Any(), gomock.Eq("m23")).DoAndReturn(func(_ context.Context, id string) (proton.Message, error) { + call503 := client.EXPECT().GetMessage(gomock.Any(), gomock.Eq("m23")).DoAndReturn(func(_ context.Context, _ string) (proton.Message, error) { return proton.Message{}, &proton.APIError{Status: 503} }) client.EXPECT().GetMessage(gomock.Any(), gomock.Eq("m23")).After(call503).DoAndReturn(autoDownloadScaleClientDoAndReturn) diff --git a/internal/services/userevents/service_test.go b/internal/services/userevents/service_test.go index 078ab23e..51895b2a 100644 --- a/internal/services/userevents/service_test.go +++ b/internal/services/userevents/service_test.go @@ -191,7 +191,7 @@ func TestService_OnBadEventServiceIsPaused(t *testing.T) { NewEventID: secondEventID, EventInfo: secondEvent[0].String(), Error: fmt.Errorf("failed to apply message events: %w", badEventErr), - }).Do(func(_ context.Context, event events.Event) { + }).Do(func(_ context.Context, _ events.Event) { group.Go(context.Background(), "", "", func(_ context.Context) { // Use background context to avoid having the request cancelled require.True(t, service.IsPaused()) diff --git a/internal/user/keys_test.go b/internal/user/keys_test.go index 376799b6..9dee82f4 100644 --- a/internal/user/keys_test.go +++ b/internal/user/keys_test.go @@ -32,7 +32,7 @@ func BenchmarkAddrKeyRing(b *testing.B) { b.StopTimer() withAPI(b, context.Background(), func(ctx context.Context, s *server.Server, m *proton.Manager) { - withAccount(b, s, "username", "password", []string{"email@pm.me"}, func(userID string, addrIDs []string) { + withAccount(b, s, "username", "password", []string{"email@pm.me"}, func(_ string, _ []string) { withUser(b, ctx, s, m, "username", "password", func(user *User) { b.StartTimer() @@ -43,7 +43,7 @@ func BenchmarkAddrKeyRing(b *testing.B) { require.NoError(b, err) for i := 0; i < b.N; i++ { - require.NoError(b, usertypes.WithAddrKRs(apiUser, apiAddrs, user.vault.KeyPass(), func(_ *crypto.KeyRing, addrKRs map[string]*crypto.KeyRing) error { + require.NoError(b, usertypes.WithAddrKRs(apiUser, apiAddrs, user.vault.KeyPass(), func(_ *crypto.KeyRing, _ map[string]*crypto.KeyRing) error { return nil })) } diff --git a/internal/vault/user_test.go b/internal/vault/user_test.go index 8a7582fb..c294dfdc 100644 --- a/internal/vault/user_test.go +++ b/internal/vault/user_test.go @@ -27,7 +27,7 @@ import ( func TestUser_New(t *testing.T) { // Replace the token generator with a dummy one. - vault.RandomToken = func(size int) ([]byte, error) { + vault.RandomToken = func(_ int) ([]byte, error) { return []byte("token"), nil } @@ -243,7 +243,7 @@ func TestUser_ForEach(t *testing.T) { func TestUser_ShouldResync(t *testing.T) { // Replace the token generator with a dummy one. - vault.RandomToken = func(size int) ([]byte, error) { + vault.RandomToken = func(_ int) ([]byte, error) { return []byte("token"), nil } diff --git a/pkg/files/removal.go b/pkg/files/removal.go index 8e5f2ab0..d4ab27fe 100644 --- a/pkg/files/removal.go +++ b/pkg/files/removal.go @@ -56,7 +56,7 @@ func (op *OpRemove) Do() error { func remove(dir string, except ...string) error { var toRemove []string - if err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + if err := filepath.Walk(dir, func(path string, _ os.FileInfo, _ error) error { for _, exception := range except { if path == exception || strings.HasPrefix(exception, path) || strings.HasPrefix(path, exception) { return nil diff --git a/pkg/message/header_test.go b/pkg/message/header_test.go index 340aec2c..48e590db 100644 --- a/pkg/message/header_test.go +++ b/pkg/message/header_test.go @@ -126,7 +126,7 @@ func FuzzReadHeaderBody(f *testing.F) { f.Add([]byte(data0)) f.Add([]byte(data1)) - f.Fuzz(func(t *testing.T, b []byte) { + f.Fuzz(func(_ *testing.T, b []byte) { _, _, _ = readHeaderBody(b) }) } diff --git a/pkg/message/parser.go b/pkg/message/parser.go index b0ff8730..f27d2c9a 100644 --- a/pkg/message/parser.go +++ b/pkg/message/parser.go @@ -241,7 +241,7 @@ func collectAttachments(p *parser.Parser) ([]Attachment, error) { return nil }). - RegisterContentTypeHandler("text/.*", func(p *parser.Part) error { + RegisterContentTypeHandler("text/.*", func(_ *parser.Part) error { return nil }). RegisterDefaultHandler(func(p *parser.Part) error { @@ -317,14 +317,14 @@ func collectBodyParts(p *parser.Parser, preferredContentType string) (parser.Par return bestChoice(childParts, preferredContentType), nil }). - RegisterRule("text/plain", func(p *parser.Part, visit parser.Visit) (interface{}, error) { + RegisterRule("text/plain", func(p *parser.Part, _ parser.Visit) (interface{}, error) { if p.IsAttachment() { return parser.Parts{}, nil } return parser.Parts{p}, nil }). - RegisterRule("text/html", func(p *parser.Part, visit parser.Visit) (interface{}, error) { + RegisterRule("text/html", func(p *parser.Part, _ parser.Visit) (interface{}, error) { if p.IsAttachment() { return parser.Parts{}, nil } @@ -404,7 +404,7 @@ func determineBodyMIMEType(p *parser.Parser) (string, error) { var isHTML bool w := p.NewWalker(). - RegisterContentTypeHandler("text/html", func(p *parser.Part) (err error) { + RegisterContentTypeHandler("text/html", func(_ *parser.Part) (err error) { isHTML = true return }) diff --git a/pkg/message/parser/parser_test.go b/pkg/message/parser/parser_test.go index c9c71dec..1cc28d82 100644 --- a/pkg/message/parser/parser_test.go +++ b/pkg/message/parser/parser_test.go @@ -62,7 +62,7 @@ func FuzzNewParser(f *testing.F) { f.Add(inSeed1) f.Add(inSeed2) - f.Fuzz(func(t *testing.T, data []byte) { + f.Fuzz(func(_ *testing.T, data []byte) { _, _ = New(bytes.NewReader(data)) }) } diff --git a/pkg/message/parser/part.go b/pkg/message/parser/part.go index 02604d53..b393f13f 100644 --- a/pkg/message/parser/part.go +++ b/pkg/message/parser/part.go @@ -133,7 +133,7 @@ func (p *Part) ConvertMetaCharset() error { // Override charset to UTF-8 in meta headers only if needed. var metaModified = false - goquery.NewDocumentFromNode(doc).Find("meta").Each(func(n int, sel *goquery.Selection) { + goquery.NewDocumentFromNode(doc).Find("meta").Each(func(_ int, sel *goquery.Selection) { if val, ok := sel.Attr("content"); ok { t, params, err := pmmime.ParseMediaType(val) if err != nil { diff --git a/pkg/message/parser/walker_test.go b/pkg/message/parser/walker_test.go index b295ae5a..eea811b0 100644 --- a/pkg/message/parser/walker_test.go +++ b/pkg/message/parser/walker_test.go @@ -104,11 +104,11 @@ func TestWalkerDispositionAndTypeHandler_TypeDefinedFirst(t *testing.T) { var typeCalled, dispCalled bool walker := p.NewWalker(). - RegisterContentTypeHandler("application/octet-stream", func(p *Part) (err error) { + RegisterContentTypeHandler("application/octet-stream", func(_ *Part) (err error) { typeCalled = true return }). - RegisterContentDispositionHandler("attachment", func(p *Part) (err error) { + RegisterContentDispositionHandler("attachment", func(_ *Part) (err error) { dispCalled = true return }) diff --git a/tests/user_test.go b/tests/user_test.go index 5030e534..9d811bfb 100644 --- a/tests/user_test.go +++ b/tests/user_test.go @@ -315,7 +315,7 @@ func (s *scenario) drafAtIndexWasMovedToTrashForAddressOfAccount(draftIndex int, defer cancel() return s.t.withClient(ctx, username, func(ctx context.Context, c *proton.Client) error { - return s.t.withAddrKR(ctx, c, username, s.t.getUserByName(username).getAddrID(address), func(_ context.Context, addrKR *crypto.KeyRing) error { + return s.t.withAddrKR(ctx, c, username, s.t.getUserByName(username).getAddrID(address), func(_ context.Context, _ *crypto.KeyRing) error { if err := c.UnlabelMessages(ctx, []string{draftID}, proton.DraftsLabel); err != nil { return fmt.Errorf("failed to unlabel draft") } diff --git a/utils/bridge-rollout/bridge-rollout.go b/utils/bridge-rollout/bridge-rollout.go index e199e20c..deb468c1 100644 --- a/utils/bridge-rollout/bridge-rollout.go +++ b/utils/bridge-rollout/bridge-rollout.go @@ -62,7 +62,7 @@ func main() { func getRollout(_ *cli.Context) error { return app.WithLocations(func(locations *locations.Locations) error { return app.WithKeychainList(async.NoopPanicHandler{}, func(keychains *keychain.List) error { - return app.WithVault(locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, insecure, corrupt bool) error { + return app.WithVault(locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, _, _ bool) error { fmt.Println(vault.GetUpdateRollout()) return nil }) @@ -73,7 +73,7 @@ func getRollout(_ *cli.Context) error { func setRollout(c *cli.Context) error { return app.WithLocations(func(locations *locations.Locations) error { return app.WithKeychainList(async.NoopPanicHandler{}, func(keychains *keychain.List) error { - return app.WithVault(locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, insecure, corrupt bool) error { + return app.WithVault(locations, keychains, async.NoopPanicHandler{}, func(vault *vault.Vault, _, _ bool) error { clamped := max(0.0, min(1.0, c.Float64("value"))) if err := vault.SetUpdateRollout(clamped); err != nil { return err