open-vault/http/sys_mount_test.go

161 lines
3.9 KiB
Go
Raw Normal View History

2015-03-16 04:18:25 +00:00
package http
import (
"net/http"
"reflect"
"testing"
"github.com/hashicorp/vault/vault"
)
func TestSysMounts(t *testing.T) {
2015-03-29 23:14:54 +00:00
core, _, token := vault.TestCoreUnsealed(t)
2015-03-16 04:18:25 +00:00
ln, addr := TestServer(t, core)
defer ln.Close()
2015-03-29 23:14:54 +00:00
TestServerAuth(t, addr, token)
2015-03-16 04:18:25 +00:00
resp, err := http.Get(addr + "/v1/sys/mounts")
if err != nil {
t.Fatalf("err: %s", err)
}
var actual map[string]interface{}
expected := map[string]interface{}{
"secret/": map[string]interface{}{
"description": "generic secret storage",
"type": "generic",
},
"sys/": map[string]interface{}{
"description": "system endpoints used for control, policy and debugging",
"type": "system",
},
}
testResponseStatus(t, resp, 200)
testResponseBody(t, resp, &actual)
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}
2015-03-16 17:36:29 +00:00
func TestSysMount(t *testing.T) {
2015-03-29 23:14:54 +00:00
core, _, token := vault.TestCoreUnsealed(t)
2015-03-16 17:36:29 +00:00
ln, addr := TestServer(t, core)
defer ln.Close()
2015-03-29 23:14:54 +00:00
TestServerAuth(t, addr, token)
2015-03-16 17:36:29 +00:00
2015-03-16 17:51:13 +00:00
resp := testHttpPost(t, addr+"/v1/sys/mounts/foo", map[string]interface{}{
2015-03-16 17:36:29 +00:00
"type": "generic",
"description": "foo",
})
testResponseStatus(t, resp, 204)
resp, err := http.Get(addr + "/v1/sys/mounts")
if err != nil {
t.Fatalf("err: %s", err)
}
var actual map[string]interface{}
expected := map[string]interface{}{
"foo/": map[string]interface{}{
"description": "foo",
"type": "generic",
},
"secret/": map[string]interface{}{
"description": "generic secret storage",
"type": "generic",
},
"sys/": map[string]interface{}{
"description": "system endpoints used for control, policy and debugging",
"type": "system",
},
}
testResponseStatus(t, resp, 200)
testResponseBody(t, resp, &actual)
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
2015-04-07 17:54:58 +00:00
}
}
func TestSysRemount(t *testing.T) {
core, _, token := vault.TestCoreUnsealed(t)
ln, addr := TestServer(t, core)
defer ln.Close()
TestServerAuth(t, addr, token)
resp := testHttpPost(t, addr+"/v1/sys/mounts/foo", map[string]interface{}{
"type": "generic",
"description": "foo",
})
testResponseStatus(t, resp, 204)
resp = testHttpPost(t, addr+"/v1/sys/remount", map[string]interface{}{
"from": "foo",
"to": "bar",
})
testResponseStatus(t, resp, 204)
resp, err := http.Get(addr + "/v1/sys/mounts")
if err != nil {
t.Fatalf("err: %s", err)
}
var actual map[string]interface{}
expected := map[string]interface{}{
"bar/": map[string]interface{}{
"description": "foo",
"type": "generic",
},
"secret/": map[string]interface{}{
"description": "generic secret storage",
"type": "generic",
},
"sys/": map[string]interface{}{
"description": "system endpoints used for control, policy and debugging",
"type": "system",
},
}
testResponseStatus(t, resp, 200)
testResponseBody(t, resp, &actual)
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
2015-03-16 17:36:29 +00:00
}
}
2015-03-16 17:41:08 +00:00
func TestSysUnmount(t *testing.T) {
2015-03-29 23:14:54 +00:00
core, _, token := vault.TestCoreUnsealed(t)
2015-03-16 17:41:08 +00:00
ln, addr := TestServer(t, core)
defer ln.Close()
2015-03-29 23:14:54 +00:00
TestServerAuth(t, addr, token)
2015-03-16 17:41:08 +00:00
2015-03-16 17:51:13 +00:00
resp := testHttpPost(t, addr+"/v1/sys/mounts/foo", map[string]interface{}{
2015-03-16 17:41:08 +00:00
"type": "generic",
"description": "foo",
})
testResponseStatus(t, resp, 204)
2015-03-16 17:51:13 +00:00
resp = testHttpDelete(t, addr+"/v1/sys/mounts/foo")
2015-03-16 17:41:08 +00:00
testResponseStatus(t, resp, 204)
resp, err := http.Get(addr + "/v1/sys/mounts")
if err != nil {
t.Fatalf("err: %s", err)
}
var actual map[string]interface{}
expected := map[string]interface{}{
"secret/": map[string]interface{}{
"description": "generic secret storage",
"type": "generic",
},
"sys/": map[string]interface{}{
"description": "system endpoints used for control, policy and debugging",
"type": "system",
},
}
testResponseStatus(t, resp, 200)
testResponseBody(t, resp, &actual)
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}