-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] migrate to new GET metadata list API (#119123)
- Loading branch information
Showing
19 changed files
with
273 additions
and
180 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
x-pack/plugins/security_solution/common/endpoint/schema/metadata.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { HostStatus } from '../types'; | ||
import { GetMetadataListRequestSchemaV2 } from './metadata'; | ||
|
||
describe('endpoint metadata schema', () => { | ||
describe('GetMetadataListRequestSchemaV2', () => { | ||
const query = GetMetadataListRequestSchemaV2.query; | ||
|
||
it('should return correct query params when valid', () => { | ||
const queryParams = { | ||
page: 1, | ||
pageSize: 20, | ||
kuery: 'some kuery', | ||
hostStatuses: [HostStatus.HEALTHY.toString()], | ||
}; | ||
expect(query.validate(queryParams)).toEqual(queryParams); | ||
}); | ||
|
||
it('should correctly use default values', () => { | ||
const expected = { page: 0, pageSize: 10 }; | ||
expect(query.validate(undefined)).toEqual(expected); | ||
expect(query.validate({ page: undefined })).toEqual(expected); | ||
expect(query.validate({ pageSize: undefined })).toEqual(expected); | ||
expect(query.validate({ page: undefined, pageSize: undefined })).toEqual(expected); | ||
}); | ||
|
||
it('should throw if page param is not a number', () => { | ||
expect(() => query.validate({ page: 'notanumber' })).toThrowError(); | ||
}); | ||
|
||
it('should throw if page param is less than 0', () => { | ||
expect(() => query.validate({ page: -1 })).toThrowError(); | ||
}); | ||
|
||
it('should throw if pageSize param is not a number', () => { | ||
expect(() => query.validate({ pageSize: 'notanumber' })).toThrowError(); | ||
}); | ||
|
||
it('should throw if pageSize param is less than 1', () => { | ||
expect(() => query.validate({ pageSize: 0 })).toThrowError(); | ||
}); | ||
|
||
it('should throw if pageSize param is greater than 10000', () => { | ||
expect(() => query.validate({ pageSize: 10001 })).toThrowError(); | ||
}); | ||
|
||
it('should throw if kuery is not string', () => { | ||
expect(() => query.validate({ kuery: 123 })).toThrowError(); | ||
}); | ||
|
||
it('should work with valid hostStatus', () => { | ||
const queryParams = { hostStatuses: [HostStatus.HEALTHY, HostStatus.UPDATING] }; | ||
const expected = { page: 0, pageSize: 10, ...queryParams }; | ||
expect(query.validate(queryParams)).toEqual(expected); | ||
}); | ||
|
||
it('should throw if invalid hostStatus', () => { | ||
expect(() => | ||
query.validate({ hostStatuses: [HostStatus.UNHEALTHY, 'invalidstatus'] }) | ||
).toThrowError(); | ||
}); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
x-pack/plugins/security_solution/common/endpoint/schema/metadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema, TypeOf } from '@kbn/config-schema'; | ||
import { HostStatus } from '../types'; | ||
|
||
export const GetMetadataListRequestSchemaV2 = { | ||
query: schema.object( | ||
{ | ||
page: schema.number({ defaultValue: 0, min: 0 }), | ||
pageSize: schema.number({ defaultValue: 10, min: 1, max: 10000 }), | ||
kuery: schema.maybe(schema.string()), | ||
hostStatuses: schema.maybe( | ||
schema.arrayOf( | ||
schema.oneOf([ | ||
schema.literal(HostStatus.HEALTHY.toString()), | ||
schema.literal(HostStatus.OFFLINE.toString()), | ||
schema.literal(HostStatus.UPDATING.toString()), | ||
schema.literal(HostStatus.UNHEALTHY.toString()), | ||
schema.literal(HostStatus.INACTIVE.toString()), | ||
]) | ||
) | ||
), | ||
}, | ||
{ defaultValue: { page: 0, pageSize: 10 } } | ||
), | ||
}; | ||
|
||
export type GetMetadataListRequestQuery = TypeOf<typeof GetMetadataListRequestSchemaV2.query>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.