Fix tests

This commit is contained in:
Jeff Mitchell
2018-07-12 10:18:50 -04:00
parent 0eebc77263
commit 5269abb64c
8 changed files with 40 additions and 21 deletions

View File

@@ -129,11 +129,7 @@ func (c *Logical) Write(path string, data map[string]interface{}) (*Secret, erro
return nil, err
}
if resp.StatusCode == 200 {
return ParseSecret(resp.Body)
}
return nil, nil
}
func (c *Logical) Delete(path string) (*Secret, error) {
@@ -159,11 +155,7 @@ func (c *Logical) Delete(path string) (*Secret, error) {
return nil, err
}
if resp.StatusCode == 200 {
return ParseSecret(resp.Body)
}
return nil, nil
}
func (c *Logical) Unwrap(wrappingToken string) (*Secret, error) {

View File

@@ -1,6 +1,7 @@
package api
import (
"bytes"
"fmt"
"io"
"time"
@@ -298,9 +299,20 @@ type SecretAuth struct {
// ParseSecret is used to parse a secret value from JSON from an io.Reader.
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{}
var secret Secret
if err := jsonutil.DecodeJSONFromReader(r, &secret); err != nil {
if err := jsonutil.DecodeJSONFromReader(&buf, &secret); err != nil {
return nil, err
}

View File

@@ -37,6 +37,12 @@ func TestLeaseRevokeCommand_Run(t *testing.T) {
{
"single",
nil,
"All revocation operations queued successfully",
0,
},
{
"single_sync",
[]string{"-sync"},
"Success",
0,
},
@@ -49,6 +55,12 @@ func TestLeaseRevokeCommand_Run(t *testing.T) {
{
"prefix",
[]string{"-prefix"},
"All revocation operations queued successfully",
0,
},
{
"prefix_sync",
[]string{"-prefix", "-sync"},
"Success",
0,
},

View File

@@ -147,12 +147,7 @@ func TestHandler_Accepted(t *testing.T) {
t.Fatalf("err: %s", err)
}
t.Logf("%#v", resp)
testResponseStatus(t, resp, 202)
if resp.Body != http.NoBody {
t.Fatal("got non-empty body")
}
}
// We use this test to verify header auth

View File

@@ -150,7 +150,10 @@ func RespondWithStatusCode(resp *Response, req *Request, code int) (*Response, e
if resp != nil {
httpResp := LogicalResponseToHTTPResponse(resp)
if req != nil {
httpResp.RequestID = req.ID
}
body, err := json.Marshal(httpResp)
if err != nil {

View File

@@ -684,7 +684,7 @@ func TestExpiration_RevokePrefix(t *testing.T) {
}
// 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)
}
@@ -1489,7 +1489,7 @@ func TestExpiration_revokeEntry_rejected(t *testing.T) {
t.Fatal(err)
}
err = exp.Revoke(le.LeaseID)
err = exp.LazyRevoke(le.LeaseID)
if err != nil {
t.Fatal(err)
}
@@ -1527,7 +1527,7 @@ func TestExpiration_revokeEntry_rejected(t *testing.T) {
t.Fatal(err)
}
if le != nil {
t.Fatal("ugh")
t.Fatal("lease entry not nil")
}
}

View File

@@ -666,6 +666,11 @@ func TestSystemBackend_InternalUIResultantACL(t *testing.T) {
"update",
},
},
"sys/control-group/request": map[string]interface{}{
"capabilities": []interface{}{
"update",
},
},
"sys/internal/ui/resultant-acl": map[string]interface{}{
"capabilities": []interface{}{
"read",

View File

@@ -4066,7 +4066,7 @@ func TestTokenStore_TidyLeaseRevocation(t *testing.T) {
}
// Call tidy
ts.handleTidy(context.Background(), nil, nil)
ts.handleTidy(context.Background(), &logical.Request{}, nil)
time.Sleep(200 * time.Millisecond)