mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
[VAULT-2825] Fix erroneous 500 resp for field validation errors (#12042)
* [VAULT-2825] Correctly respond with 400 rather than 500 for field validation errors * [VAULT-2825] Add changelog entry * [VAULT-2825] Simplify test assertion
This commit is contained in:
@@ -267,7 +267,7 @@ func (b *Backend) HandleRequest(ctx context.Context, req *logical.Request) (*log
|
||||
if req.Operation != logical.HelpOperation {
|
||||
err := fd.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return logical.ErrorResponse(fmt.Sprintf("Field validation failed: %s", err.Error())), nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -240,14 +240,17 @@ func TestBackendHandleRequest_badwrite(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, err := b.HandleRequest(context.Background(), &logical.Request{
|
||||
resp, err := b.HandleRequest(context.Background(), &logical.Request{
|
||||
Operation: logical.UpdateOperation,
|
||||
Path: "foo/bar",
|
||||
Data: map[string]interface{}{"value": "3false3"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("should have thrown a conversion error")
|
||||
if !strings.Contains(resp.Data["error"].(string), "Field validation failed") {
|
||||
t.Fatalf("bad: %#v", resp)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user