2015-04-01 02:21:02 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/jsonutil"
|
2015-04-01 02:21:02 +00:00
|
|
|
"github.com/hashicorp/vault/vault"
|
|
|
|
)
|
|
|
|
|
2015-04-14 00:21:31 +00:00
|
|
|
func TestSysRenew(t *testing.T) {
|
|
|
|
core, _, token := vault.TestCoreUnsealed(t)
|
|
|
|
ln, addr := TestServer(t, core)
|
|
|
|
defer ln.Close()
|
|
|
|
TestServerAuth(t, addr, token)
|
|
|
|
|
|
|
|
// write secret
|
2015-08-22 00:36:19 +00:00
|
|
|
resp := testHttpPut(t, token, addr+"/v1/secret/foo", map[string]interface{}{
|
2015-04-14 00:21:31 +00:00
|
|
|
"data": "bar",
|
|
|
|
"lease": "1h",
|
|
|
|
})
|
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
|
|
|
|
// read secret
|
2015-08-22 00:36:19 +00:00
|
|
|
resp = testHttpGet(t, token, addr+"/v1/secret/foo")
|
2015-04-14 00:21:31 +00:00
|
|
|
var result struct {
|
2017-06-20 16:34:00 +00:00
|
|
|
LeaseID string `json:"lease_id"`
|
2015-04-14 00:21:31 +00:00
|
|
|
}
|
2016-07-06 16:25:40 +00:00
|
|
|
if err := jsonutil.DecodeJSONFromReader(resp.Body, &result); err != nil {
|
2015-04-14 00:21:31 +00:00
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
|
|
|
|
2017-06-20 16:34:00 +00:00
|
|
|
var renewResult struct {
|
|
|
|
LeaseID string `json:"lease_id"`
|
|
|
|
Data map[string]interface{} `json:"data"`
|
|
|
|
}
|
|
|
|
resp = testHttpPut(t, token, addr+"/v1/sys/renew/"+result.LeaseID, nil)
|
2015-04-14 00:21:31 +00:00
|
|
|
testResponseStatus(t, resp, 200)
|
2017-06-20 16:34:00 +00:00
|
|
|
if err := jsonutil.DecodeJSONFromReader(resp.Body, &renewResult); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if result.LeaseID != renewResult.LeaseID {
|
|
|
|
t.Fatal("lease id changed in renew request")
|
|
|
|
}
|
|
|
|
|
|
|
|
resp = testHttpPut(t, token, addr+"/v1/sys/leases/renew/"+result.LeaseID, nil)
|
|
|
|
testResponseStatus(t, resp, 200)
|
|
|
|
if err := jsonutil.DecodeJSONFromReader(resp.Body, &renewResult); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if result.LeaseID != renewResult.LeaseID {
|
|
|
|
t.Fatal("lease id changed in renew request")
|
|
|
|
}
|
2015-04-14 00:21:31 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 02:21:02 +00:00
|
|
|
func TestSysRevoke(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/revoke/secret/foo/1234", nil)
|
2015-04-01 02:21:02 +00:00
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
}
|
2015-04-01 02:23:32 +00:00
|
|
|
|
|
|
|
func TestSysRevokePrefix(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/revoke-prefix/secret/foo/1234", nil)
|
2015-04-01 02:23:32 +00:00
|
|
|
testResponseStatus(t, resp, 204)
|
|
|
|
}
|