mirror of
https://github.com/gopasspw/gopass.git
synced 2026-10-07 16:51:40 +02: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>
110 lines
2.4 KiB
Go
110 lines
2.4 KiB
Go
package age
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"filippo.io/age"
|
|
"filippo.io/age/plugin"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestParseIdentity(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
encoding string
|
|
expectedType any
|
|
shouldFail bool
|
|
}{
|
|
{
|
|
"plugin id",
|
|
"AGE-PLUGIN-YUBIKEY-1GKZKJQYZL98RLMC67F9PJ",
|
|
&wrappedIdentity{},
|
|
false,
|
|
},
|
|
{
|
|
"native age id",
|
|
"AGE-SECRET-KEY-1RLNPSS8EV69RL40DKHUFUPU9SNWHUYYJQQMF3ZXQ7S4F3PTPS8EQ2RWVNA",
|
|
&age.X25519Identity{},
|
|
false,
|
|
},
|
|
{
|
|
"invalid age id",
|
|
"AGE-NONSECRET-KEY-TEST",
|
|
nil,
|
|
true,
|
|
},
|
|
{
|
|
"invalid bech32 plugin",
|
|
"AGE-PLUGIN-YUBIKEY-1GKKJQYZL98RLM7FJ",
|
|
nil,
|
|
true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
tID, err := parseIdentity(tt.encoding)
|
|
if tt.shouldFail {
|
|
require.Error(t, err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
require.IsType(t, tt.expectedType, tID)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestIdentityAndRecipient(t *testing.T) {
|
|
testID, err := age.GenerateX25519Identity()
|
|
require.NoError(t, err)
|
|
|
|
pluginID, err := plugin.NewIdentity("AGE-PLUGIN-YUBIKEY-1GKZKJQYZL98RLMC67F9PJ", nil)
|
|
require.NoError(t, err)
|
|
pluginRec, err := plugin.NewRecipient("age1yubikey1qt2r3tfk7wvlykudm7ew28dqqm3h8ln9zfsxsq4lcd2w8rh4n4hhz46ur24", nil)
|
|
require.NoError(t, err)
|
|
wrRec := &wrappedRecipient{
|
|
rec: pluginRec,
|
|
encoding: "age0yubikey1qt2r3tfk7wvlykudm7ew28dqqm3h8ln9zfsxsq4lcd2w8rh4n4hhz46ur24",
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
id age.Identity
|
|
want age.Recipient
|
|
}{
|
|
{
|
|
"native identity",
|
|
testID,
|
|
testID.Recipient(),
|
|
},
|
|
{
|
|
"wrapped native id",
|
|
&wrappedIdentity{
|
|
id: testID,
|
|
rec: testID.Recipient(),
|
|
encoding: testID.String(),
|
|
},
|
|
testID.Recipient(),
|
|
},
|
|
{
|
|
"wrapped plugin id",
|
|
&wrappedIdentity{
|
|
id: pluginID,
|
|
rec: wrRec,
|
|
encoding: "AGE-PLUGIN-YUBIKEY-1GKZKJQYZL98RLMC67F9PJ",
|
|
},
|
|
wrRec,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equalf(t, tt.want, IdentityToRecipient(tt.id), "IdentityToRecipient(%v)", tt.id)
|
|
// ensure recipient strings aren't equal identity strings
|
|
assert.NotEqual(t, fmt.Sprintf("%s", tt.id), fmt.Sprintf("%s", tt.want))
|
|
// ensure Parsing works on the String of the id:
|
|
_, err = parseIdentity(fmt.Sprintf("%s", tt.id))
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
}
|