diff --git a/pkg/config/settings/kvs_test.go b/pkg/config/settings/kvs_test.go index 0600409..641e04b 100644 --- a/pkg/config/settings/kvs_test.go +++ b/pkg/config/settings/kvs_test.go @@ -38,7 +38,7 @@ func TestLoadBadKeyValueStore(t *testing.T) { path, clean := newTmpFile(r) defer clean() - r.NoError(ioutil.WriteFile(path, []byte("{\"key\":\"MISSING_QUOTES"), 0700)) + r.NoError(ioutil.WriteFile(path, []byte("{\"key\":\"MISSING_QUOTES"), 0o700)) pref := newKeyValueStore(path) r.Equal("", pref.Get("key")) } @@ -103,7 +103,7 @@ func newTestEmptyKeyValueStore(r *require.Assertions) (*keyValueStore, func()) { func newTestKeyValueStore(r *require.Assertions) (*keyValueStore, func()) { path, clean := newTmpFile(r) - r.NoError(ioutil.WriteFile(path, []byte("{\"str\":\"value\",\"int\":\"42\",\"bool\":\"true\",\"falseBool\":\"t\"}"), 0700)) + r.NoError(ioutil.WriteFile(path, []byte("{\"str\":\"value\",\"int\":\"42\",\"bool\":\"true\",\"falseBool\":\"t\"}"), 0o700)) return newKeyValueStore(path), clean } diff --git a/pkg/files/removal_test.go b/pkg/files/removal_test.go index 8f9f8da..038d693 100644 --- a/pkg/files/removal_test.go +++ b/pkg/files/removal_test.go @@ -97,7 +97,7 @@ func newTestDir(t *testing.T, subdirs ...string) string { require.NoError(t, err) for _, target := range subdirs { - require.NoError(t, os.MkdirAll(filepath.Join(dir, target), 0700)) + require.NoError(t, os.MkdirAll(filepath.Join(dir, target), 0o700)) } return dir diff --git a/pkg/message/parser/parser_test.go b/pkg/message/parser/parser_test.go index 3e88fa3..d6e3c1d 100644 --- a/pkg/message/parser/parser_test.go +++ b/pkg/message/parser/parser_test.go @@ -36,7 +36,6 @@ func newTestParser(t *testing.T, msg string) *Parser { func getFileReader(filename string) io.ReadCloser { f, err := os.Open(filepath.Join("testdata", filename)) - if err != nil { panic(err) } diff --git a/pkg/message/parser/trimmer_test.go b/pkg/message/parser/trimmer_test.go index d8fa3dc..f2626da 100644 --- a/pkg/message/parser/trimmer_test.go +++ b/pkg/message/parser/trimmer_test.go @@ -26,7 +26,7 @@ import ( ) func TestEndOfMailTrimmer(t *testing.T) { - var tests = []struct { + tests := []struct { in string out string }{ diff --git a/pkg/message/section_test.go b/pkg/message/section_test.go index 3704032..6b6568e 100644 --- a/pkg/message/section_test.go +++ b/pkg/message/section_test.go @@ -341,7 +341,8 @@ var testPaths = []struct { path []int expectedSection, expectedBody string }{ - {[]int{}, + { + []int{}, sampleMail, `main summary @@ -434,7 +435,8 @@ Content-Type: text/html `, }, - {[]int{1}, + { + []int{1}, `Content-Type: text/plain 1. main message @@ -446,7 +448,8 @@ Content-Type: text/html `, }, - {[]int{3}, + { + []int{3}, `Subject: Inside mail 3 From: Mary Smith To: John Doe @@ -488,7 +491,8 @@ Content-Transfer-Encoding: base64 `, }, - {[]int{3, 1}, + { + []int{3, 1}, `Content-Type: text/plain 3.1 message text @@ -498,7 +502,8 @@ Content-Transfer-Encoding: base64 `, }, - {[]int{3, 2}, + { + []int{3, 2}, `Content-Type: application/octet-stream Content-Disposition: attachment; filename="msg_3_signature.sig" Content-Transfer-Encoding: base64 @@ -510,7 +515,8 @@ Content-Transfer-Encoding: base64 `, }, - {[]int{4, 2, 2, 1}, + { + []int{4, 2, 2, 1}, `Content-Type: text/plain 4.2.2.1 plain text @@ -520,7 +526,8 @@ Content-Transfer-Encoding: base64 `, }, - {[]int{4, 2, 2, 2}, + { + []int{4, 2, 2, 2}, `Content-Type: text/html

4.2.2.2 html text

diff --git a/pkg/mime/encoding_test.go b/pkg/mime/encoding_test.go index 676a98f..35c524b 100644 --- a/pkg/mime/encoding_test.go +++ b/pkg/mime/encoding_test.go @@ -126,21 +126,21 @@ func TestGetEncoding(t *testing.T) { // All MIME charsets with aliases can be found here: // https://www.iana.org/assignments/character-sets/character-sets.xhtml mimesets := map[string][]string{ - "utf-8": []string{ // MIB 16 + "utf-8": { // MIB 16 "utf8", "csutf8", "unicode-1-1-utf-8", "iso-utf-8", "utf8mb4", }, - "gbk": []string{ + "gbk": { "gb2312", // MIB 2025 //"euc-cn": []string{ "euccn", "ibm-euccn", }, //"utf7": []string{"utf-7", "unicode-1-1-utf-7"}, - "iso-8859-2": []string{ // MIB 5 + "iso-8859-2": { // MIB 5 "iso-ir-101", "iso_8859-2", "iso8859-2", @@ -150,27 +150,27 @@ func TestGetEncoding(t *testing.T) { "ibm852", //"FAILEDibm852", }, - "iso-8859-3": []string{ // MIB 6 + "iso-8859-3": { // MIB 6 "iso-ir-109", "iso_8859-3", "latin3", "l3", "csisolatin3", }, - "iso-8859-4": []string{ // MIB 7 + "iso-8859-4": { // MIB 7 "iso-ir-110", "iso_8859-4", "latin4", "l4", "csisolatin4", }, - "iso-8859-5": []string{ // MIB 8 + "iso-8859-5": { // MIB 8 "iso-ir-144", "iso_8859-5", "cyrillic", "csisolatincyrillic", }, - "iso-8859-6": []string{ // MIB 9 + "iso-8859-6": { // MIB 9 "iso-ir-127", "iso_8859-6", "ecma-114", @@ -182,16 +182,18 @@ func TestGetEncoding(t *testing.T) { "iso-8859-6-e", //"iso-8859-6i": []string{ // MIB 82 "csiso88596i", - "iso-8859-6-i"}, - "iso-8859-7": []string{ // MIB 10 + "iso-8859-6-i", + }, + "iso-8859-7": { // MIB 10 "iso-ir-126", "iso_8859-7", "elot_928", "ecma-118", "greek", "greek8", - "csisolatingreek"}, - "iso-8859-8": []string{ // MIB 11 + "csisolatingreek", + }, + "iso-8859-8": { // MIB 11 "iso-ir-138", "iso_8859-8", "hebrew", @@ -200,33 +202,36 @@ func TestGetEncoding(t *testing.T) { "csiso88598e", "iso-8859-8-e", }, - "iso-8859-8-i": []string{ // MIB 85 + "iso-8859-8-i": { // MIB 85 "logical", "csiso88598i", "iso-8859-8-i", // Hebrew, the "i" means right-to-left, probably unnecessary with ISO cleaning above. }, - "iso-8859-10": []string{ // MIB 13 + "iso-8859-10": { // MIB 13 "iso-ir-157", "l6", "iso_8859-10:1992", "csisolatin6", - "latin6"}, - "iso-8859-13": []string{ // MIB 109 + "latin6", + }, + "iso-8859-13": { // MIB 109 "csiso885913"}, - "iso-8859-14": []string{ // MIB 110 + "iso-8859-14": { // MIB 110 "iso-ir-199", "iso_8859-14:1998", "iso_8859-14", "latin8", "iso-celtic", "l8", - "csiso885914"}, - "iso-8859-15": []string{ // MIB 111 + "csiso885914", + }, + "iso-8859-15": { // MIB 111 "iso_8859-15", "latin-9", "csiso885915", - "ISO8859-15"}, - "iso-8859-16": []string{ // MIB 112 + "ISO8859-15", + }, + "iso-8859-16": { // MIB 112 "iso-ir-226", "iso_8859-16:2001", "iso_8859-16", @@ -234,21 +239,21 @@ func TestGetEncoding(t *testing.T) { "l10", "csiso885916", }, - "windows-874": []string{ // MIB 2109 + "windows-874": { // MIB 2109 "cswindows874", "cp874", "iso-8859-11", "tis-620", }, - "windows-1250": []string{ // MIB 2250 + "windows-1250": { // MIB 2250 "cswindows1250", "cp1250", }, - "windows-1251": []string{ // MIB 2251 + "windows-1251": { // MIB 2251 "cswindows1251", "cp1251", }, - "windows-1252": []string{ // MIB 2252 + "windows-1252": { // MIB 2252 "cswindows1252", "cp1252", "3dwindows-1252", @@ -278,20 +283,20 @@ func TestGetEncoding(t *testing.T) { "iso-ir-6", "we8iso8859p1", }, - "windows-1253": []string{"cswindows1253", "cp1253"}, // MIB 2253 - "windows-1254": []string{"cswindows1254", "cp1254"}, // MIB 2254 - "windows-1255": []string{"cSwindows1255", "cp1255"}, // MIB 2255 - "windows-1256": []string{"cswIndows1256", "cp1256"}, // MIB 2256 - "windows-1257": []string{"cswinDows1257", "cp1257"}, // MIB 2257 - "windows-1258": []string{"cswindoWs1258", "cp1258"}, // MIB 2257 - "koi8-r": []string{"cskoi8r", "koi8r"}, // MIB 2084 - "koi8-u": []string{"cskoi8u", "koi8u"}, // MIB 2088 - "macintosh": []string{"mac", "macroman", "csmacintosh"}, // MIB 2027 - "big5": []string{ + "windows-1253": {"cswindows1253", "cp1253"}, // MIB 2253 + "windows-1254": {"cswindows1254", "cp1254"}, // MIB 2254 + "windows-1255": {"cSwindows1255", "cp1255"}, // MIB 2255 + "windows-1256": {"cswIndows1256", "cp1256"}, // MIB 2256 + "windows-1257": {"cswinDows1257", "cp1257"}, // MIB 2257 + "windows-1258": {"cswindoWs1258", "cp1258"}, // MIB 2257 + "koi8-r": {"cskoi8r", "koi8r"}, // MIB 2084 + "koi8-u": {"cskoi8u", "koi8u"}, // MIB 2088 + "macintosh": {"mac", "macroman", "csmacintosh"}, // MIB 2027 + "big5": { "zht16mswin950", // cp950 "cp950", }, - "euc-kr": []string{ + "euc-kr": { "euckr", // MIB 38 "ibm-euckr", //"uhc": []string{ // Korea @@ -299,11 +304,11 @@ func TestGetEncoding(t *testing.T) { "ksc5601", "cp949", }, - "euc-jp": []string{ + "euc-jp": { "eucjp", "ibm-eucjp", }, - "shift_jis": []string{ + "shift_jis": { "CP932", "MS932", "Windows-932", @@ -312,7 +317,7 @@ func TestGetEncoding(t *testing.T) { "IBM-943", "CP943", }, - "iso-2022-jp": []string{ // MIB 39 + "iso-2022-jp": { // MIB 39 "iso2022jp", "csiso2022jp", }, @@ -424,14 +429,14 @@ func TestEncodeReader(t *testing.T) { // run tests for _, val := range testData { - //fmt.Println("Testing ", val) + // fmt.Println("Testing ", val) expected := []byte(val.message) decoded, err := DecodeCharset(val.original, "text/plain; charset="+val.charset) if len(expected) == 0 { if err == nil { t.Error("Expected err but have ", err) } else { - //fmt.Println("Expected err: ", err) + // fmt.Println("Expected err: ", err) continue } } else { diff --git a/pkg/pmapi/config_qa.go b/pkg/pmapi/config_qa.go index e92b9da..2f00f6f 100644 --- a/pkg/pmapi/config_qa.go +++ b/pkg/pmapi/config_qa.go @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License // along with Proton Mail Bridge. If not, see . +//go:build build_qa // +build build_qa package pmapi diff --git a/pkg/pmapi/manager_auth.go b/pkg/pmapi/manager_auth.go index 2daad62..77abef5 100644 --- a/pkg/pmapi/manager_auth.go +++ b/pkg/pmapi/manager_auth.go @@ -105,7 +105,7 @@ func (m *manager) authRefresh(ctx context.Context, uid, ref string) (*AuthRefres m.refreshingAuth.Lock() defer m.refreshingAuth.Unlock() - var req = authRefreshReq{ + req := authRefreshReq{ UID: uid, RefreshToken: ref, ResponseType: "token", diff --git a/pkg/pmapi/manager_ping.go b/pkg/pmapi/manager_ping.go index 0d013dc..0835eec 100644 --- a/pkg/pmapi/manager_ping.go +++ b/pkg/pmapi/manager_ping.go @@ -24,10 +24,8 @@ import ( "github.com/sirupsen/logrus" ) -var ( - // retryConnectionSleeps defines a smooth cool down in seconds. - retryConnectionSleeps = []int{2, 5, 10, 30, 60} //nolint:gochecknoglobals -) +// retryConnectionSleeps defines a smooth cool down in seconds. +var retryConnectionSleeps = []int{2, 5, 10, 30, 60} //nolint:gochecknoglobals func (m *manager) pingUntilSuccess() { if m.isPingOngoing() { diff --git a/pkg/pmapi/messages_test.go b/pkg/pmapi/messages_test.go index 9847ad8..eed778c 100644 --- a/pkg/pmapi/messages_test.go +++ b/pkg/pmapi/messages_test.go @@ -27,8 +27,10 @@ import ( "github.com/stretchr/testify/require" ) -const testMessageCleartext = `
jeej saas

Sent from ProtonMail, encrypted email based in Switzerland.

` -const testMessageCleartextLegacy = `
flkasjfkjasdklfjasd
fasd
jfasjdfjasd
fj
asdfj
sadjf
sadjf
asjdf
jasd
fj
asdjf
asdjfsad
fasdlkfjasdjfkljsadfljsdfjsdljflkdsjfkljsdlkfjsdlk
jasfd
jsd
jf
sdjfjsdf

djfskjsladf
asd
fja
sdjfajsf
jas
fas
fj
afj
ajf
af
asdfasdfasd
Sent from ProtonMail, encrypted email based in Switzerland.
dshfljsadfasdf
as
df
asd
fasd
f
asd
fasdflasdklfjsadlkjf
asd
fasdlkfjasdlkfjklasdjflkasjdflaslkfasdfjlasjflkasflksdjflkjasdf
asdflkasdjflajsfljaslkflasf
asdfkas
dfjas
djf
asjf
asj
faj
f
afj
sdjaf
jas
sdfj
ajf
aj
ajsdafafdaaf
a
f
lasl;ga
sags
ad
gags
g
ga
a
gg
a
ag
ag
agga.g.ga,ag.ag./ga

dsga
sg

gasga\g\g\g\g\g\n\y\t\r\\r\r\\n\n\n\


sd
asdf
asdf
dsa
fasd
f
` +const ( + testMessageCleartext = `
jeej saas

Sent from ProtonMail, encrypted email based in Switzerland.

` + testMessageCleartextLegacy = `
flkasjfkjasdklfjasd
fasd
jfasjdfjasd
fj
asdfj
sadjf
sadjf
asjdf
jasd
fj
asdjf
asdjfsad
fasdlkfjasdjfkljsadfljsdfjsdljflkdsjfkljsdlkfjsdlk
jasfd
jsd
jf
sdjfjsdf

djfskjsladf
asd
fja
sdjfajsf
jas
fas
fj
afj
ajf
af
asdfasdfasd
Sent from ProtonMail, encrypted email based in Switzerland.
dshfljsadfasdf
as
df
asd
fasd
f
asd
fasdflasdklfjsadlkjf
asd
fasdlkfjasdlkfjklasdjflkasjdflaslkfasdfjlasjflkasflksdjflkjasdf
asdflkasdjflajsfljaslkflasf
asdfkas
dfjas
djf
asjf
asj
faj
f
afj
sdjaf
jas
sdfj
ajf
aj
ajsdafafdaaf
a
f
lasl;ga
sags
ad
gags
g
ga
a
gg
a
ag
ag
agga.g.ga,ag.ag./ga

dsga
sg

gasga\g\g\g\g\g\n\y\t\r\\r\r\\n\n\n\


sd
asdf
asdf
dsa
fasd
f
` +) const testMessageEncrypted = `-----BEGIN PGP MESSAGE----- Version: OpenPGP.js v1.2.0 diff --git a/pkg/pmapi/pmapi_test.go b/pkg/pmapi/pmapi_test.go index b75306b..9da3366 100644 --- a/pkg/pmapi/pmapi_test.go +++ b/pkg/pmapi/pmapi_test.go @@ -24,8 +24,10 @@ import ( "github.com/ProtonMail/gopenpgp/v2/crypto" ) -const testMailboxPassword = "apple" -const testMailboxPasswordLegacy = "123" +const ( + testMailboxPassword = "apple" + testMailboxPasswordLegacy = "123" +) var ( testPrivateKeyRing *crypto.KeyRing diff --git a/pkg/smtp/dump_qa.go b/pkg/smtp/dump_qa.go index edf3360..27f3a67 100644 --- a/pkg/smtp/dump_qa.go +++ b/pkg/smtp/dump_qa.go @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License // along with Proton Mail Bridge. If not, see . +//go:build build_qa // +build build_qa package smtp @@ -38,7 +39,7 @@ func dumpMessageData(b []byte, subject string) { path := filepath.Join(home, "bridge-qa") - if err := os.MkdirAll(path, 0700); err != nil { + if err := os.MkdirAll(path, 0o700); err != nil { logrus.WithError(err).Error("Failed to dump raw message data") return } @@ -50,7 +51,7 @@ func dumpMessageData(b []byte, subject string) { if err := ioutil.WriteFile( filepath.Join(path, fmt.Sprintf("%v-%v.eml", subject, time.Now().Unix())), b, - 0600, + 0o600, ); err != nil { logrus.WithError(err).Error("Failed to dump raw message data") return diff --git a/pkg/smtp/smtp.go b/pkg/smtp/smtp.go index 443ef34..5df423c 100644 --- a/pkg/smtp/smtp.go +++ b/pkg/smtp/smtp.go @@ -20,6 +20,4 @@ package smtp import "github.com/sirupsen/logrus" -var ( - log = logrus.WithField("pkg", "smtp") //nolint:gochecknoglobals -) +var log = logrus.WithField("pkg", "smtp") //nolint:gochecknoglobals diff --git a/pkg/store/sync_test.go b/pkg/store/sync_test.go index ef2546d..23e9a71 100644 --- a/pkg/store/sync_test.go +++ b/pkg/store/sync_test.go @@ -155,9 +155,6 @@ func generateIDsR(start, stop int) []string { // Tests func TestSyncAllMail(t *testing.T) { //nolint:funlen - m, clear := initMocks(t) - defer clear() - numberOfMessages := 10000 api := &mockLister{ diff --git a/pkg/users/cache.go b/pkg/users/cache.go index 2d9e56f..780a4af 100644 --- a/pkg/users/cache.go +++ b/pkg/users/cache.go @@ -41,7 +41,7 @@ func isFolderEmpty(path string) (bool, error) { // if it is suitable (non existing, or empty and deletable) the folder is deleted. func checkFolderIsSuitableDestinationForCache(path string) error { // Ensure the parent directory exists. - if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil { + if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil { return err } @@ -87,7 +87,7 @@ func copyFolder(srcPath, dstPath string) error { return errors.New("source is not an existing folder") } - if err = os.MkdirAll(dstPath, 0700); err != nil { + if err = os.MkdirAll(dstPath, 0o700); err != nil { return err } files, err := ioutil.ReadDir(srcPath) @@ -170,7 +170,7 @@ func copyFile(srcPath, dstPath string) error { err = src.Close() }() - dst, err := os.OpenFile(filepath.Clean(dstPath), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) + dst, err := os.OpenFile(filepath.Clean(dstPath), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600) if err != nil { return err } diff --git a/pkg/users/credentials/pass_imaptest.go b/pkg/users/credentials/pass_imaptest.go index 1a09531..4cf5eea 100644 --- a/pkg/users/credentials/pass_imaptest.go +++ b/pkg/users/credentials/pass_imaptest.go @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License // along with Proton Mail Bridge. If not, see . +//go:build imaptest // +build imaptest package credentials diff --git a/pkg/users/users_test.go b/pkg/users/users_test.go index d6c5a6f..fde44d0 100644 --- a/pkg/users/users_test.go +++ b/pkg/users/users_test.go @@ -222,6 +222,7 @@ func (fr *fullStackReporter) Errorf(format string, args ...interface{}) { fmt.Printf("err: "+format+"\n", args...) fr.T.Fail() } + func (fr *fullStackReporter) Fatalf(format string, args ...interface{}) { debug.PrintStack() fmt.Printf("fail: "+format+"\n", args...)