forked from Silverfish/proton-bridge
Other: Update golangci-lint to v1.50.0
This commit is contained in:
@ -13,6 +13,8 @@ issues:
|
||||
- should have comment (\([^)]+\) )?or be unexported
|
||||
# For now we are missing a lot of comments.
|
||||
- at least one file in a package should have a package comment
|
||||
# Package comments.
|
||||
- "package-comments: should have a package comment"
|
||||
|
||||
exclude-rules:
|
||||
- path: _test\.go
|
||||
@ -106,4 +108,3 @@ linters:
|
||||
# - testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false]
|
||||
# - thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
|
||||
# - wrapcheck # Checks that errors returned from external packages are wrapped [fast: false, auto-fix: false]
|
||||
|
||||
|
||||
2
Makefile
2
Makefile
@ -169,7 +169,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.47.2"
|
||||
LINTVER:="v1.50.0"
|
||||
LINTSRC:="https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh"
|
||||
|
||||
install-dev-dependencies: install-devel-tools install-linter install-go-mod-outdated
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
// Package api provides HTTP API of the Bridge.
|
||||
//
|
||||
// API endpoints:
|
||||
// * /focus, see focusHandler
|
||||
// - /focus, see focusHandler
|
||||
package api
|
||||
|
||||
import (
|
||||
|
||||
@ -23,7 +23,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -33,7 +32,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MaxAttachmentSize = 7 * 1024 * 1024 // 7 MB total limit
|
||||
MaxAttachmentSize = 7 * 1024 * 1024 // MaxAttachmentSize 7 MB total limit
|
||||
MaxCompressedFilesCount = 6
|
||||
)
|
||||
|
||||
@ -106,7 +105,7 @@ func (b *Bridge) getMatchingLogs(filenameMatchFunc func(string) bool) (filenames
|
||||
return nil, err
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(logsPath)
|
||||
files, err := os.ReadDir(logsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package clientconfig
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@ -89,7 +88,7 @@ func prepareMobileConfig(
|
||||
}
|
||||
|
||||
func saveConfigTemporarily(mc *mobileconfig.Config) (fname string, err error) {
|
||||
dir, err := ioutil.TempDir("", "protonmail-autoconfig")
|
||||
dir, err := os.MkdirTemp("", "protonmail-autoconfig")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
3
internal/config/cache/cache_test.go
vendored
3
internal/config/cache/cache_test.go
vendored
@ -18,7 +18,6 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -28,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
func TestRemoveOldVersions(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "test-cache")
|
||||
dir, err := os.MkdirTemp("", "test-cache")
|
||||
require.NoError(t, err)
|
||||
|
||||
cache, err := New(dir, "c4")
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
@ -79,7 +78,7 @@ func (p *keyValueStore) save() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(p.path, b, 0o600)
|
||||
return os.WriteFile(p.path, b, 0o600)
|
||||
}
|
||||
|
||||
func (p *keyValueStore) setDefault(key Key, value string) {
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@ -38,7 +37,7 @@ func TestLoadBadKeyValueStore(t *testing.T) {
|
||||
path, clean := newTmpFile(r)
|
||||
defer clean()
|
||||
|
||||
r.NoError(ioutil.WriteFile(path, []byte("{\"key\":\"MISSING_QUOTES"), 0o700))
|
||||
r.NoError(os.WriteFile(path, []byte("{\"key\":\"MISSING_QUOTES"), 0o700))
|
||||
pref := newKeyValueStore(path)
|
||||
r.Equal("", pref.Get("key"))
|
||||
}
|
||||
@ -115,7 +114,7 @@ func TestKeyValueStoreSetBool(t *testing.T) {
|
||||
}
|
||||
|
||||
func newTmpFile(r *require.Assertions) (path string, clean func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "pref.*.json")
|
||||
tmpfile, err := os.CreateTemp("", "pref.*.json")
|
||||
r.NoError(err)
|
||||
defer r.NoError(tmpfile.Close())
|
||||
|
||||
@ -131,12 +130,12 @@ 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\"}"), 0o700))
|
||||
r.NoError(os.WriteFile(path, []byte("{\"str\":\"value\",\"int\":\"42\",\"bool\":\"true\",\"falseBool\":\"t\"}"), 0o700))
|
||||
return newKeyValueStore(path), clean
|
||||
}
|
||||
|
||||
func checkSavedKeyValueStore(r *require.Assertions, path, expected string) {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
r.NoError(err)
|
||||
r.Equal(expected, string(data))
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
package tls
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetOldConfig(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "test-tls")
|
||||
dir, err := os.MkdirTemp("", "test-tls")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create new tls object.
|
||||
@ -49,7 +49,7 @@ func TestGetOldConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetValidConfig(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "test-tls")
|
||||
dir, err := os.MkdirTemp("", "test-tls")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create new tls object.
|
||||
|
||||
@ -18,9 +18,9 @@
|
||||
package cookies
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -170,7 +170,7 @@ func getTestServer(t *testing.T, wantCookies []testCookie) *httptest.Server {
|
||||
|
||||
// newFakeSettings creates a temporary folder for files.
|
||||
func newFakeSettings() *settings.Settings {
|
||||
dir, err := ioutil.TempDir("", "test-settings")
|
||||
dir, err := os.MkdirTemp("", "test-settings")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -24,10 +24,11 @@
|
||||
// When IMAP clients request message literals (or parts thereof), we sometimes need to build RFC822 message literals.
|
||||
// To do this, we pass build jobs to the message builder, which internally manages its own parallelism.
|
||||
// Summary:
|
||||
// - each IMAP fetch request is handled in parallel,
|
||||
// - within each IMAP fetch request, individual items are handled by a pool of `fetchWorkers` workers,
|
||||
// - within each worker, build jobs are posted to the message builder,
|
||||
// - the message builder handles build jobs using its own, independent worker pool,
|
||||
// - each IMAP fetch request is handled in parallel,
|
||||
// - within each IMAP fetch request, individual items are handled by a pool of `fetchWorkers` workers,
|
||||
// - within each worker, build jobs are posted to the message builder,
|
||||
// - the message builder handles build jobs using its own, independent worker pool,
|
||||
//
|
||||
// The builder will handle jobs in parallel up to its own internal limit. This prevents it from overwhelming API.
|
||||
package imap
|
||||
|
||||
|
||||
@ -31,15 +31,16 @@ const (
|
||||
|
||||
// addToCache adds item to existing item list.
|
||||
// Starting from following structure:
|
||||
// {
|
||||
// "username": {"label": "item1;item2"}
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// "username": {"label": "item1;item2"}
|
||||
// }
|
||||
//
|
||||
// After calling addToCache("username", "label", "newItem") we get:
|
||||
// {
|
||||
// "username": {"label": "item1;item2;newItem"}
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// "username": {"label": "item1;item2;newItem"}
|
||||
// }
|
||||
func (ib *imapBackend) addToCache(userID, label, toAdd string) {
|
||||
list := ib.getCacheList(userID, label)
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/mail"
|
||||
"strings"
|
||||
"time"
|
||||
@ -55,7 +55,7 @@ func (im *imapMailbox) createMessage(imapFlags []string, date time.Time, r imap.
|
||||
im.user.appendExpungeLock.Lock()
|
||||
defer im.user.appendExpungeLock.Unlock()
|
||||
|
||||
body, err := ioutil.ReadAll(r)
|
||||
body, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -30,11 +30,11 @@ import (
|
||||
// The purpose of this mailbox is to see "Folders" and "Labels"
|
||||
// at the root of the mailbox tree, e.g.:
|
||||
//
|
||||
// Folders << this
|
||||
// Folders/Family
|
||||
// Folders << this
|
||||
// Folders/Family
|
||||
//
|
||||
// Labels << this
|
||||
// Labels/Security
|
||||
// Labels << this
|
||||
// Labels/Security
|
||||
//
|
||||
// This mailbox cannot be modified or read in any way.
|
||||
type imapRootMailbox struct {
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
// Package uidplus DOES NOT implement full RFC4315!
|
||||
//
|
||||
// Excluded parts are:
|
||||
// * Response `UIDNOTSTICKY`: All mailboxes of Bridge support stable
|
||||
// UIDVALIDITY so it would never return this response
|
||||
// - Response `UIDNOTSTICKY`: All mailboxes of Bridge support stable
|
||||
// UIDVALIDITY so it would never return this response
|
||||
//
|
||||
// Otherwise the standard RFC4315 is followed.
|
||||
package uidplus
|
||||
@ -48,9 +48,10 @@ const (
|
||||
// ranges or out of the bound ranges are possible.
|
||||
//
|
||||
// NOTE: potential issue with response length
|
||||
// * the user selects large number of messages to be copied and the
|
||||
// response line will be long,
|
||||
// * list of UIDs which high values
|
||||
// - the user selects large number of messages to be copied and the
|
||||
// response line will be long,
|
||||
// - list of UIDs which high values
|
||||
//
|
||||
// which can create long response line. We didn't find a maximum length of one
|
||||
// IMAP response line or maximum length of IMAP "response code" with parameters.
|
||||
type OrderedSeq []uint32
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package locations
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -118,10 +117,10 @@ func TestCleanRemovesUnexpectedFilesAndFolders(t *testing.T) {
|
||||
}
|
||||
|
||||
func newFakeAppDirs(t *testing.T) *fakeAppDirs {
|
||||
configDir, err := ioutil.TempDir("", "test-locations-config")
|
||||
configDir, err := os.MkdirTemp("", "test-locations-config")
|
||||
require.NoError(t, err)
|
||||
|
||||
cacheDir, err := ioutil.TempDir("", "test-locations-cache")
|
||||
cacheDir, err := os.MkdirTemp("", "test-locations-cache")
|
||||
require.NoError(t, err)
|
||||
|
||||
return &fakeAppDirs{
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -27,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
func clearLogs(logDir string, maxLogs int, maxCrashes int) error {
|
||||
files, err := ioutil.ReadDir(logDir)
|
||||
files, err := os.ReadDir(logDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@ -27,14 +27,14 @@ import (
|
||||
|
||||
// TestClearLogs tests that cearLogs removes only bridge old log files keeping last three of them.
|
||||
func TestClearLogs(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "clear-logs-test")
|
||||
dir, err := os.MkdirTemp("", "clear-logs-test")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "other.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "v1_10.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "v1_11.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "v2_12.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "v2_13.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "other.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "v1_10.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "v1_11.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "v2_12.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "v2_13.log"), []byte("Hello"), 0o755))
|
||||
|
||||
require.NoError(t, clearLogs(dir, 3, 0))
|
||||
checkFileNames(t, dir, []string{
|
||||
@ -51,7 +51,7 @@ func checkFileNames(t *testing.T, dir string, expectedFileNames []string) {
|
||||
}
|
||||
|
||||
func getFileNames(t *testing.T, dir string) []string {
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
files, err := os.ReadDir(dir)
|
||||
require.NoError(t, err)
|
||||
|
||||
fileNames := []string{}
|
||||
|
||||
@ -20,7 +20,6 @@ package logging
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@ -77,7 +76,7 @@ func TestRotator(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkRotateRAMFile(b *testing.B) {
|
||||
dir, err := ioutil.TempDir("", "rotate-benchmark")
|
||||
dir, err := os.MkdirTemp("", "rotate-benchmark")
|
||||
require.NoError(b, err)
|
||||
defer os.RemoveAll(dir) //nolint:errcheck
|
||||
|
||||
@ -88,7 +87,7 @@ func BenchmarkRotateDiskFile(b *testing.B) {
|
||||
cache, err := os.UserCacheDir()
|
||||
require.NoError(b, err)
|
||||
|
||||
dir, err := ioutil.TempDir(cache, "rotate-benchmark")
|
||||
dir, err := os.MkdirTemp(cache, "rotate-benchmark")
|
||||
require.NoError(b, err)
|
||||
defer os.RemoveAll(dir) //nolint:errcheck
|
||||
|
||||
@ -113,7 +112,7 @@ func getTestFile(b *testing.B, dir string, length int) func() (io.WriteCloser, e
|
||||
b.StopTimer()
|
||||
defer b.StartTimer()
|
||||
|
||||
f, err := ioutil.TempFile(dir, "log")
|
||||
f, err := os.CreateTemp(dir, "log")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -22,7 +22,6 @@ package smtp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@ -48,7 +47,7 @@ func dumpMessageData(b []byte, subject string) {
|
||||
subject = subject[:16]
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(
|
||||
if err := os.WriteFile(
|
||||
filepath.Join(path, fmt.Sprintf("%v-%v.eml", subject, time.Now().Unix())),
|
||||
b,
|
||||
0o600,
|
||||
|
||||
@ -163,17 +163,18 @@ func (b *sendPreferencesBuilder) withPublicKey(v *crypto.KeyRing) {
|
||||
// preferences. Notice that the composer allows to select a sign preference,
|
||||
// an email format preference and an encrypt-to-outside preference. The
|
||||
// object we extract has the following possible value types:
|
||||
// {
|
||||
// encrypt: true | false,
|
||||
// sign: true | false,
|
||||
// pgpScheme: 1 (protonmail custom scheme)
|
||||
// | 2 (Protonmail scheme for encrypted-to-outside email)
|
||||
// | 4 (no cryptographic scheme)
|
||||
// | 8 (PGP/INLINE)
|
||||
// | 16 (PGP/MIME),
|
||||
// mimeType: 'text/html' | 'text/plain' | 'multipart/mixed',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }.
|
||||
//
|
||||
// {
|
||||
// encrypt: true | false,
|
||||
// sign: true | false,
|
||||
// pgpScheme: 1 (protonmail custom scheme)
|
||||
// | 2 (Protonmail scheme for encrypted-to-outside email)
|
||||
// | 4 (no cryptographic scheme)
|
||||
// | 8 (PGP/INLINE)
|
||||
// | 16 (PGP/MIME),
|
||||
// mimeType: 'text/html' | 'text/plain' | 'multipart/mixed',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }.
|
||||
func (b *sendPreferencesBuilder) build() (p SendPreferences) {
|
||||
p.Encrypt = b.shouldEncrypt()
|
||||
p.Sign = b.shouldSign()
|
||||
@ -207,13 +208,13 @@ func (b *sendPreferencesBuilder) build() (p SendPreferences) {
|
||||
|
||||
// setPGPSettings returns a SendPreferences with the following possible values:
|
||||
//
|
||||
// {
|
||||
// encrypt: true | false | undefined/null/'',
|
||||
// sign: true | false | undefined/null/'',
|
||||
// pgpScheme: 'pgp-mime' | 'pgp-inline' | undefined/null/'',
|
||||
// mimeType: 'text/html' | 'text/plain' | undefined/null/'',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }
|
||||
// {
|
||||
// encrypt: true | false | undefined/null/'',
|
||||
// sign: true | false | undefined/null/'',
|
||||
// pgpScheme: 'pgp-mime' | 'pgp-inline' | undefined/null/'',
|
||||
// mimeType: 'text/html' | 'text/plain' | undefined/null/'',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }
|
||||
//
|
||||
// These settings are simply a reflection of the vCard content plus the public
|
||||
// key info retrieved from the API via the GET KEYS route.
|
||||
@ -285,17 +286,17 @@ func (b *sendPreferencesBuilder) setInternalPGPSettings(
|
||||
// pickSendingKey tries to determine which key to use to encrypt outgoing mail.
|
||||
// It returns a keyring containing the chosen key or an error.
|
||||
//
|
||||
// 1. If there are pinned keys in the vCard, those should be given preference
|
||||
// (assuming the fingerprint matches one of the keys served by the API).
|
||||
// 2. If there are pinned keys in the vCard but no matching keys were served
|
||||
// by the API, we use one of the API keys but first show a modal to the
|
||||
// user to ask them to confirm that they trust the API key.
|
||||
// (Use case: user doesn't trust server, pins the only keys they trust to
|
||||
// the contact, rogue server sends unknown keys, user should have option
|
||||
// to say they don't recognise these keys and abort the mail send.)
|
||||
// 3. If there are no pinned keys, then the client should encrypt with the
|
||||
// first valid key served by the API (in principle the server already
|
||||
// validates the keys and the first one provided should be valid).
|
||||
// 1. If there are pinned keys in the vCard, those should be given preference
|
||||
// (assuming the fingerprint matches one of the keys served by the API).
|
||||
// 2. If there are pinned keys in the vCard but no matching keys were served
|
||||
// by the API, we use one of the API keys but first show a modal to the
|
||||
// user to ask them to confirm that they trust the API key.
|
||||
// (Use case: user doesn't trust server, pins the only keys they trust to
|
||||
// the contact, rogue server sends unknown keys, user should have option
|
||||
// to say they don't recognise these keys and abort the mail send.)
|
||||
// 3. If there are no pinned keys, then the client should encrypt with the
|
||||
// first valid key served by the API (in principle the server already
|
||||
// validates the keys and the first one provided should be valid).
|
||||
func pickSendingKey(vCardData *ContactMetadata, rawAPIKeys []pmapi.PublicKey) (kr *crypto.KeyRing, err error) {
|
||||
contactKeys := make([]*crypto.Key, len(vCardData.Keys))
|
||||
apiKeys := make([]*crypto.Key, len(rawAPIKeys))
|
||||
@ -457,13 +458,13 @@ func (b *sendPreferencesBuilder) setExternalPGPSettingsWithoutWKDKeys(
|
||||
// determined thus far using using the (global) user mail settings.
|
||||
// The object we extract has the following possible value types:
|
||||
//
|
||||
// {
|
||||
// encrypt: true | false,
|
||||
// sign: true | false,
|
||||
// pgpScheme: 'pgp-mime' | 'pgp-inline',
|
||||
// mimeType: 'text/html' | 'text/plain',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }
|
||||
// {
|
||||
// encrypt: true | false,
|
||||
// sign: true | false,
|
||||
// pgpScheme: 'pgp-mime' | 'pgp-inline',
|
||||
// mimeType: 'text/html' | 'text/plain',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }
|
||||
//
|
||||
// The public key can still be undefined as we do not need it if the outgoing
|
||||
// email is not encrypted.
|
||||
|
||||
7
internal/store/cache/disk.go
vendored
7
internal/store/cache/disk.go
vendored
@ -23,7 +23,6 @@ import (
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
@ -64,7 +63,7 @@ func NewOnDiskCache(path string, cmp Compressor, opts Options) (Cache, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file, err := ioutil.TempFile(path, "tmp")
|
||||
file, err := os.CreateTemp(path, "tmp")
|
||||
defer func() {
|
||||
file.Close() //nolint:errcheck,gosec
|
||||
os.Remove(file.Name()) //nolint:errcheck,gosec
|
||||
@ -210,7 +209,7 @@ func (c *onDiskCache) readFile(path string) ([]byte, error) {
|
||||
// Wait before reading in case the file is currently being written.
|
||||
c.pending.wait(path)
|
||||
|
||||
return ioutil.ReadFile(filepath.Clean(path))
|
||||
return os.ReadFile(filepath.Clean(path))
|
||||
}
|
||||
|
||||
func (c *onDiskCache) writeFile(path string, b []byte) error {
|
||||
@ -235,7 +234,7 @@ func (c *onDiskCache) writeFile(path string, b []byte) error {
|
||||
defer c.update()
|
||||
|
||||
// NOTE(GODT-1158): What happens when this fails? Should be fixed eventually.
|
||||
return ioutil.WriteFile(filepath.Clean(path), b, 0o600)
|
||||
return os.WriteFile(filepath.Clean(path), b, 0o600)
|
||||
}
|
||||
|
||||
func (c *onDiskCache) hasSpace(size int) bool {
|
||||
|
||||
@ -20,7 +20,6 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@ -162,7 +161,7 @@ func initMocks(tb testing.TB) (*mocksForStore, func()) {
|
||||
mocks.panicHandler.EXPECT().HandlePanic().AnyTimes()
|
||||
|
||||
var err error
|
||||
mocks.tmpDir, err = ioutil.TempDir("", "store-test")
|
||||
mocks.tmpDir, err = os.MkdirTemp("", "store-test")
|
||||
require.NoError(tb, err)
|
||||
|
||||
cacheFile := filepath.Join(mocks.tmpDir, "cache.json")
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/mail"
|
||||
"net/textproto"
|
||||
"strings"
|
||||
@ -126,7 +125,7 @@ func encryptDraft(kr *crypto.KeyRing, message *pmapi.Message, attachments []*dra
|
||||
|
||||
for _, att := range attachments {
|
||||
attachment := att.attachment
|
||||
attachmentBody, err := ioutil.ReadAll(att.reader)
|
||||
attachmentBody, err := io.ReadAll(att.reader)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read attachment")
|
||||
}
|
||||
@ -158,7 +157,7 @@ func (store *Store) checkDraftTotalSize(message *pmapi.Message, attachments []*d
|
||||
|
||||
var attSize int64
|
||||
for _, att := range attachments {
|
||||
b, err := ioutil.ReadAll(att.encReader)
|
||||
b, err := io.ReadAll(att.encReader)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@ -111,13 +111,13 @@ func (store *Store) isSynced(countsOnAPI []*pmapi.MessagesCount) (bool, error) {
|
||||
// All Mail mailbox contains all messages, so we download all meta data needed
|
||||
// to generate any address/mailbox IMAP UIDs.
|
||||
// Sync state can be in three states:
|
||||
// * Nothing in database. For example when user logs in for the first time.
|
||||
// `triggerSync` will start full sync.
|
||||
// * Database has syncIDRangesKey and syncIDsToBeDeletedKey keys with data.
|
||||
// Sync is in progress or was interrupted. In later case when, `triggerSync`
|
||||
// will continue where it left off.
|
||||
// * Database has only syncStateKey with time when database was last synced.
|
||||
// `triggerSync` will reset it and start full sync again.
|
||||
// - Nothing in database. For example when user logs in for the first time.
|
||||
// `triggerSync` will start full sync.
|
||||
// - Database has syncIDRangesKey and syncIDsToBeDeletedKey keys with data.
|
||||
// Sync is in progress or was interrupted. In later case when, `triggerSync`
|
||||
// will continue where it left off.
|
||||
// - Database has only syncStateKey with time when database was last synced.
|
||||
// `triggerSync` will reset it and start full sync again.
|
||||
func (store *Store) triggerSync() {
|
||||
syncState := store.loadSyncState()
|
||||
|
||||
|
||||
@ -20,7 +20,6 @@ package updater
|
||||
import (
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -43,7 +42,7 @@ func (i *InstallerDarwin) InstallUpdate(_ *semver.Version, r io.Reader) error {
|
||||
}
|
||||
defer func() { _ = gr.Close() }()
|
||||
|
||||
tempDir, err := ioutil.TempDir("", "proton-update-source")
|
||||
tempDir, err := os.MkdirTemp("", "proton-update-source")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get temporary update directory")
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package updater
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -104,10 +103,10 @@ func checkThatFilesAreSame(r *require.Assertions, src, dst string) {
|
||||
|
||||
r.Equal(srcLnk, dstLnk)
|
||||
} else {
|
||||
srcContent, err := ioutil.ReadFile(srcPath)
|
||||
srcContent, err := os.ReadFile(srcPath)
|
||||
r.NoError(err)
|
||||
|
||||
dstContent, err := ioutil.ReadFile(dstPath)
|
||||
dstContent, err := os.ReadFile(dstPath)
|
||||
r.NoError(err)
|
||||
|
||||
r.Equal(srcContent, dstContent)
|
||||
@ -155,7 +154,7 @@ func createTestFolder(dirPath, dirType string) error {
|
||||
path := filepath.Join(dirPath, "testpath")
|
||||
switch dirType {
|
||||
case FileType:
|
||||
err = ioutil.WriteFile(path, []byte("This is a test"), 0o640)
|
||||
err = os.WriteFile(path, []byte("This is a test"), 0o640)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -172,7 +171,7 @@ func createTestFolder(dirPath, dirType string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(path, "another_file"), []byte("This is a test"), 0o640)
|
||||
err = os.WriteFile(filepath.Join(path, "another_file"), []byte("This is a test"), 0o640)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@ -314,7 +314,7 @@ type fakeSettings struct {
|
||||
|
||||
// newFakeSettings creates a temporary folder for files.
|
||||
func newFakeSettings(rollout float64, earlyAccess bool) *fakeSettings {
|
||||
dir, err := ioutil.TempDir("", "test-settings")
|
||||
dir, err := os.MkdirTemp("", "test-settings")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -50,41 +50,42 @@ type VersionInfo struct {
|
||||
|
||||
// VersionMap represents the structure of the version.json file.
|
||||
// It looks like this:
|
||||
// {
|
||||
// "stable": {
|
||||
// "Version": "2.3.4",
|
||||
// "Package": "https://protonmail.com/.../bridge_2.3.4_linux.tgz",
|
||||
// "Installers": [
|
||||
// "https://protonmail.com/.../something.deb",
|
||||
// "https://protonmail.com/.../something.rpm",
|
||||
// "https://protonmail.com/.../PKGBUILD"
|
||||
// ],
|
||||
// "LandingPage": "https://protonmail.com/bridge",
|
||||
// "ReleaseNotesPage": "https://protonmail.com/.../release_notes.html",
|
||||
// "RolloutProportion": 0.5
|
||||
// },
|
||||
// "early": {
|
||||
// "Version": "2.4.0",
|
||||
// "Package": "https://protonmail.com/.../bridge_2.4.0_linux.tgz",
|
||||
// "Installers": [
|
||||
// "https://protonmail.com/.../something.deb",
|
||||
// "https://protonmail.com/.../something.rpm",
|
||||
// "https://protonmail.com/.../PKGBUILD"
|
||||
// ],
|
||||
// "LandingPage": "https://protonmail.com/bridge",
|
||||
// "ReleaseNotesPage": "https://protonmail.com/.../release_notes.html",
|
||||
// "RolloutProportion": 0.5
|
||||
// },
|
||||
// "...": {
|
||||
// ...
|
||||
// }
|
||||
// }.
|
||||
//
|
||||
// {
|
||||
// "stable": {
|
||||
// "Version": "2.3.4",
|
||||
// "Package": "https://protonmail.com/.../bridge_2.3.4_linux.tgz",
|
||||
// "Installers": [
|
||||
// "https://protonmail.com/.../something.deb",
|
||||
// "https://protonmail.com/.../something.rpm",
|
||||
// "https://protonmail.com/.../PKGBUILD"
|
||||
// ],
|
||||
// "LandingPage": "https://protonmail.com/bridge",
|
||||
// "ReleaseNotesPage": "https://protonmail.com/.../release_notes.html",
|
||||
// "RolloutProportion": 0.5
|
||||
// },
|
||||
// "early": {
|
||||
// "Version": "2.4.0",
|
||||
// "Package": "https://protonmail.com/.../bridge_2.4.0_linux.tgz",
|
||||
// "Installers": [
|
||||
// "https://protonmail.com/.../something.deb",
|
||||
// "https://protonmail.com/.../something.rpm",
|
||||
// "https://protonmail.com/.../PKGBUILD"
|
||||
// ],
|
||||
// "LandingPage": "https://protonmail.com/bridge",
|
||||
// "ReleaseNotesPage": "https://protonmail.com/.../release_notes.html",
|
||||
// "RolloutProportion": 0.5
|
||||
// },
|
||||
// "...": {
|
||||
// ...
|
||||
// }
|
||||
// }.
|
||||
type VersionMap map[string]VersionInfo
|
||||
|
||||
// getVersionFileURL returns the URL of the version file.
|
||||
// For example:
|
||||
// - https://protonmail.com/download/bridge/version_linux.json
|
||||
// - https://protonmail.com/download/ie/version_linux.json
|
||||
// - https://protonmail.com/download/bridge/version_linux.json
|
||||
// - https://protonmail.com/download/ie/version_linux.json
|
||||
func (u *Updater) getVersionFileURL() string {
|
||||
return fmt.Sprintf("%v/%v/version_%v.json", Host, u.updateURLName, u.platform)
|
||||
}
|
||||
|
||||
@ -20,7 +20,6 @@ package users
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -30,7 +29,7 @@ import (
|
||||
// isFolderEmpty checks whether a folder is empty.
|
||||
// path must point to an existing folder.
|
||||
func isFolderEmpty(path string) (bool, error) {
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
@ -90,13 +89,13 @@ func copyFolder(srcPath, dstPath string) error {
|
||||
if err = os.MkdirAll(dstPath, 0o700); err != nil {
|
||||
return err
|
||||
}
|
||||
files, err := ioutil.ReadDir(srcPath)
|
||||
files, err := os.ReadDir(srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// copy only regular files and folders
|
||||
for _, fileInfo := range files {
|
||||
mode := fileInfo.Mode()
|
||||
mode := fileInfo.Type()
|
||||
if mode&os.ModeSymlink != 0 {
|
||||
continue // we skip symbolic links to avoid potential endless recursion
|
||||
}
|
||||
@ -227,7 +226,7 @@ func (u *Users) MigrateCache(srcPath, dstPath string) error {
|
||||
|
||||
// GODT-1381 Edge case: read-only source migration: prevent re-naming
|
||||
// (read-only is conserved). Do copy instead.
|
||||
tmp, err := ioutil.TempFile(srcPath, "tmp")
|
||||
tmp, err := os.CreateTemp(srcPath, "tmp")
|
||||
if err == nil {
|
||||
// Removal of tmp file cannot be deferred, as we are going to try to move the containing folder.
|
||||
if err = tmp.Close(); err == nil {
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -37,7 +36,7 @@ const (
|
||||
// tempFileWithContent() creates a temporary file in folderPath containing the string content.
|
||||
// Returns the path of the created file.
|
||||
func tempFileWithContent(folderPath, content string) (string, error) {
|
||||
file, err := ioutil.TempFile(folderPath, "")
|
||||
file, err := os.CreateTemp(folderPath, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -49,7 +48,7 @@ func tempFileWithContent(folderPath, content string) (string, error) {
|
||||
// itemCountInFolder() counts the number of items (files, folders, etc) in a folder.
|
||||
// Returns -1 if an error occurred.
|
||||
func itemCountInFolder(path string) int {
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
@ -83,13 +82,13 @@ func filesAreIdentical(path1, path2 string) bool {
|
||||
func TestCache_IsFolderEmpty(t *testing.T) {
|
||||
_, err := isFolderEmpty("")
|
||||
r.Error(t, err)
|
||||
tempDirPath, err := ioutil.TempDir("", "")
|
||||
tempDirPath, err := os.MkdirTemp("", "")
|
||||
defer func() { r.NoError(t, os.Remove(tempDirPath)) }()
|
||||
r.NoError(t, err)
|
||||
result, err := isFolderEmpty(tempDirPath)
|
||||
r.NoError(t, err)
|
||||
r.True(t, result)
|
||||
tempFile, err := ioutil.TempFile(tempDirPath, "")
|
||||
tempFile, err := os.CreateTemp(tempDirPath, "")
|
||||
r.NoError(t, err)
|
||||
defer func() { r.NoError(t, os.Remove(tempFile.Name())) }()
|
||||
r.NoError(t, tempFile.Close())
|
||||
@ -101,10 +100,10 @@ func TestCache_IsFolderEmpty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCache_CheckFolderIsSuitableDestinationForCache(t *testing.T) {
|
||||
tempDirPath, err := ioutil.TempDir("", "")
|
||||
tempDirPath, err := os.MkdirTemp("", "")
|
||||
defer func() { _ = os.Remove(tempDirPath) }() // cleanup in case we fail before removing it.
|
||||
r.NoError(t, err)
|
||||
tempFile, err := ioutil.TempFile(tempDirPath, "")
|
||||
tempFile, err := os.CreateTemp(tempDirPath, "")
|
||||
r.NoError(t, err)
|
||||
defer func() { _ = os.Remove(tempFile.Name()) }() // cleanup in case we fail before removing it.
|
||||
r.NoError(t, tempFile.Close())
|
||||
@ -122,10 +121,10 @@ func TestCache_CopyFolder(t *testing.T) {
|
||||
// |-srcSubDir/
|
||||
// |-file2
|
||||
|
||||
srcDir, err := ioutil.TempDir("", "")
|
||||
srcDir, err := os.MkdirTemp("", "")
|
||||
defer func() { r.NoError(t, os.RemoveAll(srcDir)) }()
|
||||
r.NoError(t, err)
|
||||
srcSubDir, err := ioutil.TempDir(srcDir, "")
|
||||
srcSubDir, err := os.MkdirTemp(srcDir, "")
|
||||
r.NoError(t, err)
|
||||
subDirName := filepath.Base(srcSubDir)
|
||||
file1, err := tempFileWithContent(srcDir, str1)
|
||||
@ -162,7 +161,7 @@ func TestCache_CopyFolder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCache_IsSubfolderOf(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
dir, err := os.MkdirTemp("", "")
|
||||
defer func() { r.NoError(t, os.Remove(dir)) }()
|
||||
r.NoError(t, err)
|
||||
r.True(t, isSubfolderOf(dir, dir))
|
||||
|
||||
@ -19,7 +19,6 @@ package users
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
@ -166,7 +165,7 @@ func initMocks(t *testing.T) mocks {
|
||||
mockCtrl = gomock.NewController(t)
|
||||
}
|
||||
|
||||
cacheFile, err := ioutil.TempFile("", "bridge-store-cache-*.db")
|
||||
cacheFile, err := os.CreateTemp("", "bridge-store-cache-*.db")
|
||||
r.NoError(t, err, "could not get temporary file for store cache")
|
||||
r.NoError(t, cacheFile.Close())
|
||||
|
||||
@ -193,7 +192,7 @@ func initMocks(t *testing.T) mocks {
|
||||
m.storeMaker.EXPECT().New(gomock.Any()).DoAndReturn(func(user store.BridgeUser) (*store.Store, error) {
|
||||
var sentryReporter *sentry.Reporter // Sentry reporter is not used under unit tests.
|
||||
|
||||
dbFile, err := ioutil.TempFile(t.TempDir(), "bridge-store-db-*.db")
|
||||
dbFile, err := os.CreateTemp(t.TempDir(), "bridge-store-db-*.db")
|
||||
r.NoError(t, err, "could not get temporary file for store db")
|
||||
r.NoError(t, dbFile.Close())
|
||||
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -65,12 +64,12 @@ func (v *Version) SemVer() *semver.Version {
|
||||
|
||||
// VerifyFiles verifies all files in the version directory.
|
||||
func (v *Version) VerifyFiles(kr *crypto.KeyRing) error {
|
||||
fileBytes, err := ioutil.ReadFile(filepath.Join(v.path, sumFile)) //nolint:gosec
|
||||
fileBytes, err := os.ReadFile(filepath.Join(v.path, sumFile)) //nolint:gosec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sigBytes, err := ioutil.ReadFile(filepath.Join(v.path, sumFile+".sig")) //nolint:gosec
|
||||
sigBytes, err := os.ReadFile(filepath.Join(v.path, sumFile+".sig")) //nolint:gosec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -19,7 +19,6 @@ package versioner
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -33,7 +32,7 @@ import (
|
||||
)
|
||||
|
||||
func TestVerifyFiles(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "verify-test")
|
||||
tempDir, err := os.MkdirTemp("", "verify-test")
|
||||
require.NoError(t, err)
|
||||
|
||||
version := &Version{
|
||||
@ -53,7 +52,7 @@ func TestVerifyFiles(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyWithBadFile(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "verify-test")
|
||||
tempDir, err := os.MkdirTemp("", "verify-test")
|
||||
require.NoError(t, err)
|
||||
|
||||
version := &Version{
|
||||
@ -76,7 +75,7 @@ func TestVerifyWithBadFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyWithBadSubFile(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "verify-test")
|
||||
tempDir, err := os.MkdirTemp("", "verify-test")
|
||||
require.NoError(t, err)
|
||||
|
||||
version := &Version{
|
||||
@ -136,10 +135,10 @@ func makeFile(t *testing.T, path string) {
|
||||
}
|
||||
|
||||
func signFile(t *testing.T, path string, kr *crypto.KeyRing) {
|
||||
file, err := ioutil.ReadFile(path)
|
||||
file, err := os.ReadFile(path)
|
||||
require.NoError(t, err)
|
||||
|
||||
sig, err := kr.SignDetached(crypto.NewPlainMessage(file))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, ioutil.WriteFile(path+".sig", sig.GetBinary(), 0o700))
|
||||
require.NoError(t, os.WriteFile(path+".sig", sig.GetBinary(), 0o700))
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ package versioner
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
@ -43,7 +43,7 @@ func New(root string) *Versioner {
|
||||
|
||||
// ListVersions returns a collection of all available version numbers, sorted from newest to oldest.
|
||||
func (v *Versioner) ListVersions() (Versions, error) {
|
||||
dirs, err := ioutil.ReadDir(v.root)
|
||||
dirs, err := os.ReadDir(v.root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
package versioner
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@ -33,7 +33,7 @@ import (
|
||||
// RemoveOldVersions is a noop on darwin; we don't test it there.
|
||||
|
||||
func TestRemoveOldVersions(t *testing.T) {
|
||||
updates, err := ioutil.TempDir(t.TempDir(), "updates")
|
||||
updates, err := os.MkdirTemp(t.TempDir(), "updates")
|
||||
require.NoError(t, err)
|
||||
|
||||
v := newTestVersioner(t, "myCoolApp", updates, "2.3.4-beta", "2.3.4", "2.3.5", "2.4.0")
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package versioner
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -29,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
func TestListVersions(t *testing.T) {
|
||||
updates, err := ioutil.TempDir("", "updates")
|
||||
updates, err := os.MkdirTemp("", "updates")
|
||||
require.NoError(t, err)
|
||||
|
||||
v := newTestVersioner(t, "myCoolApp", updates, "2.3.4-beta", "2.3.4", "2.3.5", "2.4.0")
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package files
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -93,7 +92,7 @@ func TestRemoveWithExceptions(t *testing.T) {
|
||||
}
|
||||
|
||||
func newTestDir(t *testing.T, subdirs ...string) string {
|
||||
dir, err := ioutil.TempDir("", "test-files-dir")
|
||||
dir, err := os.MkdirTemp("", "test-files-dir")
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, target := range subdirs {
|
||||
|
||||
@ -20,7 +20,6 @@ package message
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
@ -52,8 +51,8 @@ type Fetcher interface {
|
||||
}
|
||||
|
||||
// NewBuilder creates a new builder which manages the given number of fetch/attach/build workers.
|
||||
// - fetchWorkers: the number of workers which fetch messages from API
|
||||
// - attachWorkers: the number of workers which fetch attachments from API.
|
||||
// - fetchWorkers: the number of workers which fetch messages from API
|
||||
// - attachWorkers: the number of workers which fetch attachments from API.
|
||||
//
|
||||
// The returned builder is ready to handle jobs -- see (*Builder).NewJob for more information.
|
||||
//
|
||||
@ -167,7 +166,7 @@ func newAttacherWorkFunc() pool.WorkFunc {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(rc)
|
||||
b, err := io.ReadAll(rc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -209,7 +208,7 @@ func newFetcherWorkFunc(attachmentPool *pool.Pool) pool.WorkFunc {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(rc)
|
||||
b, err := io.ReadAll(rc)
|
||||
if err != nil {
|
||||
_ = rc.Close()
|
||||
return nil, err
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
@ -83,7 +82,7 @@ func BuildEncrypted(m *pmapi.Message, readers []io.Reader, kr *crypto.KeyRing) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(r)
|
||||
data, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"mime/quotedprintable"
|
||||
"strings"
|
||||
@ -33,7 +32,7 @@ import (
|
||||
)
|
||||
|
||||
func EncryptRFC822(kr *crypto.KeyRing, r io.Reader) ([]byte, error) {
|
||||
b, err := ioutil.ReadAll(r)
|
||||
b, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -118,7 +117,7 @@ func writeEncryptedPart(kr *crypto.KeyRing, header *textproto.Header, r io.Reade
|
||||
}
|
||||
|
||||
func writeEncryptedTextPart(w io.Writer, r io.Reader, kr *crypto.KeyRing) error {
|
||||
dec, err := ioutil.ReadAll(r)
|
||||
dec, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -146,7 +145,7 @@ func writeEncryptedTextPart(w io.Writer, r io.Reader, kr *crypto.KeyRing) error
|
||||
}
|
||||
|
||||
func writeEncryptedAttachmentPart(w io.Writer, r io.Reader, kr *crypto.KeyRing) error {
|
||||
dec, err := ioutil.ReadAll(r)
|
||||
dec, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ package message
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
func TestEncryptRFC822(t *testing.T) {
|
||||
literal, err := ioutil.ReadFile("testdata/text_plain_latin1.eml")
|
||||
literal, err := os.ReadFile("testdata/text_plain_latin1.eml")
|
||||
require.NoError(t, err)
|
||||
|
||||
key, err := crypto.GenerateKey("name", "email", "rsa", 2048)
|
||||
@ -46,7 +46,7 @@ func TestEncryptRFC822(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEncryptRFC822Multipart(t *testing.T) {
|
||||
literal, err := ioutil.ReadFile("testdata/multipart_alternative_nested.eml")
|
||||
literal, err := os.ReadFile("testdata/multipart_alternative_nested.eml")
|
||||
require.NoError(t, err)
|
||||
|
||||
key, err := crypto.GenerateKey("name", "email", "rsa", 2048)
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"unicode"
|
||||
|
||||
"github.com/emersion/go-message/textproto"
|
||||
@ -141,7 +140,7 @@ func splitHeaderBody(b []byte) ([]byte, []byte, error) {
|
||||
}
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(br)
|
||||
body, err := io.ReadAll(br)
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@ -215,8 +215,8 @@ func collectAttachments(p *parser.Parser) ([]*pmapi.Attachment, []io.Reader, err
|
||||
}
|
||||
|
||||
// buildBodies collects all text/html and text/plain parts and returns two bodies,
|
||||
// - a rich text body (in which html is allowed), and
|
||||
// - a plaintext body (in which html is converted to plaintext).
|
||||
// - a rich text body (in which html is allowed), and
|
||||
// - a plaintext body (in which html is converted to plaintext).
|
||||
//
|
||||
// text/html parts are converted to plaintext in order to build the plaintext body,
|
||||
// unless there is already a plaintext part provided via multipart/alternative,
|
||||
|
||||
@ -19,7 +19,6 @@ package parser
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/emersion/go-message"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -129,7 +128,7 @@ func (p *Parser) parseEntity(e *message.Entity) error {
|
||||
}
|
||||
|
||||
func (p *Parser) parsePart(e *message.Entity) (err error) {
|
||||
bytes, err := ioutil.ReadAll(e.Body)
|
||||
bytes, err := io.ReadAll(e.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -19,7 +19,6 @@ package parser
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -44,7 +43,7 @@ func getFileReader(filename string) io.ReadCloser {
|
||||
}
|
||||
|
||||
func getFileAsString(filename string) string {
|
||||
b, err := ioutil.ReadAll(getFileReader(filename))
|
||||
b, err := io.ReadAll(getFileReader(filename))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -20,7 +20,6 @@ package message
|
||||
import (
|
||||
"image/png"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -603,7 +602,7 @@ func getFileReader(filename string) io.Reader {
|
||||
}
|
||||
|
||||
func readerToString(r io.Reader) string {
|
||||
b, err := ioutil.ReadAll(r)
|
||||
b, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/textproto"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -166,7 +165,7 @@ func (bs *BodyStructure) parseAllChildSections(r io.Reader, currentPath []int, s
|
||||
}
|
||||
} else {
|
||||
// Count length.
|
||||
_, _ = bodyReader.WriteTo(ioutil.Discard)
|
||||
_, _ = bodyReader.WriteTo(io.Discard)
|
||||
}
|
||||
|
||||
// Clear all buffers.
|
||||
|
||||
@ -20,7 +20,7 @@ package message
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
@ -93,7 +93,7 @@ func TestParseBodyStructurePGP(t *testing.T) {
|
||||
"2": "application/pgp-signature; name=\"OpenPGP_signature.asc\"",
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadFile("testdata/enc-body-structure.eml")
|
||||
b, err := os.ReadFile("testdata/enc-body-structure.eml")
|
||||
require.NoError(t, err)
|
||||
|
||||
bs, err := NewBodyStructure(bytes.NewReader(b))
|
||||
|
||||
@ -24,7 +24,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/textproto"
|
||||
@ -114,7 +113,7 @@ func TestClient_CreateAttachment(t *testing.T) {
|
||||
r.NoError(err)
|
||||
defer r.NoError(dataFile.Close())
|
||||
|
||||
b, err := ioutil.ReadAll(dataFile)
|
||||
b, err := io.ReadAll(dataFile)
|
||||
r.NoError(err)
|
||||
r.Equal(testAttachmentCleartext, string(b))
|
||||
|
||||
@ -146,7 +145,7 @@ func TestClient_GetAttachment(t *testing.T) {
|
||||
defer att.Close() //nolint:errcheck
|
||||
|
||||
// In reality, r contains encrypted data
|
||||
b, err := ioutil.ReadAll(att)
|
||||
b, err := io.ReadAll(att)
|
||||
r.NoError(err)
|
||||
|
||||
r.Equal(testAttachmentCleartext, string(b))
|
||||
@ -181,7 +180,7 @@ func TestAttachmentEncrypt(t *testing.T) {
|
||||
func decryptAndCheck(r *require.Assertions, data io.Reader) {
|
||||
// First separate KeyPacket from encrypted data. In our case keypacket
|
||||
// has 271 bytes.
|
||||
raw, err := ioutil.ReadAll(data)
|
||||
raw, err := io.ReadAll(data)
|
||||
r.NoError(err)
|
||||
rawKeyPacket := raw[:271]
|
||||
rawDataPacket := raw[271:]
|
||||
@ -195,7 +194,7 @@ func decryptAndCheck(r *require.Assertions, data io.Reader) {
|
||||
decryptedReader, err := haveAttachment.Decrypt(bytes.NewBuffer(rawDataPacket), testPrivateKeyRing)
|
||||
r.NoError(err)
|
||||
|
||||
b, err := ioutil.ReadAll(decryptedReader)
|
||||
b, err := io.ReadAll(decryptedReader)
|
||||
r.NoError(err)
|
||||
|
||||
r.Equal(testAttachmentCleartext, string(b))
|
||||
|
||||
@ -20,7 +20,7 @@ package pmapi
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -139,6 +139,6 @@ func (r tlsReport) sendReport(cfg Config, uri string) {
|
||||
logrus.WithField("status", http.StatusOK).Error("StatusCode was not OK")
|
||||
}
|
||||
|
||||
_, _ = ioutil.ReadAll(res.Body)
|
||||
_, _ = io.ReadAll(res.Body)
|
||||
_ = res.Body.Close()
|
||||
}
|
||||
|
||||
@ -54,10 +54,10 @@ type Event struct {
|
||||
type EventAction int
|
||||
|
||||
const (
|
||||
EventDelete EventAction = iota // Item has been deleted.
|
||||
EventCreate // Item has been created.
|
||||
EventUpdate // Item has been updated.
|
||||
EventUpdateFlags // For messages: flags have been updated.
|
||||
EventDelete EventAction = iota // EventDelete Item has been deleted.
|
||||
EventCreate // EventCreate Item has been created.
|
||||
EventUpdate // EventUpdate Item has been updated.
|
||||
EventUpdateFlags // EventUpdateFlags For messages: flags have been updated.
|
||||
)
|
||||
|
||||
// Flags for event refresh.
|
||||
|
||||
@ -29,7 +29,7 @@ import (
|
||||
|
||||
const (
|
||||
MaxImportMessageRequestLength = 10
|
||||
MaxImportMessageRequestSize = 25 * 1024 * 1024 // 25 MB total limit
|
||||
MaxImportMessageRequestSize = 25 * 1024 * 1024 // MaxImportMessageRequestSize 25 MB total limit
|
||||
)
|
||||
|
||||
type ImportMsgReq struct {
|
||||
|
||||
@ -22,7 +22,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
@ -76,7 +75,7 @@ func TestClient_Import(t *testing.T) { //nolint:funlen
|
||||
r.Equal(t, "form-data", contentDisp)
|
||||
r.Equal(t, "0", params["name"])
|
||||
|
||||
b, err := ioutil.ReadAll(p)
|
||||
b, err := io.ReadAll(p)
|
||||
r.NoError(t, err)
|
||||
r.Equal(t, string(testImportReqs[0].Message), string(b))
|
||||
|
||||
|
||||
@ -22,7 +22,6 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/pkg/errors"
|
||||
@ -231,7 +230,7 @@ func encryptAttachment(kr *crypto.KeyRing, data io.Reader, filename string) (enc
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dataBytes, err := ioutil.ReadAll(data)
|
||||
dataBytes, err := io.ReadAll(data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -253,7 +252,7 @@ func decryptAttachment(kr *crypto.KeyRing, keyPackets []byte, data io.Reader) (d
|
||||
if kr == nil {
|
||||
return nil, ErrNoKeyringAvailable
|
||||
}
|
||||
dataBytes, err := ioutil.ReadAll(data)
|
||||
dataBytes, err := io.ReadAll(data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -269,7 +268,7 @@ func signAttachment(encrypter *crypto.KeyRing, data io.Reader) (signature io.Rea
|
||||
if encrypter == nil {
|
||||
return nil, ErrNoKeyringAvailable
|
||||
}
|
||||
dataBytes, err := ioutil.ReadAll(data)
|
||||
dataBytes, err := io.ReadAll(data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
package pmapi
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"golang.org/x/net/context"
|
||||
@ -56,7 +56,7 @@ func (m *manager) fetchFile(url string) ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(res.RawBody())
|
||||
b, err := io.ReadAll(res.RawBody())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ package pmapi
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
@ -68,7 +68,7 @@ func TestClient_BugReportWithAttachment(t *testing.T) {
|
||||
|
||||
attReader, err := req.MultipartForm.File["log"][0].Open()
|
||||
r.NoError(t, err)
|
||||
_, err = ioutil.ReadAll(attReader)
|
||||
_, err = io.ReadAll(attReader)
|
||||
r.NoError(t, err)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
@ -27,7 +27,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/mail"
|
||||
"net/url"
|
||||
@ -133,10 +132,10 @@ const (
|
||||
type LabelsOperation int
|
||||
|
||||
const (
|
||||
KeepLabels LabelsOperation = iota // Do nothing.
|
||||
ReplaceLabels // Replace current labels with new ones.
|
||||
AddLabels // Add new labels to current ones.
|
||||
RemoveLabels // Remove specified labels from current ones.
|
||||
KeepLabels LabelsOperation = iota // KeepLabels Do nothing.
|
||||
ReplaceLabels // ReplaceLabels Replace current labels with new ones.
|
||||
AddLabels // AddLabels Add new labels to current ones.
|
||||
RemoveLabels // RemoveLabels Remove specified labels from current ones.
|
||||
)
|
||||
|
||||
// Due to API limitations, we shouldn't make requests with more than 100 message IDs at a time.
|
||||
@ -309,7 +308,7 @@ func (m *Message) ExtractSignatures(kr *crypto.KeyRing) ([]Signature, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := ioutil.ReadAll(msg.UnverifiedBody); err != nil {
|
||||
if _, err := io.ReadAll(msg.UnverifiedBody); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
package pmapi
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
@ -65,7 +65,7 @@ func init() {
|
||||
}
|
||||
|
||||
func readTestFile(name string, trimNewlines bool) string { //nolint:unparam
|
||||
data, err := ioutil.ReadFile("testdata/" + name)
|
||||
data, err := os.ReadFile("testdata/" + name)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
package sum
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
func TestRecursiveSum(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "verify-test")
|
||||
tempDir, err := os.MkdirTemp("", "verify-test")
|
||||
require.NoError(t, err)
|
||||
|
||||
createFiles(t, tempDir,
|
||||
@ -97,7 +97,7 @@ func modifyFile(t *testing.T, path string, data []byte) []byte {
|
||||
r, err := os.Open(path)
|
||||
require.NoError(t, err)
|
||||
|
||||
b, err := ioutil.ReadAll(r)
|
||||
b, err := io.ReadAll(r)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, r.Close())
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ package accounts
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -90,7 +89,7 @@ func (a *TestAccount) initKeys() {
|
||||
func readTestFile(fileName string) []byte {
|
||||
testDataFolder := os.Getenv("TEST_DATA")
|
||||
path := filepath.Join(testDataFolder, fileName)
|
||||
data, err := ioutil.ReadFile(path) //nolint:gosec
|
||||
data, err := os.ReadFile(path) //nolint:gosec
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ package accounts
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/v2/pkg/pmapi"
|
||||
"github.com/pkg/errors"
|
||||
@ -37,7 +37,7 @@ type TestAccounts struct {
|
||||
}
|
||||
|
||||
func Load(path string) (*TestAccounts, error) {
|
||||
data, err := ioutil.ReadFile(path) //nolint:gosec
|
||||
data, err := os.ReadFile(path) //nolint:gosec
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to load JSON")
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ package context
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"runtime/pprof"
|
||||
)
|
||||
|
||||
@ -41,7 +41,7 @@ func (ph *panicHandler) HandlePanic() {
|
||||
|
||||
r := bytes.NewBufferString("")
|
||||
_ = pprof.Lookup("goroutine").WriteTo(r, 2)
|
||||
b, err := ioutil.ReadAll(r)
|
||||
b, err := io.ReadAll(r)
|
||||
ph.t.Errorf("pprof details: %s %s", err, b)
|
||||
|
||||
ph.t.FailNow()
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
@ -29,7 +29,7 @@ type fakeCache struct {
|
||||
// newFakeCache creates a temporary folder for files.
|
||||
// It's expected the test calls `ClearData` before finish to remove it from the file system.
|
||||
func newFakeCache() *fakeCache {
|
||||
dir, err := ioutil.TempDir("", "test-cache")
|
||||
dir, err := os.MkdirTemp("", "test-cache")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -27,7 +26,7 @@ type fakeLocations struct {
|
||||
}
|
||||
|
||||
func newFakeLocations() *fakeLocations {
|
||||
dir, err := ioutil.TempDir("", "test-cache")
|
||||
dir, err := os.MkdirTemp("", "test-cache")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/config/settings"
|
||||
)
|
||||
@ -32,7 +32,7 @@ type fakeSettings struct {
|
||||
// newFakeSettings creates a temporary folder for files.
|
||||
// It's expected the test calls `ClearData` before finish to remove it from the file system.
|
||||
func newFakeSettings() *fakeSettings {
|
||||
dir, err := ioutil.TempDir("", "test-settings")
|
||||
dir, err := os.MkdirTemp("", "test-settings")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -23,7 +23,6 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/textproto"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/v2/pkg/pmapi"
|
||||
@ -32,8 +31,8 @@ import (
|
||||
// dataPacketOutlineLightInstagram48png is data packet with encrypted data and
|
||||
// session key
|
||||
//
|
||||
// gpg: encrypted with 2048-bit RSA key, ID 70B8CA23079F2167, created 2019-09-23
|
||||
// "james-test@protonmail.blue <james-test@protonmail.blue>"
|
||||
// gpg: encrypted with 2048-bit RSA key, ID 70B8CA23079F2167, created 2019-09-23
|
||||
// "james-test@protonmail.blue <james-test@protonmail.blue>"
|
||||
//
|
||||
// If you need to rebuild you can dump KeyPacket string from `CreateAttachment`
|
||||
// function when called during message sending test.
|
||||
@ -63,14 +62,14 @@ func (api *FakePMAPI) GetAttachment(_ context.Context, attachmentID string) (io.
|
||||
return nil, err
|
||||
}
|
||||
r := bytes.NewReader(b)
|
||||
return ioutil.NopCloser(r), nil
|
||||
return io.NopCloser(r), nil
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) CreateAttachment(_ context.Context, attachment *pmapi.Attachment, data io.Reader, signature io.Reader) (*pmapi.Attachment, error) {
|
||||
if err := api.checkAndRecordCall(POST, "/mail/v4/attachments", nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bytes, err := ioutil.ReadAll(data)
|
||||
bytes, err := io.ReadAll(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -41,13 +41,13 @@ func (api *FakePMAPI) GetMessage(_ context.Context, apiID string) (*pmapi.Messag
|
||||
}
|
||||
|
||||
// ListMessages does not implement following filters:
|
||||
// * Sort (it sorts by ID only), but Desc works
|
||||
// * Keyword
|
||||
// * To
|
||||
// * Subject
|
||||
// * ID
|
||||
// * Attachments
|
||||
// * AutoWildcard
|
||||
// - Sort (it sorts by ID only), but Desc works
|
||||
// - Keyword
|
||||
// - To
|
||||
// - Subject
|
||||
// - ID
|
||||
// - Attachments
|
||||
// - AutoWildcard
|
||||
func (api *FakePMAPI) ListMessages(_ context.Context, filter *pmapi.MessagesFilter) ([]*pmapi.Message, int, error) {
|
||||
if err := api.checkAndRecordCall(GET, "/mail/v4/messages", filter); err != nil {
|
||||
return nil, 0, err
|
||||
|
||||
@ -64,7 +64,7 @@ func (pc *persistentClient) AuthDelete(_ context.Context) error {
|
||||
|
||||
// AuthSalt returns cached string. Otherwise after some time there is an error:
|
||||
//
|
||||
// Access token does not have sufficient scope
|
||||
// Access token does not have sufficient scope
|
||||
//
|
||||
// while all other routes works normally. Need to confirm with Aron that this
|
||||
// is expected behaviour.
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
package liveapi
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@ -49,7 +49,7 @@ func (t *fakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
return nil, errors.Wrap(err, "failed to get body")
|
||||
}
|
||||
if bodyReader != nil {
|
||||
body, err = ioutil.ReadAll(bodyReader)
|
||||
body, err = io.ReadAll(bodyReader)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to read body")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user