2015-03-16 04:18:25 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2015-09-02 21:46:15 +00:00
|
|
|
"time"
|
2015-03-16 04:18:25 +00:00
|
|
|
|
|
|
|
"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
|
|
|
|
2015-08-22 00:36:19 +00:00
|
|
|
resp := testHttpGet(t, token, addr+"/v1/sys/mounts")
|
2015-03-16 04:18:25 +00:00
|
|
|
|
|
|
|
var actual map[string]interface{}
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"secret/": map[string]interface{}{
|
|
|
|
"description": "generic secret storage",
|
|
|
|
"type": "generic",
|
2015-08-31 18:27:49 +00:00
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
2015-03-16 04:18:25 +00:00
|
|
|
},
|
|
|
|
"sys/": map[string]interface{}{
|
|
|
|
"description": "system endpoints used for control, policy and debugging",
|
|
|
|
"type": "system",
|
2015-08-31 18:27:49 +00:00
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
2015-03-16 04:18:25 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
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-08-22 00:36:19 +00:00
|
|
|
resp := testHttpPost(t, token, addr+"/v1/sys/mounts/foo", map[string]interface{}{
|
2015-03-16 17:36:29 +00:00
|
|
|
"type": "generic",
|
|
|
|
"description": "foo",
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
2015-08-22 00:36:19 +00:00
|
|
|
resp = testHttpGet(t, token, addr+"/v1/sys/mounts")
|
2015-03-16 17:36:29 +00:00
|
|
|
|
|
|
|
var actual map[string]interface{}
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"foo/": map[string]interface{}{
|
|
|
|
"description": "foo",
|
|
|
|
"type": "generic",
|
2015-08-31 18:27:49 +00:00
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
2015-03-16 17:36:29 +00:00
|
|
|
},
|
|
|
|
"secret/": map[string]interface{}{
|
|
|
|
"description": "generic secret storage",
|
|
|
|
"type": "generic",
|
2015-08-31 18:27:49 +00:00
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
2015-03-16 17:36:29 +00:00
|
|
|
},
|
|
|
|
"sys/": map[string]interface{}{
|
|
|
|
"description": "system endpoints used for control, policy and debugging",
|
|
|
|
"type": "system",
|
2015-08-31 18:27:49 +00:00
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
2015-03-16 17:36:29 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 17:02:15 +00:00
|
|
|
func TestSysMount_put(t *testing.T) {
|
|
|
|
core, _, token := vault.TestCoreUnsealed(t)
|
|
|
|
ln, addr := TestServer(t, core)
|
|
|
|
defer ln.Close()
|
|
|
|
TestServerAuth(t, addr, token)
|
|
|
|
|
2015-08-22 00:36:19 +00:00
|
|
|
resp := testHttpPut(t, token, addr+"/v1/sys/mounts/foo", map[string]interface{}{
|
2015-06-16 17:02:15 +00:00
|
|
|
"type": "generic",
|
|
|
|
"description": "foo",
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
|
|
|
// The TestSysMount test tests the thing is actually created. See that test
|
|
|
|
// for more info.
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
2015-08-22 00:36:19 +00:00
|
|
|
resp := testHttpPost(t, token, addr+"/v1/sys/mounts/foo", map[string]interface{}{
|
2015-04-07 17:54:58 +00:00
|
|
|
"type": "generic",
|
|
|
|
"description": "foo",
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
2015-08-22 00:36:19 +00:00
|
|
|
resp = testHttpPost(t, token, addr+"/v1/sys/remount", map[string]interface{}{
|
2015-04-07 17:54:58 +00:00
|
|
|
"from": "foo",
|
|
|
|
"to": "bar",
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
2015-08-22 00:36:19 +00:00
|
|
|
resp = testHttpGet(t, token, addr+"/v1/sys/mounts")
|
2015-04-07 17:54:58 +00:00
|
|
|
|
|
|
|
var actual map[string]interface{}
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"bar/": map[string]interface{}{
|
|
|
|
"description": "foo",
|
|
|
|
"type": "generic",
|
2015-08-31 18:27:49 +00:00
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
2015-04-07 17:54:58 +00:00
|
|
|
},
|
|
|
|
"secret/": map[string]interface{}{
|
|
|
|
"description": "generic secret storage",
|
|
|
|
"type": "generic",
|
2015-08-31 18:27:49 +00:00
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
2015-04-07 17:54:58 +00:00
|
|
|
},
|
|
|
|
"sys/": map[string]interface{}{
|
|
|
|
"description": "system endpoints used for control, policy and debugging",
|
|
|
|
"type": "system",
|
2015-08-31 18:27:49 +00:00
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
2015-04-07 17:54:58 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
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-08-22 00:36:19 +00:00
|
|
|
resp := testHttpPost(t, token, 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-08-22 00:36:19 +00:00
|
|
|
resp = testHttpDelete(t, token, addr+"/v1/sys/mounts/foo")
|
2015-03-16 17:41:08 +00:00
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
2015-08-22 00:36:19 +00:00
|
|
|
resp = testHttpGet(t, token, addr+"/v1/sys/mounts")
|
2015-03-16 17:41:08 +00:00
|
|
|
|
|
|
|
var actual map[string]interface{}
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"secret/": map[string]interface{}{
|
|
|
|
"description": "generic secret storage",
|
|
|
|
"type": "generic",
|
2015-08-31 18:27:49 +00:00
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
2015-03-16 17:41:08 +00:00
|
|
|
},
|
|
|
|
"sys/": map[string]interface{}{
|
|
|
|
"description": "system endpoints used for control, policy and debugging",
|
|
|
|
"type": "system",
|
2015-08-31 18:27:49 +00:00
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
2015-03-16 17:41:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
testResponseStatus(t, resp, 200)
|
|
|
|
testResponseBody(t, resp, &actual)
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
2015-09-02 21:46:15 +00:00
|
|
|
|
|
|
|
func TestSysTuneMount(t *testing.T) {
|
|
|
|
core, _, token := vault.TestCoreUnsealed(t)
|
|
|
|
ln, addr := TestServer(t, core)
|
|
|
|
defer ln.Close()
|
|
|
|
TestServerAuth(t, addr, token)
|
|
|
|
|
|
|
|
resp := testHttpPost(t, token, addr+"/v1/sys/mounts/foo", map[string]interface{}{
|
|
|
|
"type": "generic",
|
|
|
|
"description": "foo",
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
|
|
|
resp = testHttpGet(t, token, addr+"/v1/sys/mounts")
|
|
|
|
|
|
|
|
var actual map[string]interface{}
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"foo/": map[string]interface{}{
|
|
|
|
"description": "foo",
|
|
|
|
"type": "generic",
|
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"secret/": map[string]interface{}{
|
|
|
|
"description": "generic secret storage",
|
|
|
|
"type": "generic",
|
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"sys/": map[string]interface{}{
|
|
|
|
"description": "system endpoints used for control, policy and debugging",
|
|
|
|
"type": "system",
|
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testResponseStatus(t, resp, 200)
|
|
|
|
testResponseBody(t, resp, &actual)
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shorter than system default
|
|
|
|
resp = testHttpPost(t, token, addr+"/v1/sys/mounts/foo/tune", map[string]interface{}{
|
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": time.Duration(time.Hour * 72),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
|
|
|
// Longer than system default
|
|
|
|
resp = testHttpPost(t, token, addr+"/v1/sys/mounts/foo/tune", map[string]interface{}{
|
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": time.Duration(time.Hour * 72000),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 400)
|
|
|
|
|
|
|
|
// Longer than system default
|
|
|
|
resp = testHttpPost(t, token, addr+"/v1/sys/mounts/foo/tune", map[string]interface{}{
|
|
|
|
"config": map[string]interface{}{
|
|
|
|
"max_lease_ttl": time.Duration(time.Hour * 72000),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
|
|
|
// Longer than backend max
|
|
|
|
resp = testHttpPost(t, token, addr+"/v1/sys/mounts/foo/tune", map[string]interface{}{
|
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": time.Duration(time.Hour * 72001),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 400)
|
|
|
|
|
|
|
|
// Shorter than backend max, longer than system max
|
|
|
|
resp = testHttpPost(t, token, addr+"/v1/sys/mounts/foo/tune", map[string]interface{}{
|
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": time.Duration(time.Hour * 71999),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
|
|
|
resp = testHttpGet(t, token, addr+"/v1/sys/mounts")
|
|
|
|
expected = map[string]interface{}{
|
|
|
|
"foo/": map[string]interface{}{
|
|
|
|
"description": "foo",
|
|
|
|
"type": "generic",
|
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(time.Duration(time.Hour * 71999)),
|
|
|
|
"max_lease_ttl": float64(time.Duration(time.Hour * 72000)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"secret/": map[string]interface{}{
|
|
|
|
"description": "generic secret storage",
|
|
|
|
"type": "generic",
|
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"sys/": map[string]interface{}{
|
|
|
|
"description": "system endpoints used for control, policy and debugging",
|
|
|
|
"type": "system",
|
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(0),
|
|
|
|
"max_lease_ttl": float64(0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-09-03 12:54:59 +00:00
|
|
|
|
2015-09-02 21:46:15 +00:00
|
|
|
testResponseStatus(t, resp, 200)
|
|
|
|
testResponseBody(t, resp, &actual)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad:\nExpected: %#v\nActual:%#v", expected, actual)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp = testHttpGet(t, token, addr+"/v1/sys/mounts/foo/tune")
|
2015-09-03 12:54:59 +00:00
|
|
|
actual = map[string]interface{}{}
|
2015-09-02 21:46:15 +00:00
|
|
|
expected = map[string]interface{}{
|
2015-09-03 12:54:59 +00:00
|
|
|
"config": map[string]interface{}{
|
|
|
|
"default_lease_ttl": float64(time.Duration(time.Hour * 71999)),
|
|
|
|
"max_lease_ttl": float64(time.Duration(time.Hour * 72000)),
|
2015-09-02 21:46:15 +00:00
|
|
|
},
|
|
|
|
}
|
2015-09-03 12:54:59 +00:00
|
|
|
|
2015-09-02 21:46:15 +00:00
|
|
|
testResponseStatus(t, resp, 200)
|
|
|
|
testResponseBody(t, resp, &actual)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad:\nExpected: %#v\nActual:%#v", expected, actual)
|
|
|
|
}
|
|
|
|
}
|