The age, Vault and SOPS engines shelled out with stderr discarded, so a missing key and a broken setup both surfaced as 'exit status 1' and were reported as the engine being unavailable. age now decrypts with the age library and Vault reads over its API (KV v1 or v2, detected as the CLI does), so neither needs a CLI on the host. SOPS still uses the CLI, whose library would pull in every cloud KMS SDK, but decrypts the whole file to JSON and looks the key up itself, so the key never reaches the CLI.
29 lines
686 B
Go
29 lines
686 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archipelago/sdk/secretengine"
|
|
)
|
|
|
|
func TestLookup(t *testing.T) {
|
|
plain := []byte(`{"token":"s3cret","port":5432,"nested":{"a":1},"empty":"","nil":null}`)
|
|
for _, tc := range []struct {
|
|
key, want string
|
|
missing bool
|
|
}{
|
|
{key: "token", want: "s3cret"},
|
|
{key: "port", want: "5432"},
|
|
{key: "nested", want: `{"a":1}`},
|
|
{key: "empty", missing: true},
|
|
{key: "nil", missing: true},
|
|
{key: `"] --output x`, missing: true},
|
|
} {
|
|
got, err := lookup(plain, tc.key)
|
|
if tc.missing != errors.Is(err, secretengine.ErrNotFound) || got != tc.want {
|
|
t.Errorf("lookup(%q) = %q, %v", tc.key, got, err)
|
|
}
|
|
}
|
|
}
|