2016-08-18 21:16:44 +00:00
|
|
|
package datastore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-11-11 17:59:12 +00:00
|
|
|
"github.com/fleetdm/fleet/server/kolide"
|
2016-08-18 21:16:44 +00:00
|
|
|
)
|
|
|
|
|
2016-10-04 20:34:36 +00:00
|
|
|
var testFunctions = [...]func(*testing.T, kolide.Datastore){
|
|
|
|
testOrgInfo,
|
2020-05-21 15:36:00 +00:00
|
|
|
testAdditionalQueries,
|
2020-05-29 16:12:39 +00:00
|
|
|
testEnrollSecrets,
|
2020-11-04 20:09:00 +00:00
|
|
|
testEnrollSecretsCaseSensitive,
|
2020-05-29 16:12:39 +00:00
|
|
|
testEnrollSecretRoundtrip,
|
2016-10-04 20:34:36 +00:00
|
|
|
testCreateInvite,
|
2016-12-20 21:31:09 +00:00
|
|
|
testInviteByEmail,
|
2016-12-30 01:58:12 +00:00
|
|
|
testInviteByToken,
|
2016-11-16 13:47:49 +00:00
|
|
|
testListInvites,
|
|
|
|
testDeleteInvite,
|
|
|
|
testSaveInvite,
|
2016-10-04 20:34:36 +00:00
|
|
|
testDeleteQuery,
|
2016-12-09 17:12:45 +00:00
|
|
|
testDeleteQueries,
|
2016-10-04 20:34:36 +00:00
|
|
|
testSaveQuery,
|
2016-11-16 13:47:49 +00:00
|
|
|
testListQuery,
|
2016-10-04 20:34:36 +00:00
|
|
|
testDeletePack,
|
2020-11-05 05:18:02 +00:00
|
|
|
testNewPack,
|
2016-10-04 20:34:36 +00:00
|
|
|
testEnrollHost,
|
|
|
|
testAuthenticateHost,
|
2020-11-04 20:09:00 +00:00
|
|
|
testAuthenticateHostCaseSensitive,
|
2016-10-04 20:34:36 +00:00
|
|
|
testLabels,
|
2018-06-18 17:09:08 +00:00
|
|
|
testSaveLabel,
|
2016-10-04 20:34:36 +00:00
|
|
|
testManagingLabelsOnPacks,
|
|
|
|
testPasswordResetRequests,
|
|
|
|
testCreateUser,
|
|
|
|
testSaveUser,
|
|
|
|
testUserByID,
|
|
|
|
testPasswordResetRequests,
|
2016-11-02 14:59:53 +00:00
|
|
|
testSearchHosts,
|
|
|
|
testSearchHostsLimit,
|
|
|
|
testSearchLabels,
|
|
|
|
testSearchLabelsLimit,
|
|
|
|
testListHostsInLabel,
|
|
|
|
testListUniqueHostsInLabels,
|
2016-11-16 13:47:49 +00:00
|
|
|
testSaveHosts,
|
|
|
|
testDeleteHost,
|
2020-11-04 20:03:06 +00:00
|
|
|
testListHosts,
|
Add host additional info filters (#28)
This change adds the ability to filter additional host info via the list hosts endpoint; a continuation from [here](https://github.com/kolide/fleet/pull/2330), but now filtering is accomplished via SQL.
Additional object without filter:
```
curl 'https://localhost:8080/api/v1/kolide/hosts'
...
"additional": {
"macs": [
{
"mac": "00:00:00:00:00:00"
},
{
"mac": "02:42:c0:a8:10:05"
}
],
"time": [
{
"day": "13",
"hour": "3",
"year": "2020",
"month": "10",
"minutes": "43",
"seconds": "11",
"weekday": "Tuesday",
"datetime": "2020-10-13T03:43:11Z",
"iso_8601": "2020-10-13T03:43:11Z",
"timezone": "GMT",
"timestamp": "Tue Oct 13 03:43:11 2020 UTC",
"unix_time": "1602560591",
"local_time": "1602560591",
"local_timezone": "UTC"
}
},
...
```
Additional object with filter:
```
curl 'https://localhost:8080/api/v1/kolide/hosts?additional_info_filters=macs,notreal'
...
"additional": {
"macs": [
{
"mac": "00:00:00:00:00:00"
},
{
"mac": "02:42:c0:a8:10:05"
}
],
"notreal": null
},
...
```
2020-11-14 00:33:25 +00:00
|
|
|
testListHostsFilterAdditional,
|
2020-11-04 20:03:06 +00:00
|
|
|
testListHostsStatus,
|
2021-02-17 00:53:42 +00:00
|
|
|
testListHostsQuery,
|
2018-01-10 19:38:20 +00:00
|
|
|
testListHostsInPack,
|
|
|
|
testListPacksForHost,
|
2018-05-17 22:54:34 +00:00
|
|
|
testHostIDsByName,
|
2020-04-22 20:54:32 +00:00
|
|
|
testHostByIdentifier,
|
2018-01-10 19:38:20 +00:00
|
|
|
testListPacks,
|
2016-11-23 00:35:43 +00:00
|
|
|
testDistributedQueryCampaign,
|
2016-12-01 18:31:16 +00:00
|
|
|
testCleanupDistributedQueryCampaigns,
|
2016-11-25 18:08:22 +00:00
|
|
|
testBuiltInLabels,
|
2016-12-06 18:22:28 +00:00
|
|
|
testLoadPacksForQueries,
|
2018-06-15 14:13:11 +00:00
|
|
|
testScheduledQuery,
|
|
|
|
testDeleteScheduledQuery,
|
|
|
|
testNewScheduledQuery,
|
2016-12-13 22:22:05 +00:00
|
|
|
testListScheduledQueriesInPack,
|
2018-06-21 00:32:43 +00:00
|
|
|
testCascadingDeletionOfQueries,
|
2017-01-13 18:35:25 +00:00
|
|
|
testGetPackByName,
|
|
|
|
testGetQueryByName,
|
Add host_ids and label_ids fields to the packs API (#737)
This PR adds the `host_ids` and `label_ids` field to the packs HTTP API so that one can operate on the hosts/labels which a pack is scheduled to be executed on. This replaces (and deletes) the `/api/v1/kolide/packs/123/labels/456` API in favor of `PATCH /api/v1/packs/123` and specifying the `label_ids` field. This also allows for bulk operations.
Consider the following API examples:
## Creating a pack with a known set of hosts and labels
The key addition is the `host_ids` and `label_ids` field in both the request and the response.
### Request
```
POST /api/v1/kolide/packs
```
```json
{
"name": "My new pack",
"description": "The newest of the packs",
"host_ids": [1, 2, 3],
"label_ids": [1, 3, 5]
}
```
### Response
```json
{
"pack": {
"id": 123,
"name": "My new pack",
"description": "The newest of the packs",
"platform": "",
"created_by": 1,
"disabled": false,
"query_count": 0,
"total_hosts_count": 5,
"host_ids": [1, 2, 3],
"label_ids": [1, 3, 5]
}
}
```
## Modifying the hosts and/or labels that a pack is scheduled to execute on
### Request
```
PATCH /api/v1/kolide/packs/123
```
```json
{
"host_ids": [1, 2, 3, 4, 5],
"label_ids": [1, 3, 5, 7]
}
```
### Response
```json
{
"pack": {
"id": 123,
"name": "My new pack",
"description": "The newest of the packs",
"platform": "",
"created_by": 1,
"disabled": false,
"query_count": 0,
"total_hosts_count": 5,
"host_ids": [1, 2, 3, 4, 5],
"label_ids": [1, 3, 5, 7]
}
}
```
close #633
2017-01-03 17:32:06 +00:00
|
|
|
testAddLabelToPackTwice,
|
2017-01-04 21:16:17 +00:00
|
|
|
testGenerateHostStatusStatistics,
|
|
|
|
testMarkHostSeen,
|
2019-04-09 18:11:11 +00:00
|
|
|
testCleanupIncomingHosts,
|
2017-01-16 22:20:15 +00:00
|
|
|
testDuplicateNewQuery,
|
2017-01-27 13:35:58 +00:00
|
|
|
testChangeEmail,
|
2018-01-10 19:38:20 +00:00
|
|
|
testChangeLabelDetails,
|
2017-03-08 17:17:07 +00:00
|
|
|
testMigrationStatus,
|
2017-03-08 17:29:25 +00:00
|
|
|
testUnicode,
|
2017-03-30 15:31:28 +00:00
|
|
|
testCountHostsInTargets,
|
2017-04-18 17:39:50 +00:00
|
|
|
testHostStatus,
|
2020-03-23 01:33:04 +00:00
|
|
|
testHostIDsInTargets,
|
2017-12-13 23:14:54 +00:00
|
|
|
testApplyOsqueryOptions,
|
|
|
|
testApplyOsqueryOptionsNoOverrides,
|
|
|
|
testOsqueryOptionsForHost,
|
2018-01-03 19:18:05 +00:00
|
|
|
testApplyQueries,
|
|
|
|
testApplyPackSpecRoundtrip,
|
|
|
|
testApplyPackSpecMissingQueries,
|
2019-01-17 23:59:42 +00:00
|
|
|
testApplyPackSpecMissingName,
|
2018-05-08 01:54:29 +00:00
|
|
|
testGetPackSpec,
|
2018-01-10 19:38:20 +00:00
|
|
|
testApplyLabelSpecsRoundtrip,
|
2018-05-08 01:54:29 +00:00
|
|
|
testGetLabelSpec,
|
2018-05-17 22:54:34 +00:00
|
|
|
testLabelIDsByName,
|
2018-01-10 19:38:20 +00:00
|
|
|
testListLabelsForPack,
|
2020-05-21 15:36:00 +00:00
|
|
|
testHostAdditional,
|
2020-11-05 04:45:16 +00:00
|
|
|
testCarveMetadata,
|
|
|
|
testCarveBlocks,
|
|
|
|
testCarveListCarves,
|
|
|
|
testCarveCleanupCarves,
|
2020-12-16 17:16:55 +00:00
|
|
|
testCarveUpdateCarve,
|
2016-10-03 03:14:35 +00:00
|
|
|
}
|