mirror of
https://github.com/gopasspw/gopass.git
synced 2025-12-08 19:24:54 +00:00
* [chore] Migrate to golangci-lint v2 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issue Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Add more package comments. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix golangci-lint config and the remaining checks Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Use Go 1.24 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix container builds Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix more failing tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix test failure Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix another len assertion Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Move location tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix most remaining lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Only run XDG specific tests on linux Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Attempt to address on source of flaky failures Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> --------- Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
78 lines
1.5 KiB
Go
78 lines
1.5 KiB
Go
package audit
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gopasspw/gopass/internal/backend"
|
|
"github.com/gopasspw/gopass/pkg/gopass"
|
|
"github.com/gopasspw/gopass/pkg/gopass/secrets"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type mockSecretGetter struct{}
|
|
|
|
func (m *mockSecretGetter) Get(ctx context.Context, name string) (gopass.Secret, error) {
|
|
sec := secrets.New()
|
|
sec.SetPassword("password")
|
|
|
|
return sec, nil
|
|
}
|
|
|
|
func (m *mockSecretGetter) ListRevisions(ctx context.Context, name string) ([]backend.Revision, error) {
|
|
return []backend.Revision{
|
|
{Date: time.Now().Add(-time.Hour * 24 * 365)},
|
|
}, nil
|
|
}
|
|
|
|
func (m *mockSecretGetter) Concurrency() int {
|
|
return 1
|
|
}
|
|
|
|
func TestNewAuditor(t *testing.T) {
|
|
ctx := t.Context()
|
|
s := &mockSecretGetter{}
|
|
a := New(ctx, s)
|
|
|
|
assert.NotNil(t, a)
|
|
assert.Equal(t, s, a.s)
|
|
assert.NotNil(t, a.r)
|
|
assert.NotNil(t, a.v)
|
|
}
|
|
|
|
func TestBatch(t *testing.T) {
|
|
ctx := t.Context()
|
|
s := &mockSecretGetter{}
|
|
a := New(ctx, s)
|
|
|
|
secrets := []string{"secret1", "secret2"}
|
|
report, err := a.Batch(ctx, secrets)
|
|
|
|
require.NoError(t, err)
|
|
assert.NotNil(t, report)
|
|
assert.Len(t, secrets, len(report.Secrets))
|
|
}
|
|
|
|
func TestAuditSecret(t *testing.T) {
|
|
ctx := t.Context()
|
|
s := &mockSecretGetter{}
|
|
a := New(ctx, s)
|
|
|
|
secret := "secret1"
|
|
a.auditSecret(ctx, secret)
|
|
|
|
assert.Contains(t, a.r.secrets, secret)
|
|
}
|
|
|
|
func TestCheckHIBP(t *testing.T) {
|
|
ctx := t.Context()
|
|
s := &mockSecretGetter{}
|
|
a := New(ctx, s)
|
|
|
|
err := a.checkHIBP(ctx)
|
|
|
|
require.NoError(t, err)
|
|
}
|