mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
fix: email searching when filtering by labels (#15774)
# Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/` or `orbit/changes/`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] Added/updated tests - [x] Manual QA for all new/changed functionality
This commit is contained in:
parent
50550092c3
commit
b348399f7e
3 changed files with 16 additions and 1 deletions
1
changes/15525-email-search
Normal file
1
changes/15525-email-search
Normal file
|
|
@ -0,0 +1 @@
|
|||
- Fixes bug where searching hosts by email when filtering by a label returned no results.
|
||||
|
|
@ -596,7 +596,7 @@ func (ds *Datastore) applyHostLabelFilters(ctx context.Context, filter fleet.Tea
|
|||
query, params = ds.filterHostsByOSSettingsDiskEncryptionStatus(query, opt, params, enableDiskEncryption)
|
||||
}
|
||||
// TODO: should search columns include display_name (requires join to host_display_names)?
|
||||
query, params = searchLike(query, params, opt.MatchQuery, hostSearchColumns...)
|
||||
query, params, _ = hostSearchLike(query, params, opt.MatchQuery, hostSearchColumns...)
|
||||
|
||||
query, params = appendListOptionsWithCursorToSQL(query, params, &opt.ListOptions)
|
||||
return query, params, nil
|
||||
|
|
|
|||
|
|
@ -3604,6 +3604,20 @@ func (s *integrationTestSuite) TestLabels() {
|
|||
assert.Equal(t, hosts[len(hosts)-1].ID, listHostsResp.Hosts[0].ID)
|
||||
assert.Equal(t, hosts[0].ID, listHostsResp.Hosts[len(hosts)-1].ID)
|
||||
|
||||
mysql.ExecAdhocSQL(t, s.ds, func(db sqlx.ExtContext) error {
|
||||
_, err := db.ExecContext(
|
||||
context.Background(),
|
||||
`INSERT INTO host_emails (host_id, email, source) VALUES (?, ?, ?)`,
|
||||
hosts[0].ID, "a@b.c", "src1")
|
||||
|
||||
return err
|
||||
})
|
||||
|
||||
// list hosts in label searching by email address
|
||||
s.DoJSON("GET", fmt.Sprintf("/api/latest/fleet/labels/%d/hosts", lbl2.ID), nil, http.StatusOK, &listHostsResp, "query", "a@b.c")
|
||||
assert.Len(t, listHostsResp.Hosts, 1)
|
||||
assert.Equal(t, hosts[0].ID, listHostsResp.Hosts[0].ID)
|
||||
|
||||
// count hosts in label order by display_name
|
||||
var countResp countHostsResponse
|
||||
s.DoJSON("GET", "/api/latest/fleet/hosts/count", nil, http.StatusOK, &countResp, "label_id", fmt.Sprint(lbl2.ID), "order_key", "display_name", "order_direction", "desc")
|
||||
|
|
|
|||
Loading…
Reference in a new issue