command/write: can write arbitrary data from stdin

This commit is contained in:
Mitchell Hashimoto
2015-03-15 20:40:12 -07:00
parent 8093f94c65
commit f93f1198d5
2 changed files with 67 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package command
import (
"io"
"testing"
"github.com/hashicorp/vault/http"
@@ -43,3 +44,47 @@ func TestWrite(t *testing.T) {
t.Fatalf("bad: %#v", resp)
}
}
func TestWrite_arbitrary(t *testing.T) {
core, _ := vault.TestCoreUnsealed(t)
ln, addr := http.TestServer(t, core)
defer ln.Close()
stdinR, stdinW := io.Pipe()
ui := new(cli.MockUi)
c := &WriteCommand{
Meta: Meta{
Ui: ui,
},
testStdin: stdinR,
}
go func() {
stdinW.Write([]byte(`{"foo":"bar"}`))
stdinW.Close()
}()
args := []string{
"-address", addr,
"secret/foo",
"-",
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
client, err := c.Client()
if err != nil {
t.Fatalf("err: %s", err)
}
resp, err := client.Logical().Read("secret/foo")
if err != nil {
t.Fatalf("err: %s", err)
}
if resp.Data["foo"] != "bar" {
t.Fatalf("bad: %#v", resp)
}
}