mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Properly parse order direction (#2812)
This commit is contained in:
parent
7a22e71c69
commit
586c2f9ead
2 changed files with 23 additions and 1 deletions
|
|
@ -171,6 +171,28 @@ func makeDecoder(iface interface{}) kithttp.DecodeRequestFunc {
|
||||||
field.SetUint(uint64(queryValUint))
|
field.SetUint(uint64(queryValUint))
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
field.SetBool(queryVal == "1" || queryVal == "true")
|
field.SetBool(queryVal == "1" || queryVal == "true")
|
||||||
|
case reflect.Int:
|
||||||
|
queryValInt := 0
|
||||||
|
switch queryTagValue {
|
||||||
|
case "order_direction":
|
||||||
|
switch queryVal {
|
||||||
|
case "desc":
|
||||||
|
queryValInt = int(fleet.OrderDescending)
|
||||||
|
case "asc":
|
||||||
|
queryValInt = int(fleet.OrderAscending)
|
||||||
|
case "":
|
||||||
|
queryValInt = int(fleet.OrderAscending)
|
||||||
|
default:
|
||||||
|
return fleet.ListOptions{},
|
||||||
|
errors.New("unknown order_direction: " + queryVal)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
queryValInt, err = strconv.Atoi(queryVal)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "parsing uint from query")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
field.SetInt(int64(queryValInt))
|
||||||
default:
|
default:
|
||||||
return nil, errors.Errorf("Cant handle type for field %s %s", f.Name, field.Kind())
|
return nil, errors.Errorf("Cant handle type for field %s %s", f.Name, field.Kind())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -333,7 +333,7 @@ func (s *integrationTestSuite) TestVulnerableSoftware() {
|
||||||
|
|
||||||
lsReq := listSoftwareRequest{}
|
lsReq := listSoftwareRequest{}
|
||||||
lsResp := listSoftwareResponse{}
|
lsResp := listSoftwareResponse{}
|
||||||
s.DoJSON("GET", "/api/v1/fleet/software", lsReq, http.StatusOK, &lsResp, "vulnerable", "true")
|
s.DoJSON("GET", "/api/v1/fleet/software", lsReq, http.StatusOK, &lsResp, "vulnerable", "true", "order_key", "generated_cpe", "order_direction", "desc")
|
||||||
assert.Len(t, lsResp.Software, 1)
|
assert.Len(t, lsResp.Software, 1)
|
||||||
assert.Equal(t, soft1.ID, lsResp.Software[0].ID)
|
assert.Equal(t, soft1.ID, lsResp.Software[0].ID)
|
||||||
assert.Len(t, lsResp.Software[0].Vulnerabilities, 1)
|
assert.Len(t, lsResp.Software[0].Vulnerabilities, 1)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue