vault: Test renew of bad ID

This commit is contained in:
Armon Dadgar 2015-03-16 16:14:53 -07:00
parent e52f1ee960
commit 57b4f970d2
2 changed files with 19 additions and 1 deletions

View File

@ -203,7 +203,11 @@ func (b *SystemBackend) handleRenew(
increment := time.Duration(incrementRaw) * time.Second
// Invoke the expiration manager directly
return b.Core.expiration.Renew(vaultID, increment)
resp, err := b.Core.expiration.Renew(vaultID, increment)
if err != nil {
return logical.ErrorResponse(err.Error()), logical.ErrInvalidRequest
}
return resp, err
}
// sysHelp is all the help text for the sys backend.

View File

@ -184,6 +184,20 @@ func TestSystemBackend_renew(t *testing.T) {
}
}
func TestSystemBackend_renew_invalidID(t *testing.T) {
b := testSystemBackend(t)
// Attempt renew
req := logical.TestRequest(t, logical.WriteOperation, "renew/foobarbaz")
resp, err := b.HandleRequest(req)
if err != logical.ErrInvalidRequest {
t.Fatalf("err: %v", err)
}
if resp.Data["error"] != "lease not found" {
t.Fatalf("bad: %v", resp)
}
}
func testSystemBackend(t *testing.T) logical.Backend {
c, _ := TestCoreUnsealed(t)
return NewSystemBackend(c)