-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf5d444
commit c663738
Showing
7 changed files
with
121 additions
and
4 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
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
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,29 @@ | ||
package tests | ||
|
||
import ( | ||
"crypto/tls" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/bradenaw/juniper/xslices" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// nolint:gosec | ||
func TestNonUTF8(t *testing.T) { | ||
runOneToOneTest(t, defaultServerOptions(t), func(_ *testConnection, s *testSession) { | ||
// Create a new connection. | ||
c := s.newConnection() | ||
|
||
// Things work fine when the command is valid UTF-8. | ||
c.C("tag capability").OK("tag") | ||
|
||
// Performing a TLS handshake should fail; the server will drop the connection. | ||
require.Error(t, tls.Client(c.conn, &tls.Config{InsecureSkipVerify: true}).Handshake()) | ||
|
||
// We should have reported the bad UTF-8 command. | ||
require.True(t, xslices.Any(s.reporter.getReports(), func(report report) bool { | ||
return reflect.DeepEqual(report.val, "Received invalid UTF-8 command") | ||
})) | ||
}) | ||
} |
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,60 @@ | ||
package tests | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/ProtonMail/gluon/reporter" | ||
) | ||
|
||
type testReporter struct { | ||
reports []report | ||
lock sync.RWMutex | ||
} | ||
|
||
type report struct { | ||
val any | ||
ctx reporter.Context | ||
} | ||
|
||
func (r *testReporter) getReports() []report { | ||
r.lock.RLock() | ||
defer r.lock.RUnlock() | ||
|
||
return r.reports | ||
} | ||
|
||
func (r *testReporter) ReportException(val any) error { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
||
r.reports = append(r.reports, report{val: val}) | ||
|
||
return nil | ||
} | ||
|
||
func (r *testReporter) ReportMessage(val string) error { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
||
r.reports = append(r.reports, report{val: val}) | ||
|
||
return nil | ||
} | ||
|
||
func (r *testReporter) ReportMessageWithContext(val string, ctx reporter.Context) error { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
||
r.reports = append(r.reports, report{val: val, ctx: ctx}) | ||
|
||
return nil | ||
} | ||
|
||
func (r *testReporter) ReportExceptionWithContext(val any, ctx reporter.Context) error { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
||
r.reports = append(r.reports, report{val: val, ctx: ctx}) | ||
|
||
return nil | ||
} |
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 |
---|---|---|
|
@@ -4,8 +4,10 @@ import ( | |
"fmt" | ||
"testing" | ||
"time" | ||
"unicode/utf8" | ||
|
||
"github.com/ProtonMail/gluon/imap" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/text/encoding/htmlindex" | ||
) | ||
|
||
|
@@ -31,11 +33,18 @@ func TestSearchCharSetISO88591(t *testing.T) { | |
// 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)) | ||
|
||
// Append a message with that as the body. | ||
c.doAppend("inbox", "To: [email protected]\r\n\r\nééé").expect("OK") | ||
|
||
// Search for it with ISO-8859-1 encoding. | ||
// Search for it with ISO-8859-1 encoding (literal). | ||
c.Cf(`TAG SEARCH CHARSET ISO-8859-1 BODY {%v}`, len(b)).Continue().Cb(b).S("* SEARCH 1").OK("TAG") | ||
|
||
// Search for it with ISO-8859-1 encoding (direct). | ||
// TODO(GODT-2165): This should work, but it doesn't. | ||
// c.Cf(`TAG SEARCH CHARSET ISO-8859-1 BODY ` + string(b)).S("* SEARCH 1").OK("TAG") | ||
}) | ||
} | ||
|
||
|
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
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