mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 12:46:46 +00:00
Other: Ensure context is string in sentry reports
This commit is contained in:
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.18
|
|||||||
require (
|
require (
|
||||||
github.com/0xAX/notificator v0.0.0-20220220101646-ee9b8921e557
|
github.com/0xAX/notificator v0.0.0-20220220101646-ee9b8921e557
|
||||||
github.com/Masterminds/semver/v3 v3.1.1
|
github.com/Masterminds/semver/v3 v3.1.1
|
||||||
github.com/ProtonMail/gluon v0.14.1
|
github.com/ProtonMail/gluon v0.14.2-0.20221129115938-cf5d444d3015
|
||||||
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a
|
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a
|
||||||
github.com/ProtonMail/go-proton-api v0.1.2
|
github.com/ProtonMail/go-proton-api v0.1.2
|
||||||
github.com/ProtonMail/go-rfc5322 v0.11.0
|
github.com/ProtonMail/go-rfc5322 v0.11.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@ -28,8 +28,8 @@ github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf h1:yc9daCCYUefEs
|
|||||||
github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf/go.mod h1:o0ESU9p83twszAU8LBeJKFAAMX14tISa0yk4Oo5TOqo=
|
github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf/go.mod h1:o0ESU9p83twszAU8LBeJKFAAMX14tISa0yk4Oo5TOqo=
|
||||||
github.com/ProtonMail/docker-credential-helpers v1.1.0 h1:+kvUIpwWcbtP3WFv5sSvkFn/XLzSqPOB5AAthuk9xPk=
|
github.com/ProtonMail/docker-credential-helpers v1.1.0 h1:+kvUIpwWcbtP3WFv5sSvkFn/XLzSqPOB5AAthuk9xPk=
|
||||||
github.com/ProtonMail/docker-credential-helpers v1.1.0/go.mod h1:mK0aBveCxhnQ756AmaTfXMZDeULvheYVhF/MWMErN5g=
|
github.com/ProtonMail/docker-credential-helpers v1.1.0/go.mod h1:mK0aBveCxhnQ756AmaTfXMZDeULvheYVhF/MWMErN5g=
|
||||||
github.com/ProtonMail/gluon v0.14.1 h1:7iXLasYoBGaOW88k4p29w7bPAOpY6aR6GErdVRu8MZs=
|
github.com/ProtonMail/gluon v0.14.2-0.20221129115938-cf5d444d3015 h1:fA6ggn06yfSXTppTjmlYeBk9lxeURx8ARBKLHId5v7Q=
|
||||||
github.com/ProtonMail/gluon v0.14.1/go.mod h1:z2AxLIiBCT1K+0OBHyaDI7AEaO5qI6/BEC2TE42vs4Q=
|
github.com/ProtonMail/gluon v0.14.2-0.20221129115938-cf5d444d3015/go.mod h1:z2AxLIiBCT1K+0OBHyaDI7AEaO5qI6/BEC2TE42vs4Q=
|
||||||
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a h1:D+aZah+k14Gn6kmL7eKxoo/4Dr/lK3ChBcwce2+SQP4=
|
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a h1:D+aZah+k14Gn6kmL7eKxoo/4Dr/lK3ChBcwce2+SQP4=
|
||||||
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a/go.mod h1:oTGdE7/DlWIr23G0IKW3OXK9wZ5Hw1GGiaJFccTvZi4=
|
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a/go.mod h1:oTGdE7/DlWIr23G0IKW3OXK9wZ5Hw1GGiaJFccTvZi4=
|
||||||
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
|
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
|
||||||
|
|||||||
@ -45,7 +45,6 @@ import (
|
|||||||
"github.com/ProtonMail/proton-bridge/v3/tests"
|
"github.com/ProtonMail/proton-bridge/v3/tests"
|
||||||
"github.com/bradenaw/juniper/xslices"
|
"github.com/bradenaw/juniper/xslices"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"go.uber.org/goleak"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -56,10 +55,6 @@ var (
|
|||||||
v2_4_0 = semver.MustParse("2.4.0")
|
v2_4_0 = semver.MustParse("2.4.0")
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
|
||||||
goleak.VerifyTestMain(m, goleak.IgnoreCurrent())
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
user.EventPeriod = 100 * time.Millisecond
|
user.EventPeriod = 100 * time.Millisecond
|
||||||
user.EventJitter = 0
|
user.EventJitter = 0
|
||||||
@ -561,9 +556,9 @@ func withBridge(
|
|||||||
mocks.Reporter,
|
mocks.Reporter,
|
||||||
|
|
||||||
// The logging stuff.
|
// The logging stuff.
|
||||||
false,
|
os.Getenv("BRIDGE_LOG_IMAP_CLIENT") == "1",
|
||||||
false,
|
os.Getenv("BRIDGE_LOG_IMAP_SERVER") == "1",
|
||||||
false,
|
os.Getenv("BRIDGE_LOG_SMTP") == "1",
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Empty(t, bridge.GetErrors())
|
require.Empty(t, bridge.GetErrors())
|
||||||
|
|||||||
36
internal/bridge/main_test.go
Normal file
36
internal/bridge/main_test.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright (c) 2022 Proton AG
|
||||||
|
//
|
||||||
|
// This file is part of Proton Mail Bridge.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package bridge_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"go.uber.org/goleak"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
if level := os.Getenv("BRIDGE_LOG_LEVEL"); level != "" {
|
||||||
|
if parsed, err := logrus.ParseLevel(level); err == nil {
|
||||||
|
logrus.SetLevel(parsed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
goleak.VerifyTestMain(m, goleak.IgnoreCurrent())
|
||||||
|
}
|
||||||
78
internal/bridge/sentry_test.go
Normal file
78
internal/bridge/sentry_test.go
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
// Copyright (c) 2022 Proton AG
|
||||||
|
//
|
||||||
|
// This file is part of Proton Mail Bridge.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package bridge_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ProtonMail/gluon/liner"
|
||||||
|
"github.com/ProtonMail/go-proton-api"
|
||||||
|
"github.com/ProtonMail/go-proton-api/server"
|
||||||
|
"github.com/ProtonMail/proton-bridge/v3/internal/bridge"
|
||||||
|
"github.com/ProtonMail/proton-bridge/v3/internal/constants"
|
||||||
|
"github.com/ProtonMail/proton-bridge/v3/internal/events"
|
||||||
|
"github.com/golang/mock/gomock"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBridge_Report(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(b *bridge.Bridge, mocks *bridge.Mocks) {
|
||||||
|
syncCh, done := chToType[events.Event, events.SyncFinished](b.GetEvents(events.SyncFinished{}))
|
||||||
|
defer done()
|
||||||
|
|
||||||
|
// Log in the user.
|
||||||
|
userID, err := b.LoginFull(ctx, username, password, nil, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Wait until the sync has finished.
|
||||||
|
require.Equal(t, userID, (<-syncCh).UserID)
|
||||||
|
|
||||||
|
// Get the IMAP info.
|
||||||
|
info, err := b.GetUserInfo(userID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, info.State == bridge.Connected)
|
||||||
|
|
||||||
|
// Dial the IMAP port.
|
||||||
|
conn, err := net.Dial("tcp", fmt.Sprintf("%v:%v", constants.Host, b.GetIMAPPort()))
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer func() { require.NoError(t, conn.Close()) }()
|
||||||
|
|
||||||
|
// Sending garbage to the IMAP port should cause the bridge to report it.
|
||||||
|
mocks.Reporter.EXPECT().ReportMessageWithContext(
|
||||||
|
gomock.Eq("Failed to parse imap command"),
|
||||||
|
gomock.Any(),
|
||||||
|
).Return(nil)
|
||||||
|
|
||||||
|
// Read lines from the IMAP port.
|
||||||
|
lineCh := liner.New(conn).Lines(func() error { return nil })
|
||||||
|
|
||||||
|
// On connection, we should get the greeting.
|
||||||
|
require.Contains(t, string((<-lineCh).Line), "* OK")
|
||||||
|
|
||||||
|
// Send garbage data.
|
||||||
|
must(conn.Write([]byte("tag garbage\r\n")))
|
||||||
|
|
||||||
|
// Bridge will reply with BAD.
|
||||||
|
require.Contains(t, string((<-lineCh).Line), "tag BAD")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -138,7 +138,7 @@ func (r *Reporter) scopedReport(context map[string]interface{}, doReport func())
|
|||||||
scope.SetTags(tags)
|
scope.SetTags(tags)
|
||||||
if len(context) != 0 {
|
if len(context) != 0 {
|
||||||
scope.SetContexts(
|
scope.SetContexts(
|
||||||
map[string]map[string]interface{}{"bridge": context},
|
map[string]sentry.Context{"bridge": contextToString(context)},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
doReport()
|
doReport()
|
||||||
@ -204,3 +204,13 @@ func isFunctionFilteredOut(function string) bool {
|
|||||||
func Flush(maxWaiTime time.Duration) {
|
func Flush(maxWaiTime time.Duration) {
|
||||||
sentry.Flush(maxWaiTime)
|
sentry.Flush(maxWaiTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func contextToString(context sentry.Context) sentry.Context {
|
||||||
|
res := make(sentry.Context)
|
||||||
|
|
||||||
|
for k, v := range context {
|
||||||
|
res[k] = fmt.Sprintf("%v", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user