Skip to content

Commit

Permalink
Merge branch 'master' into age/plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Yolan Romailler <[email protected]>
  • Loading branch information
AnomalRoil committed Oct 2, 2024
2 parents eefa21e + 486c165 commit 3e9a9de
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 31 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
version: v1.59.1 # we have a list of linters in our .golangci.yml config file
# Note: there are 2 different version of golangci-lint used inside the project.
# https://github.com/gopasspw/gopass/blob/master/.github/workflows/build.yml#L65
# https://github.com/gopasspw/gopass/blob/master/.github/workflows/golangci-lint.yml#L46
# https://github.com/gopasspw/gopass/blob/master/Makefile#L136
version: v1.61.0 # we have a list of linters in our .golangci.yml config file
only-new-issues: true
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ linters:
- errname
- errorlint
- exhaustive
- exportloopref
# - exportloopref # deprecated since Go 1.22
- forcetypeassert
- funlen
- ginkgolinter
Expand Down Expand Up @@ -90,6 +90,7 @@ issues:
- helpers/

output:
show-stats: true
sort-results: true
sort-order:
- linter
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ crosscompile:
codequality:
@echo ">> CODE QUALITY"

# Note: there are 2 different version of golangci-lint used inside the project.
# https://github.com/gopasspw/gopass/blob/master/.github/workflows/build.yml#L65
# https://github.com/gopasspw/gopass/blob/master/.github/workflows/golangci-lint.yml#L46
# https://github.com/gopasspw/gopass/blob/master/Makefile#L136
@echo -n " GOLANGCI-LINT "
@which golangci-lint > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
Expand Down
6 changes: 3 additions & 3 deletions internal/action/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (s *Action) showHandleOutput(ctx context.Context, name string, sec gopass.S
out.Warning(ctx, "show.safecontent=true. Use -f to display password, if any")
}

return exit.Error(exit.NotFound, store.ErrEmptySecret, store.ErrEmptySecret.Error())
return exit.Error(exit.NotFound, store.ErrEmptySecret, "%v", store.ErrEmptySecret)
}

if IsPrintQR(ctx) && IsQRBody(ctx) {
Expand Down Expand Up @@ -244,7 +244,7 @@ func (s *Action) showGetContent(ctx context.Context, sec gopass.Secret) (string,
key := GetKey(ctx)
values, found := sec.Values(key)
if !found {
return "", "", exit.Error(exit.NotFound, store.ErrNoKey, store.ErrNoKey.Error())
return "", "", exit.Error(exit.NotFound, store.ErrNoKey, "%v", store.ErrNoKey)
}
val := strings.Join(values, "\n")

Expand All @@ -264,7 +264,7 @@ func (s *Action) showGetContent(ctx context.Context, sec gopass.Secret) (string,
}
if IsPasswordOnly(ctx) {
if pw == "" && fullBody != "" {
return "", "", exit.Error(exit.NotFound, store.ErrNoPassword, store.ErrNoPassword.Error())
return "", "", exit.Error(exit.NotFound, store.ErrNoPassword, "%v", store.ErrNoPassword)
}

return pw, pw, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/crypto/gpg/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (k Key) String() string {

out += "\n Key fingerprint = " + k.Fingerprint
for _, id := range k.Identities {
out += fmt.Sprintf("\n" + id.String())
out += fmt.Sprintf("\n%s", id)
}

return out
Expand Down
2 changes: 1 addition & 1 deletion internal/store/leaf/recipients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestSaveRecipients(t *testing.T) {
sort.Strings(foundRecs)

ids := rs.IDs()
for i := range len(ids) {
for i := range ids {
if i >= len(foundRecs) {
t.Errorf("Read too few recipients")

Expand Down
3 changes: 2 additions & 1 deletion pkg/clipboard/clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var (
// -ldflags=='-X github.com/gopasspw/gopass/pkg/clipboard.Helpers=termux-api'.
Helpers = "xsel or xclip"
// ErrNotSupported is returned when the clipboard is not accessible.
ErrNotSupported = fmt.Errorf("WARNING: No clipboard available. Install " + Helpers + ", provide $GOPASS_CLIPBOARD_COPY_CMD and $GOPASS_CLIPBOARD_CLEAR_CMD or use -f to print to console")
ErrNotSupported = fmt.Errorf("WARNING: No clipboard available. "+
"Install %s, provide $GOPASS_CLIPBOARD_COPY_CMD and $GOPASS_CLIPBOARD_CLEAR_CMD or use -f to print to console", Helpers)
)

// CopyTo copies the given data to the clipboard and enqueues automatic
Expand Down
3 changes: 0 additions & 3 deletions pkg/fsutil/fsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"path/filepath"
"regexp"
"strings"
"time"

"github.com/gopasspw/gopass/pkg/appdir"
"github.com/gopasspw/gopass/pkg/debug"
Expand Down Expand Up @@ -138,8 +137,6 @@ func IsEmptyDir(path string) (bool, error) {

// Shred overwrite the given file any number of times.
func Shred(path string, runs int) error {
rand.Seed(time.Now().UnixNano())

fh, err := os.OpenFile(path, os.O_WRONLY, 0o600)
if err != nil {
return fmt.Errorf("failed to open file %q: %w", path, err)
Expand Down
2 changes: 0 additions & 2 deletions pkg/gitconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strconv"
"strings"
"testing"
"time"

"github.com/gopasspw/gopass/internal/set"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -274,7 +273,6 @@ func TestLoadFromEnv(t *testing.T) {
"core.timeout": "10",
}

rand.Seed(time.Now().Unix())
prefix := fmt.Sprintf("GPTEST%d", rand.Int31n(8192))

i := 0
Expand Down
16 changes: 9 additions & 7 deletions pkg/pwgen/pwgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package pwgen

import (
"bytes"
"crypto/rand"
crand "crypto/rand"
"fmt"
"io"
mrand "math/rand"
"math/rand"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -40,12 +40,14 @@ func TestPwgenCharset(t *testing.T) {
assert.Equal(t, "", GeneratePasswordCharsetCheck(4, "a"))
}

func TestPwgenNoCrand(t *testing.T) {
old := rand.Reader
rand.Reader = strings.NewReader("")
func TestPwgenNoCrandFallback(t *testing.T) {
oldFallback := randFallback
oldReader := crand.Reader
crand.Reader = strings.NewReader("")

defer func() {
rand.Reader = old
crand.Reader = oldReader
randFallback = oldFallback
}()

oldOut := os.Stdout
Expand All @@ -61,7 +63,7 @@ func TestPwgenNoCrand(t *testing.T) {
}()

// if we seed math/rand with 1789, the first "random number" will be 42
mrand.Seed(1789)
randFallback = rand.New(rand.NewSource(1789))

n := randomInteger(1024)

Expand Down
6 changes: 4 additions & 2 deletions pkg/pwgen/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (

func init() {
// seed math/rand in case we have to fall back to using it
rand.Seed(time.Now().Unix() + int64(os.Getpid()+os.Getppid()))
randFallback = rand.New(rand.NewSource(time.Now().Unix() + int64(os.Getpid()+os.Getppid())))
}

var randFallback *rand.Rand

func randomInteger(max int) int {
i, err := crand.Int(crand.Reader, big.NewInt(int64(max)))
if err == nil {
Expand All @@ -22,5 +24,5 @@ func randomInteger(max int) int {

fmt.Fprintln(os.Stderr, "WARNING: No crypto/rand available. Falling back to PRNG")

return rand.Intn(max)
return randFallback.Intn(max)
}
2 changes: 0 additions & 2 deletions tests/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ foo/

// regression test for #1628.
func TestListRegressions1628(t *testing.T) {
t.Parallel()

ts := newTester(t)
defer ts.teardown()

Expand Down
15 changes: 8 additions & 7 deletions tests/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type tester struct {
resetFn func()
}

// newTester is not compatible with t.Parallel because it uses t.Setenv.
func newTester(t *testing.T) *tester {
t.Helper()

Expand Down Expand Up @@ -77,13 +78,13 @@ func newTester(t *testing.T) *tester {

// prepare ENVIRONMENT
ts.resetFn = gptest.UnsetVars("GNUPGHOME", "GOPASS_DEBUG", "NO_COLOR", "GOPASS_CONFIG", "GOPASS_NO_NOTIFY", "GOPASS_HOMEDIR")
require.NoError(t, os.Setenv("GNUPGHOME", ts.gpgDir()))
require.NoError(t, os.Setenv("GOPASS_DEBUG", ""))
require.NoError(t, os.Setenv("NO_COLOR", "true"))
require.NoError(t, os.Setenv("GOPASS_CONFIG_NOSYSTEM", "true"))
require.NoError(t, os.Setenv("GOPASS_CONFIG_NO_MIGRATE", "true"))
require.NoError(t, os.Setenv("GOPASS_NO_NOTIFY", "true"))
require.NoError(t, os.Setenv("GOPASS_HOMEDIR", td))
t.Setenv("GNUPGHOME", ts.gpgDir())
t.Setenv("GOPASS_DEBUG", "")
t.Setenv("NO_COLOR", "true")
t.Setenv("GOPASS_CONFIG_NOSYSTEM", "true")
t.Setenv("GOPASS_CONFIG_NO_MIGRATE", "true")
t.Setenv("GOPASS_NO_NOTIFY", "true")
t.Setenv("GOPASS_HOMEDIR", td)

// write config
require.NoError(t, os.MkdirAll(filepath.Dir(ts.gopassConfig()), 0o700))
Expand Down

0 comments on commit 3e9a9de

Please sign in to comment.