mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 11:08:10 +00:00
Fix tests
This commit is contained in:
@@ -129,11 +129,7 @@ func (c *Logical) Write(path string, data map[string]interface{}) (*Secret, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode == 200 {
|
|
||||||
return ParseSecret(resp.Body)
|
return ParseSecret(resp.Body)
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Logical) Delete(path string) (*Secret, error) {
|
func (c *Logical) Delete(path string) (*Secret, error) {
|
||||||
@@ -159,11 +155,7 @@ func (c *Logical) Delete(path string) (*Secret, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode == 200 {
|
|
||||||
return ParseSecret(resp.Body)
|
return ParseSecret(resp.Body)
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Logical) Unwrap(wrappingToken string) (*Secret, error) {
|
func (c *Logical) Unwrap(wrappingToken string) (*Secret, error) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
@@ -298,9 +299,20 @@ type SecretAuth struct {
|
|||||||
|
|
||||||
// ParseSecret is used to parse a secret value from JSON from an io.Reader.
|
// ParseSecret is used to parse a secret value from JSON from an io.Reader.
|
||||||
func ParseSecret(r io.Reader) (*Secret, error) {
|
func ParseSecret(r io.Reader) (*Secret, error) {
|
||||||
|
// First read the data into a buffer. Not super efficient but we want to
|
||||||
|
// know if we actually have a body or not.
|
||||||
|
var buf bytes.Buffer
|
||||||
|
_, err := buf.ReadFrom(r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if buf.Len() == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
// First decode the JSON into a map[string]interface{}
|
// First decode the JSON into a map[string]interface{}
|
||||||
var secret Secret
|
var secret Secret
|
||||||
if err := jsonutil.DecodeJSONFromReader(r, &secret); err != nil {
|
if err := jsonutil.DecodeJSONFromReader(&buf, &secret); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,12 @@ func TestLeaseRevokeCommand_Run(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"single",
|
"single",
|
||||||
nil,
|
nil,
|
||||||
|
"All revocation operations queued successfully",
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"single_sync",
|
||||||
|
[]string{"-sync"},
|
||||||
"Success",
|
"Success",
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
@@ -49,6 +55,12 @@ func TestLeaseRevokeCommand_Run(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"prefix",
|
"prefix",
|
||||||
[]string{"-prefix"},
|
[]string{"-prefix"},
|
||||||
|
"All revocation operations queued successfully",
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prefix_sync",
|
||||||
|
[]string{"-prefix", "-sync"},
|
||||||
"Success",
|
"Success",
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -147,12 +147,7 @@ func TestHandler_Accepted(t *testing.T) {
|
|||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("%#v", resp)
|
|
||||||
|
|
||||||
testResponseStatus(t, resp, 202)
|
testResponseStatus(t, resp, 202)
|
||||||
if resp.Body != http.NoBody {
|
|
||||||
t.Fatal("got non-empty body")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use this test to verify header auth
|
// We use this test to verify header auth
|
||||||
|
|||||||
@@ -150,7 +150,10 @@ func RespondWithStatusCode(resp *Response, req *Request, code int) (*Response, e
|
|||||||
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpResp := LogicalResponseToHTTPResponse(resp)
|
httpResp := LogicalResponseToHTTPResponse(resp)
|
||||||
|
|
||||||
|
if req != nil {
|
||||||
httpResp.RequestID = req.ID
|
httpResp.RequestID = req.ID
|
||||||
|
}
|
||||||
|
|
||||||
body, err := json.Marshal(httpResp)
|
body, err := json.Marshal(httpResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -684,7 +684,7 @@ func TestExpiration_RevokePrefix(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should nuke all the keys
|
// Should nuke all the keys
|
||||||
if err := exp.RevokePrefix("prod/aws/"); err != nil {
|
if err := exp.RevokePrefix("prod/aws/", true); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1489,7 +1489,7 @@ func TestExpiration_revokeEntry_rejected(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = exp.Revoke(le.LeaseID)
|
err = exp.LazyRevoke(le.LeaseID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -1527,7 +1527,7 @@ func TestExpiration_revokeEntry_rejected(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if le != nil {
|
if le != nil {
|
||||||
t.Fatal("ugh")
|
t.Fatal("lease entry not nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -666,6 +666,11 @@ func TestSystemBackend_InternalUIResultantACL(t *testing.T) {
|
|||||||
"update",
|
"update",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"sys/control-group/request": map[string]interface{}{
|
||||||
|
"capabilities": []interface{}{
|
||||||
|
"update",
|
||||||
|
},
|
||||||
|
},
|
||||||
"sys/internal/ui/resultant-acl": map[string]interface{}{
|
"sys/internal/ui/resultant-acl": map[string]interface{}{
|
||||||
"capabilities": []interface{}{
|
"capabilities": []interface{}{
|
||||||
"read",
|
"read",
|
||||||
|
|||||||
@@ -4066,7 +4066,7 @@ func TestTokenStore_TidyLeaseRevocation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call tidy
|
// Call tidy
|
||||||
ts.handleTidy(context.Background(), nil, nil)
|
ts.handleTidy(context.Background(), &logical.Request{}, nil)
|
||||||
|
|
||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(200 * time.Millisecond)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user