mirror of
https://github.com/gopasspw/gopass.git
synced 2025-12-08 19:24:54 +00:00
* [CLEANUP] Moving options to the correct config section This adds an easy migration path to our config handling, which should allow us to migrate option names around much more easily in the future. Any system level config or env variables options are not migrated. This also fixes a bug in our test code, where the root mount path was not properly set in our config, because we used "path:" instead of "path=" to set it. Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com> * [DOCUMENTATION] Document legacy options and their migration path This also makes sure that legacy options aren't used in the code anymore using the docs test and its regexp Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com> * [n/a] Removing weird spaces from changelog Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com> * [DOCUMENTATION] Reformatting our Markdown tables properly Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com> * [TESTING] Patching a timezone bug in tests This is a fun one where if your Timezone isn't UTC and you are past midnight but it's not past midnight UTC, the tests would fail because you're not using the right date to validate it. Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com> * [n/a] Fix a typo and use the correct Env variables in the doc about the custom Env variables Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com> * [BREAKING] Custom Env options moved from GOPASS_CONFIG_CONFIG_KEY_i to GOPASS_CONFIG_KEY_i As discussed in #2617, this actually reflects the way GIT_CONFIG works. It also fixes a potential Panic in our codebase when IsSet was called without any Preset config on a non-existing key. Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com> * [CLEANUP] Patching all of the new linter complaints Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com> * [CLEANUP] Use Go1.21 everywhere Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com> * [n/a] Increase our Golangci timeout Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com> * [n/a] code review comment and extra regression test Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com> --------- Signed-off-by: Yolan Romailler <anomalroil@users.noreply.github.com>
130 lines
2.8 KiB
Go
130 lines
2.8 KiB
Go
package tests
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestBinaryCopy(t *testing.T) {
|
|
ts := newTester(t)
|
|
defer ts.teardown()
|
|
|
|
t.Run("empty store", func(t *testing.T) {
|
|
_, err := ts.run("fscopy")
|
|
require.Error(t, err)
|
|
})
|
|
|
|
ts.initStore()
|
|
|
|
t.Run("no args", func(t *testing.T) {
|
|
out, err := ts.run("fscopy")
|
|
require.Error(t, err)
|
|
assert.Equal(t, "\nError: usage: gopass fscopy from to\n", out)
|
|
})
|
|
|
|
fn := filepath.Join(ts.tempDir, "copy")
|
|
dat := []byte("foobar")
|
|
require.NoError(t, os.WriteFile(fn, dat, 0o644))
|
|
|
|
t.Run("copy file to store", func(t *testing.T) {
|
|
_, err := ts.run("fscopy " + fn + " foo/bar")
|
|
require.NoError(t, err)
|
|
require.NoError(t, os.Remove(fn))
|
|
})
|
|
|
|
t.Run("copy store to file", func(t *testing.T) {
|
|
_, err := ts.run("fscopy foo/bar " + fn)
|
|
require.NoError(t, err)
|
|
|
|
buf, err := os.ReadFile(fn)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, buf, dat)
|
|
})
|
|
|
|
t.Run("cat from store", func(t *testing.T) {
|
|
_, err := ts.run("cat foo/bar")
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
|
|
func TestBinaryMove(t *testing.T) {
|
|
ts := newTester(t)
|
|
defer ts.teardown()
|
|
|
|
t.Run("empty store", func(t *testing.T) {
|
|
_, err := ts.run("fsmove")
|
|
require.Error(t, err)
|
|
})
|
|
|
|
ts.initStore()
|
|
|
|
t.Run("no args", func(t *testing.T) {
|
|
out, err := ts.run("fsmove")
|
|
require.Error(t, err)
|
|
assert.Equal(t, "\nError: usage: gopass fsmove from to\n", out)
|
|
})
|
|
|
|
fn := filepath.Join(ts.tempDir, "move")
|
|
dat := []byte("foobar")
|
|
require.NoError(t, os.WriteFile(fn, dat, 0o644))
|
|
|
|
t.Run("move fs to store", func(t *testing.T) {
|
|
_, err := ts.run("fsmove " + fn + " foo/bar")
|
|
require.NoError(t, err)
|
|
require.Error(t, os.Remove(fn))
|
|
})
|
|
|
|
t.Run("move store to fs", func(t *testing.T) {
|
|
_, err := ts.run("fsmove foo/bar " + fn)
|
|
require.NoError(t, err)
|
|
|
|
buf, err := os.ReadFile(fn)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, buf, dat)
|
|
})
|
|
|
|
t.Run("cat secret", func(t *testing.T) {
|
|
_, err := ts.run("cat foo/bar")
|
|
require.Error(t, err)
|
|
})
|
|
}
|
|
|
|
func TestBinaryShasum(t *testing.T) {
|
|
ts := newTester(t)
|
|
defer ts.teardown()
|
|
|
|
t.Run("shasum on empty store", func(t *testing.T) {
|
|
_, err := ts.run("sha256")
|
|
require.Error(t, err)
|
|
})
|
|
|
|
ts.initStore()
|
|
|
|
t.Run("shasum w/o args", func(t *testing.T) {
|
|
out, err := ts.run("sha256")
|
|
require.Error(t, err)
|
|
assert.Equal(t, "\nError: Usage: gopass sha256 name\n", out)
|
|
})
|
|
|
|
t.Run("populate store", func(t *testing.T) {
|
|
fn := filepath.Join(ts.tempDir, "shasum")
|
|
dat := []byte("foobar")
|
|
require.NoError(t, os.WriteFile(fn, dat, 0o644))
|
|
|
|
_, err := ts.run("fsmove " + fn + " foo/bar")
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
t.Run("shasum on binary secret", func(t *testing.T) {
|
|
out, err := ts.run("sha256 foo/bar")
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2", out)
|
|
})
|
|
}
|