etcdhttp: disallow empty prevValue fields

release-2.0
Jonathan Boulle 2014-09-24 15:21:18 -07:00
parent a45d490598
commit 2e2cd12407
2 changed files with 14 additions and 1 deletions

View File

@ -218,6 +218,14 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) {
)
}
pV := r.FormValue("prevValue")
if _, ok := r.Form["prevValue"]; ok && pV == "" {
return emptyReq, etcdErr.NewRequestError(
etcdErr.EcodeInvalidField,
`"prevValue" cannot be empty`,
)
}
// prevExist is nullable, so leave it null if not specified
var pe *bool
if _, ok := r.Form["prevExist"]; ok {
@ -236,7 +244,7 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) {
Method: r.Method,
Path: p,
Val: r.FormValue("value"),
PrevValue: r.FormValue("prevValue"),
PrevValue: pV,
PrevIndex: pIdx,
PrevExist: pe,
Recursive: rec,

View File

@ -147,6 +147,11 @@ func TestBadParseRequest(t *testing.T) {
mustNewForm(t, "foo", url.Values{"stream": []string{"something"}}),
etcdErr.EcodeInvalidField,
},
// prevValue cannot be empty
{
mustNewForm(t, "foo", url.Values{"prevValue": []string{""}}),
etcdErr.EcodeInvalidField,
},
// wait is only valid with GET requests
{
mustNewMethodRequest(t, "HEAD", "foo?wait=true"),