http: renew endpoints

This commit is contained in:
Mitchell Hashimoto
2015-04-13 17:21:31 -07:00
parent 0c8084c31f
commit 4ee0222411
5 changed files with 132 additions and 45 deletions

View File

@@ -1,11 +1,44 @@
package http
import (
"encoding/json"
"net/http"
"testing"
"github.com/hashicorp/vault/vault"
)
func TestSysRenew(t *testing.T) {
core, _, token := vault.TestCoreUnsealed(t)
ln, addr := TestServer(t, core)
defer ln.Close()
TestServerAuth(t, addr, token)
// write secret
resp := testHttpPut(t, addr+"/v1/secret/foo", map[string]interface{}{
"data": "bar",
"lease": "1h",
})
testResponseStatus(t, resp, 204)
// read secret
resp, err := http.Get(addr + "/v1/secret/foo")
if err != nil {
t.Fatalf("err: %s", err)
}
var result struct {
LeaseId string `json:"lease_id"`
}
dec := json.NewDecoder(resp.Body)
if err := dec.Decode(&result); err != nil {
t.Fatalf("bad: %s", err)
}
resp = testHttpPut(t, addr+"/v1/sys/renew/"+result.LeaseId, nil)
testResponseStatus(t, resp, 200)
}
func TestSysRevoke(t *testing.T) {
core, _, token := vault.TestCoreUnsealed(t)
ln, addr := TestServer(t, core)