2015-05-28 21:28:50 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"net/http"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/vault"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSysRekeyInit_Status(t *testing.T) {
|
|
|
|
core, _, token := vault.TestCoreUnsealed(t)
|
|
|
|
ln, addr := TestServer(t, core)
|
|
|
|
defer ln.Close()
|
|
|
|
TestServerAuth(t, addr, token)
|
|
|
|
|
|
|
|
resp, err := http.Get(addr + "/v1/sys/rekey/init")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var actual map[string]interface{}
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"started": false,
|
|
|
|
"t": float64(0),
|
|
|
|
"n": float64(0),
|
|
|
|
"progress": float64(0),
|
|
|
|
"required": float64(1),
|
|
|
|
}
|
|
|
|
testResponseStatus(t, resp, 200)
|
|
|
|
testResponseBody(t, resp, &actual)
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSysRekeyInit_Setup(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/rekey/init", map[string]interface{}{
|
2015-05-28 21:28:50 +00:00
|
|
|
"secret_shares": 5,
|
|
|
|
"secret_threshold": 3,
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
2015-08-22 00:36:19 +00:00
|
|
|
resp = testHttpGet(t, token, addr+"/v1/sys/rekey/init")
|
2015-05-28 21:28:50 +00:00
|
|
|
|
|
|
|
var actual map[string]interface{}
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"started": true,
|
|
|
|
"t": float64(3),
|
|
|
|
"n": float64(5),
|
|
|
|
"progress": float64(0),
|
|
|
|
"required": float64(1),
|
|
|
|
}
|
|
|
|
testResponseStatus(t, resp, 200)
|
|
|
|
testResponseBody(t, resp, &actual)
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSysRekeyInit_Cancel(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/rekey/init", map[string]interface{}{
|
2015-05-28 21:28:50 +00:00
|
|
|
"secret_shares": 5,
|
|
|
|
"secret_threshold": 3,
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
2015-08-22 00:36:19 +00:00
|
|
|
resp = testHttpDelete(t, token, addr+"/v1/sys/rekey/init")
|
2015-05-28 21:28:50 +00:00
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
|
|
|
resp, err := http.Get(addr + "/v1/sys/rekey/init")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var actual map[string]interface{}
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"started": false,
|
|
|
|
"t": float64(0),
|
|
|
|
"n": float64(0),
|
|
|
|
"progress": float64(0),
|
|
|
|
"required": float64(1),
|
|
|
|
}
|
|
|
|
testResponseStatus(t, resp, 200)
|
|
|
|
testResponseBody(t, resp, &actual)
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSysRekey_badKey(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/rekey/update", map[string]interface{}{
|
2015-05-28 21:28:50 +00:00
|
|
|
"key": "0123",
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 400)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSysRekey_Update(t *testing.T) {
|
|
|
|
core, master, 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/rekey/init", map[string]interface{}{
|
2015-05-28 21:28:50 +00:00
|
|
|
"secret_shares": 5,
|
|
|
|
"secret_threshold": 3,
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
2015-08-22 00:36:19 +00:00
|
|
|
resp = testHttpPut(t, token, addr+"/v1/sys/rekey/update", map[string]interface{}{
|
2015-05-28 21:28:50 +00:00
|
|
|
"key": hex.EncodeToString(master),
|
|
|
|
})
|
|
|
|
|
|
|
|
var actual map[string]interface{}
|
|
|
|
expected := map[string]interface{}{
|
|
|
|
"complete": true,
|
|
|
|
}
|
|
|
|
testResponseStatus(t, resp, 200)
|
|
|
|
testResponseBody(t, resp, &actual)
|
|
|
|
|
|
|
|
keys := actual["keys"].([]interface{})
|
|
|
|
if len(keys) != 5 {
|
|
|
|
t.Fatalf("bad: %#v", keys)
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(actual, "keys")
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|