open-vault/command/policy_delete_test.go

62 lines
1.1 KiB
Go
Raw Normal View History

2015-04-19 23:36:11 +00:00
package command
import (
"testing"
"github.com/hashicorp/vault/http"
2016-04-01 17:16:05 +00:00
"github.com/hashicorp/vault/meta"
2015-04-19 23:36:11 +00:00
"github.com/hashicorp/vault/vault"
"github.com/mitchellh/cli"
)
func TestPolicyDelete(t *testing.T) {
core, _, token := vault.TestCoreUnsealed(t)
ln, addr := http.TestServer(t, core)
defer ln.Close()
ui := new(cli.MockUi)
c := &PolicyDeleteCommand{
2016-04-01 17:16:05 +00:00
Meta: meta.Meta{
2015-04-19 23:36:11 +00:00
ClientToken: token,
Ui: ui,
},
}
args := []string{
"-address", addr,
"foo",
}
// Run once so the client is setup, ignore errors
c.Run(args)
// Get the client so we can write data
client, err := c.Client()
if err != nil {
t.Fatalf("err: %s", err)
}
if err := client.Sys().PutPolicy("foo", testPolicyDeleteRules); err != nil {
t.Fatalf("err: %s", err)
}
// Test that the delete works
if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
// Test the policy is gone
rules, err := client.Sys().GetPolicy("foo")
if err != nil {
t.Fatalf("err: %s", err)
}
if rules != "" {
t.Fatalf("bad: %#v", rules)
}
}
const testPolicyDeleteRules = `
path "sys" {
policy = "deny"
}
`