mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 18:17:55 +00:00
Add response wrapping to list operations (#1814)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/vault/http"
|
||||
@@ -40,6 +41,9 @@ func TestUnwrap(t *testing.T) {
|
||||
if method == "GET" && path == "secret/foo" {
|
||||
return "60s"
|
||||
}
|
||||
if method == "LIST" && path == "secret" {
|
||||
return "60s"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
client.SetWrappingLookupFunc(wrapLookupFunc)
|
||||
@@ -71,4 +75,33 @@ func TestUnwrap(t *testing.T) {
|
||||
if output != "zap\n" {
|
||||
t.Fatalf("unexpectd output:\n%s", output)
|
||||
}
|
||||
|
||||
// Now test with list handling, specifically that it will be called with
|
||||
// the list output formatter
|
||||
ui.OutputWriter.Reset()
|
||||
|
||||
outer, err = client.Logical().List("secret")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if outer == nil {
|
||||
t.Fatal("outer response was nil")
|
||||
}
|
||||
if outer.WrapInfo == nil {
|
||||
t.Fatal("outer wrapinfo was nil, response was %#v", *outer)
|
||||
}
|
||||
|
||||
args = []string{
|
||||
"-address", addr,
|
||||
outer.WrapInfo.Token,
|
||||
}
|
||||
// Run the read
|
||||
if code := c.Run(args); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
output = ui.OutputWriter.String()
|
||||
if strings.TrimSpace(output) != "Keys\n----\nfoo" {
|
||||
t.Fatalf("unexpected output:\n%s", output)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user