2016-12-13 22:22:05 +00:00
|
|
|
package test
|
2016-12-06 18:22:28 +00:00
|
|
|
|
|
|
|
|
import (
|
2021-09-14 12:11:07 +00:00
|
|
|
"context"
|
2016-12-06 18:22:28 +00:00
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
2021-08-20 15:27:41 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server"
|
|
|
|
|
|
2021-06-26 04:46:51 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
2021-11-17 22:03:30 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/ptr"
|
2016-12-06 18:22:28 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
2023-07-25 00:17:20 +00:00
|
|
|
func NewQueryWithSchedule(t *testing.T, ds fleet.Datastore, teamID *uint, name, q string, authorID uint, saved bool, interval uint, automationsEnabled bool) *fleet.Query {
|
2021-05-07 04:05:09 +00:00
|
|
|
authorPtr := &authorID
|
|
|
|
|
if authorID == 0 {
|
|
|
|
|
authorPtr = nil
|
|
|
|
|
}
|
2021-09-14 12:11:07 +00:00
|
|
|
query, err := ds.NewQuery(context.Background(), &fleet.Query{
|
2023-07-25 00:17:20 +00:00
|
|
|
Name: name,
|
|
|
|
|
Query: q,
|
|
|
|
|
AuthorID: authorPtr,
|
|
|
|
|
Saved: saved,
|
|
|
|
|
TeamID: teamID,
|
|
|
|
|
Interval: interval,
|
|
|
|
|
AutomationsEnabled: automationsEnabled,
|
2023-10-16 22:33:39 +00:00
|
|
|
Logging: fleet.LoggingSnapshot,
|
2016-12-06 18:22:28 +00:00
|
|
|
})
|
2021-09-07 16:48:04 +00:00
|
|
|
require.NoError(t, err)
|
2016-12-06 18:22:28 +00:00
|
|
|
|
|
|
|
|
// Loading gives us the timestamps
|
2021-09-14 12:11:07 +00:00
|
|
|
query, err = ds.Query(context.Background(), query.ID)
|
2021-09-07 16:48:04 +00:00
|
|
|
require.NoError(t, err)
|
2016-12-06 18:22:28 +00:00
|
|
|
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 00:17:20 +00:00
|
|
|
func NewQuery(t *testing.T, ds fleet.Datastore, teamID *uint, name, q string, authorID uint, saved bool) *fleet.Query {
|
|
|
|
|
return NewQueryWithSchedule(t, ds, teamID, name, q, authorID, saved, 0, false)
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
func NewPack(t *testing.T, ds fleet.Datastore, name string) *fleet.Pack {
|
2021-09-14 12:11:07 +00:00
|
|
|
err := ds.ApplyPackSpecs(context.Background(), []*fleet.PackSpec{{Name: name}})
|
2016-12-06 18:22:28 +00:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
// Loading gives us the timestamps
|
2021-09-14 12:11:07 +00:00
|
|
|
pack, ok, err := ds.PackByName(context.Background(), name)
|
2018-01-10 19:38:20 +00:00
|
|
|
require.True(t, ok)
|
2021-09-07 16:48:04 +00:00
|
|
|
require.NoError(t, err)
|
2016-12-06 18:22:28 +00:00
|
|
|
|
|
|
|
|
return pack
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
func NewCampaign(t *testing.T, ds fleet.Datastore, queryID uint, status fleet.DistributedQueryStatus, now time.Time) *fleet.DistributedQueryCampaign {
|
2021-09-14 12:11:07 +00:00
|
|
|
campaign, err := ds.NewDistributedQueryCampaign(context.Background(), &fleet.DistributedQueryCampaign{
|
2021-06-06 22:07:29 +00:00
|
|
|
UpdateCreateTimestamps: fleet.UpdateCreateTimestamps{
|
|
|
|
|
CreateTimestamp: fleet.CreateTimestamp{
|
2016-12-06 18:22:28 +00:00
|
|
|
CreatedAt: now,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
QueryID: queryID,
|
|
|
|
|
Status: status,
|
|
|
|
|
})
|
2021-09-07 16:48:04 +00:00
|
|
|
require.NoError(t, err)
|
2016-12-06 18:22:28 +00:00
|
|
|
|
|
|
|
|
// Loading gives us the timestamps
|
2021-09-14 12:11:07 +00:00
|
|
|
campaign, err = ds.DistributedQueryCampaign(context.Background(), campaign.ID)
|
2021-09-07 16:48:04 +00:00
|
|
|
require.NoError(t, err)
|
2016-12-06 18:22:28 +00:00
|
|
|
|
|
|
|
|
return campaign
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
func AddHostToCampaign(t *testing.T, ds fleet.Datastore, campaignID, hostID uint) {
|
2016-12-06 18:22:28 +00:00
|
|
|
_, err := ds.NewDistributedQueryCampaignTarget(
|
2021-09-14 12:11:07 +00:00
|
|
|
context.Background(),
|
2021-06-06 22:07:29 +00:00
|
|
|
&fleet.DistributedQueryCampaignTarget{
|
|
|
|
|
Type: fleet.TargetHost,
|
2016-12-06 18:22:28 +00:00
|
|
|
TargetID: hostID,
|
|
|
|
|
DistributedQueryCampaignID: campaignID,
|
|
|
|
|
})
|
2021-09-07 16:48:04 +00:00
|
|
|
require.NoError(t, err)
|
2016-12-06 18:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
func AddLabelToCampaign(t *testing.T, ds fleet.Datastore, campaignID, labelID uint) {
|
2016-12-06 18:22:28 +00:00
|
|
|
_, err := ds.NewDistributedQueryCampaignTarget(
|
2021-09-14 12:11:07 +00:00
|
|
|
context.Background(),
|
2021-06-06 22:07:29 +00:00
|
|
|
&fleet.DistributedQueryCampaignTarget{
|
|
|
|
|
Type: fleet.TargetLabel,
|
2016-12-06 18:22:28 +00:00
|
|
|
TargetID: labelID,
|
|
|
|
|
DistributedQueryCampaignID: campaignID,
|
|
|
|
|
})
|
2021-09-07 16:48:04 +00:00
|
|
|
require.NoError(t, err)
|
2016-12-06 18:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
func AddAllHostsLabel(t *testing.T, ds fleet.Datastore) {
|
2020-04-07 01:10:20 +00:00
|
|
|
_, err := ds.NewLabel(
|
2021-09-14 12:11:07 +00:00
|
|
|
context.Background(),
|
2021-06-06 22:07:29 +00:00
|
|
|
&fleet.Label{
|
2020-04-07 22:12:32 +00:00
|
|
|
Name: "All Hosts",
|
|
|
|
|
Query: "select 1",
|
2021-06-06 22:07:29 +00:00
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeManual,
|
2020-04-07 01:10:20 +00:00
|
|
|
},
|
|
|
|
|
)
|
2021-09-07 16:48:04 +00:00
|
|
|
require.NoError(t, err)
|
2020-04-07 01:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
2024-04-08 19:34:55 +00:00
|
|
|
func AddBuiltinLabels(t *testing.T, ds fleet.Datastore) {
|
|
|
|
|
builtins := []*fleet.Label{
|
|
|
|
|
{
|
|
|
|
|
Name: "All Hosts",
|
|
|
|
|
Query: "select 1",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
2024-04-16 15:20:59 +00:00
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeDynamic,
|
2024-04-08 19:34:55 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "macOS",
|
|
|
|
|
Query: "select 1 from os_version where platform = 'darwin';",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeDynamic,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "Ubuntu Linux",
|
|
|
|
|
Query: "select 1 from os_version where platform = 'ubuntu';",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeDynamic,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "CentOS Linux",
|
|
|
|
|
Query: "select 1 from os_version where platform = 'centos' or name like '%centos%';",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeDynamic,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "MS Windows",
|
|
|
|
|
Query: "select 1 from os_version where platform = 'windows';",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeDynamic,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "Red Hat Linux",
|
|
|
|
|
Query: "SELECT 1 FROM os_version WHERE name LIKE '%red hat%'",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeDynamic,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "All Linux",
|
|
|
|
|
Query: "SELECT 1 FROM osquery_info WHERE build_platform LIKE '%ubuntu%' OR build_distro LIKE '%centos%';",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeDynamic,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "chrome",
|
|
|
|
|
Query: "select 1 from os_version where platform = 'chrome';",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeDynamic,
|
|
|
|
|
},
|
2024-04-15 20:10:10 +00:00
|
|
|
{
|
|
|
|
|
Name: fleet.BuiltinLabelMacOS14Plus,
|
|
|
|
|
Query: "select 1 from os_version where platform = 'darwin' and major >= 14;",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeDynamic,
|
|
|
|
|
},
|
iOS/iPadOS as platforms/labels (#20126)
#19963
- [X] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/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] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [X] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [X] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [X] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [X] Manual QA for all new/changed functionality
---
# API changes for dashboard UI changes
## Main dashboard page
`GET /api/latest/fleet/host_summary?low_disk_space=32` (see
`ios`/`ipados` platforms and `iOS`/`iPadOS` labels)
```json
{
"totals_hosts_count": 9,
"online_count": 0,
"offline_count": 9,
"mia_count": 0,
"missing_30_days_count": 0,
"new_count": 0,
"all_linux_count": 2,
"low_disk_space_count": 3,
"builtin_labels": [
{
"id": 1,
"name": "macOS 14+ (Sonoma+)",
"description": "macOS hosts with version 14 and above",
"label_type": "builtin"
},
{
"id": 7,
"name": "All Hosts",
"description": "All hosts which have enrolled in Fleet",
"label_type": "builtin"
},
{
"id": 8,
"name": "macOS",
"description": "All macOS hosts",
"label_type": "builtin"
},
{
"id": 9,
"name": "Ubuntu Linux",
"description": "All Ubuntu hosts",
"label_type": "builtin"
},
{
"id": 10,
"name": "CentOS Linux",
"description": "All CentOS hosts",
"label_type": "builtin"
},
{
"id": 11,
"name": "MS Windows",
"description": "All Windows hosts",
"label_type": "builtin"
},
{
"id": 12,
"name": "Red Hat Linux",
"description": "All Red Hat Enterprise Linux hosts",
"label_type": "builtin"
},
{
"id": 13,
"name": "All Linux",
"description": "All Linux distributions",
"label_type": "builtin"
},
{
"id": 14,
"name": "chrome",
"description": "All Chrome hosts",
"label_type": "builtin"
},
{
"id": 15,
"name": "iOS",
"description": "All iOS hosts",
"label_type": "builtin"
},
{
"id": 16,
"name": "iPadOS",
"description": "All iPadOS hosts",
"label_type": "builtin"
}
],
"platforms": [
{
"platform": "darwin",
"hosts_count": 3
},
{
"platform": "ios",
"hosts_count": 1
},
{
"platform": "ipados",
"hosts_count": 1
},
{
"platform": "rhel",
"hosts_count": 1
},
{
"platform": "ubuntu",
"hosts_count": 1
},
{
"platform": "windows",
"hosts_count": 2
}
]
}
```
## After selecting a platform
`GET /api/latest/fleet/host_summary?platform=ios&low_disk_space=100`
(similar with `ipados`)
```json
{
"totals_hosts_count": 1,
"online_count": 0,
"offline_count": 1,
"mia_count": 0,
"missing_30_days_count": 0,
"new_count": 0,
"all_linux_count": 0,
"low_disk_space_count": 1,
"builtin_labels": [
{
"id": 1,
"name": "macOS 14+ (Sonoma+)",
"description": "macOS hosts with version 14 and above",
"label_type": "builtin"
},
{
"id": 7,
"name": "All Hosts",
"description": "All hosts which have enrolled in Fleet",
"label_type": "builtin"
},
{
"id": 8,
"name": "macOS",
"description": "All macOS hosts",
"label_type": "builtin"
},
{
"id": 9,
"name": "Ubuntu Linux",
"description": "All Ubuntu hosts",
"label_type": "builtin"
},
{
"id": 10,
"name": "CentOS Linux",
"description": "All CentOS hosts",
"label_type": "builtin"
},
{
"id": 11,
"name": "MS Windows",
"description": "All Windows hosts",
"label_type": "builtin"
},
{
"id": 12,
"name": "Red Hat Linux",
"description": "All Red Hat Enterprise Linux hosts",
"label_type": "builtin"
},
{
"id": 13,
"name": "All Linux",
"description": "All Linux distributions",
"label_type": "builtin"
},
{
"id": 14,
"name": "chrome",
"description": "All Chrome hosts",
"label_type": "builtin"
},
{
"id": 15,
"name": "iOS",
"description": "All iOS hosts",
"label_type": "builtin"
},
{
"id": 16,
"name": "iPadOS",
"description": "All iPadOS hosts",
"label_type": "builtin"
}
],
"platforms": [
{
"platform": "ios",
"hosts_count": 1
}
]
}
```
### To populate list of MDM solutions of a selected platform
`GET /api/latest/fleet/hosts/summary/mdm\?platform=ios` (similar with
`ipados`)
```json
{
"counts_updated_at": "2024-06-27T21:56:45Z",
"mobile_device_management_enrollment_status": {
"enrolled_manual_hosts_count": 0,
"enrolled_automated_hosts_count": 1,
"pending_hosts_count": 0,
"unenrolled_hosts_count": 0,
"hosts_count": 1
},
"mobile_device_management_solution": [
{
"id": 1,
"name": "Fleet",
"server_url": "https://lucas-fleet.ngrok.app/mdm/apple/mdm",
"hosts_count": 1
}
]
}
```
### To populate OS versions of a selected platform
`GET /api/latest/fleet/os_versions?platform=ipados` (similar with `ios`)
```json
{
"meta": {
"has_next_results": false,
"has_previous_results": false
},
"count": 1,
"counts_updated_at": "2024-06-27T21:36:12Z",
"os_versions": [
{
"os_version_id": 7,
"hosts_count": 1,
"name": "iPadOS 17.5.1",
"name_only": "iPadOS",
"version": "17.5.1",
"platform": "ipados",
"vulnerabilities": []
}
]
}
```
## Filtering hosts by the two new `iOS`/`iPadOS` labels
Works the same as with other labels.
2024-07-08 21:05:29 +00:00
|
|
|
{
|
|
|
|
|
Name: "iOS",
|
|
|
|
|
Platform: "ios",
|
|
|
|
|
Query: "",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeManual,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Name: "iPadOS",
|
|
|
|
|
Platform: "ipados",
|
|
|
|
|
Query: "",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeManual,
|
|
|
|
|
},
|
2024-09-30 16:02:54 +00:00
|
|
|
{
|
|
|
|
|
Name: "Fedora Linux",
|
|
|
|
|
Platform: "rhel",
|
|
|
|
|
Query: "select 1 from os_version where name = 'Fedora Linux';",
|
|
|
|
|
LabelType: fleet.LabelTypeBuiltIn,
|
|
|
|
|
LabelMembershipType: fleet.LabelMembershipTypeDynamic,
|
|
|
|
|
},
|
2024-04-08 19:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
names := fleet.ReservedLabelNames()
|
|
|
|
|
require.Equal(t, len(builtins), len(names))
|
|
|
|
|
storedByName := map[string]*fleet.Label{}
|
|
|
|
|
for _, b := range builtins {
|
|
|
|
|
stored, err := ds.NewLabel(context.Background(), b)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
storedByName[stored.Name] = stored
|
|
|
|
|
}
|
|
|
|
|
require.Len(t, storedByName, len(builtins))
|
|
|
|
|
|
|
|
|
|
for name := range names {
|
|
|
|
|
_, ok := storedByName[name]
|
|
|
|
|
require.True(t, ok, "expected label %s to be created", name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 12:57:46 +00:00
|
|
|
// NewHostOption is an Option for the NewHost function.
|
|
|
|
|
type NewHostOption func(*fleet.Host)
|
|
|
|
|
|
|
|
|
|
// WithComputerName sets the ComputerName in NewHost.
|
|
|
|
|
func WithComputerName(s string) NewHostOption {
|
|
|
|
|
return func(h *fleet.Host) {
|
|
|
|
|
h.ComputerName = s
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 17:22:07 +00:00
|
|
|
func WithPlatform(s string) NewHostOption {
|
|
|
|
|
return func(h *fleet.Host) {
|
|
|
|
|
h.Platform = s
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-19 20:11:59 +00:00
|
|
|
func WithOSVersion(s string) NewHostOption {
|
|
|
|
|
return func(h *fleet.Host) {
|
|
|
|
|
h.OSVersion = s
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 17:13:25 +00:00
|
|
|
func WithTeamID(teamID uint) NewHostOption {
|
|
|
|
|
return func(h *fleet.Host) {
|
|
|
|
|
h.TeamID = &teamID
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 12:57:46 +00:00
|
|
|
func NewHost(tb testing.TB, ds fleet.Datastore, name, ip, key, uuid string, now time.Time, options ...NewHostOption) *fleet.Host {
|
2021-07-19 18:08:41 +00:00
|
|
|
osqueryHostID, _ := server.GenerateRandomText(10)
|
2022-10-08 12:57:46 +00:00
|
|
|
h := &fleet.Host{
|
2021-06-24 00:32:19 +00:00
|
|
|
Hostname: name,
|
2022-12-26 21:32:39 +00:00
|
|
|
NodeKey: &key,
|
2021-06-24 00:32:19 +00:00
|
|
|
UUID: uuid,
|
|
|
|
|
DetailUpdatedAt: now,
|
|
|
|
|
LabelUpdatedAt: now,
|
2021-09-27 19:27:38 +00:00
|
|
|
PolicyUpdatedAt: now,
|
2021-06-24 00:32:19 +00:00
|
|
|
SeenTime: now,
|
2022-12-26 21:32:39 +00:00
|
|
|
OsqueryHostID: &osqueryHostID,
|
2021-11-17 22:03:30 +00:00
|
|
|
Platform: "darwin",
|
2022-10-08 12:57:46 +00:00
|
|
|
PublicIP: ip,
|
|
|
|
|
PrimaryIP: ip,
|
|
|
|
|
}
|
|
|
|
|
for _, o := range options {
|
|
|
|
|
o(h)
|
|
|
|
|
}
|
|
|
|
|
h, err := ds.NewHost(context.Background(), h)
|
2022-01-26 14:47:56 +00:00
|
|
|
require.NoError(tb, err)
|
|
|
|
|
require.NotZero(tb, h.ID)
|
|
|
|
|
require.NoError(tb, ds.MarkHostsSeen(context.Background(), []uint{h.ID}, now))
|
2016-12-06 18:22:28 +00:00
|
|
|
|
|
|
|
|
return h
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 20:42:29 +00:00
|
|
|
func NewUser(t *testing.T, ds fleet.Datastore, name, email string, admin bool) *fleet.User {
|
2021-07-13 19:33:04 +00:00
|
|
|
role := fleet.RoleObserver
|
|
|
|
|
if admin {
|
|
|
|
|
role = fleet.RoleAdmin
|
|
|
|
|
}
|
2021-09-14 12:11:07 +00:00
|
|
|
u, err := ds.NewUser(context.Background(), &fleet.User{
|
2021-07-13 19:33:04 +00:00
|
|
|
Password: []byte("garbage"),
|
|
|
|
|
Salt: "garbage",
|
|
|
|
|
Name: name,
|
|
|
|
|
Email: email,
|
|
|
|
|
GlobalRole: &role,
|
2016-12-07 20:22:31 +00:00
|
|
|
})
|
|
|
|
|
|
2021-09-07 16:48:04 +00:00
|
|
|
require.NoError(t, err)
|
2016-12-07 20:22:31 +00:00
|
|
|
require.NotZero(t, u.ID)
|
|
|
|
|
|
|
|
|
|
return u
|
|
|
|
|
}
|
2018-06-15 14:13:11 +00:00
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
func NewScheduledQuery(t *testing.T, ds fleet.Datastore, pid, qid, interval uint, snapshot, removed bool, name string) *fleet.ScheduledQuery {
|
2021-09-14 12:11:07 +00:00
|
|
|
sq, err := ds.NewScheduledQuery(context.Background(), &fleet.ScheduledQuery{
|
2021-05-07 04:05:09 +00:00
|
|
|
Name: name,
|
2018-06-15 14:13:11 +00:00
|
|
|
PackID: pid,
|
|
|
|
|
QueryID: qid,
|
|
|
|
|
Interval: interval,
|
|
|
|
|
Snapshot: &snapshot,
|
|
|
|
|
Removed: &removed,
|
2021-11-17 22:03:30 +00:00
|
|
|
Platform: ptr.String("darwin"),
|
2018-06-15 14:13:11 +00:00
|
|
|
})
|
2021-09-07 16:48:04 +00:00
|
|
|
require.NoError(t, err)
|
2018-06-15 14:13:11 +00:00
|
|
|
require.NotZero(t, sq.ID)
|
|
|
|
|
|
|
|
|
|
return sq
|
|
|
|
|
}
|