mirror of
https://github.com/gopasspw/gopass.git
synced 2026-05-30 11:18:48 +02:00
dfb8fcb787
This commit adds yet another config handler for gopass. It is based on the format used by git itself. This has the potential to address a lot of long standing issues, but it also causes a lot of changes to how we handle configuration, so bugs are inevitable. Fixes #1567 Fixes #1764 Fixes #1819 Fixes #1878 Fixes #2387 RELEASE_NOTES=[BREAKING] New config format based on git config. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> Co-authored-by: Yolan Romailler <AnomalRoil@users.noreply.github.com>
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package action
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/gopasspw/gopass/internal/out"
|
|
"github.com/gopasspw/gopass/pkg/ctxutil"
|
|
"github.com/gopasspw/gopass/pkg/gopass/secrets"
|
|
"github.com/gopasspw/gopass/tests/gptest"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestProcess(t *testing.T) { //nolint:paralleltest
|
|
u := gptest.NewUnitTester(t)
|
|
defer u.Remove()
|
|
|
|
ctx := context.Background()
|
|
ctx = ctxutil.WithAlwaysYes(ctx, true)
|
|
ctx = ctxutil.WithInteractive(ctx, false)
|
|
|
|
buf := &bytes.Buffer{}
|
|
out.Stdout = buf
|
|
stdout = buf
|
|
defer func() {
|
|
out.Stdout = os.Stdout
|
|
stdout = os.Stdout
|
|
}()
|
|
|
|
act, err := newMock(ctx, u.StoreDir(""))
|
|
require.NoError(t, err)
|
|
require.NotNil(t, act)
|
|
ctx = act.cfg.WithConfig(ctx)
|
|
|
|
sec := secrets.New()
|
|
assert.NoError(t, sec.Set("username", "admin"))
|
|
sec.SetPassword("hunter2")
|
|
require.NoError(t, act.Store.Set(ctx, "server/local/mysql", sec))
|
|
|
|
infile := filepath.Join(u.Dir, "my.cnf.tpl")
|
|
err = ioutil.WriteFile(infile, []byte(`[client]
|
|
host=127.0.0.1
|
|
port=3306
|
|
user={{ getval "server/local/mysql" "username" }}
|
|
password={{ getpw "server/local/mysql" }}`), 0o644)
|
|
require.NoError(t, err)
|
|
|
|
t.Run("process template", func(t *testing.T) {
|
|
defer buf.Reset()
|
|
|
|
err := act.Process(gptest.CliCtx(ctx, t, infile))
|
|
require.NoError(t, err)
|
|
assert.Equal(t, `[client]
|
|
host=127.0.0.1
|
|
port=3306
|
|
user=admin
|
|
password=hunter2
|
|
`, buf.String(), "processed template")
|
|
})
|
|
}
|