-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(GODT-2165): Detect TLS handshake header to avoid reporter spam
When not using SSL/TLS connections, identify whether the line input is a TSL header and if so, abort the connection without reporting invalid UTF8 events.
- Loading branch information
1 parent
549c1f0
commit 542c2bf
Showing
5 changed files
with
171 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package tests | ||
|
||
import ( | ||
"github.com/ProtonMail/gluon/reporter/mock_reporter" | ||
"github.com/emersion/go-imap/client" | ||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
"unicode/utf8" | ||
) | ||
|
||
func TestSSLConnectionOverStartTLS(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
reporter := mock_reporter.NewMockReporter(ctrl) | ||
|
||
defer ctrl.Finish() | ||
|
||
// Ensure the nothing is reported when connecting via TLS connection if we are not running with TLS | ||
runOneToOneTestClientWithAuth(t, defaultServerOptions(t, withReporter(reporter)), func(_ *client.Client, session *testSession) { | ||
_, err := client.DialTLS(session.listener.Addr().String(), nil) | ||
require.Error(t, err) | ||
}) | ||
} | ||
|
||
func TestNonUtf8CommandTriggersReporter(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
reporter := mock_reporter.NewMockReporter(ctrl) | ||
|
||
defer ctrl.Finish() | ||
|
||
reporter.EXPECT().ReportMessageWithContext("Received invalid UTF-8 command", gomock.Any()).Return(nil).Times(1) | ||
|
||
// Ensure the nothing is reported when connecting via TLS connection if we are not running with TLS | ||
runOneToOneTestWithAuth(t, defaultServerOptions(t, withReporter(reporter)), func(c *testConnection, session *testSession) { | ||
// Encode "ééé" as ISO-8859-1. | ||
b := enc("ééé", "ISO-8859-1") | ||
|
||
// Assert that b is no longer valid UTF-8. | ||
require.False(t, utf8.Valid(b)) | ||
|
||
// This will fail and produce a report | ||
c.Cf(`TAG SEARCH CHARSET ISO-8859-1 BODY ` + string(b)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters