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