@@ -9,12 +9,12 @@ import { FtrProviderContext } from '../../ftr_provider_context';
99export default function ( { getService } : FtrProviderContext ) {
1010 const esArchiver = getService ( 'esArchiver' ) ;
1111 const supertest = getService ( 'supertest' ) ;
12- describe ( 'test endpoints api' , ( ) => {
13- describe ( 'POST /api/endpoint/endpoints when index is empty' , ( ) => {
14- it ( 'endpoints api should return empty result when index is empty' , async ( ) => {
15- await esArchiver . unload ( 'endpoint/endpoints /api_feature' ) ;
12+ describe ( 'test metadata api' , ( ) => {
13+ describe ( 'POST /api/endpoint/metadata when index is empty' , ( ) => {
14+ it ( 'metadata api should return empty result when index is empty' , async ( ) => {
15+ await esArchiver . unload ( 'endpoint/metadata /api_feature' ) ;
1616 const { body } = await supertest
17- . post ( '/api/endpoint/endpoints ' )
17+ . post ( '/api/endpoint/metadata ' )
1818 . set ( 'kbn-xsrf' , 'xxx' )
1919 . send ( )
2020 . expect ( 200 ) ;
@@ -25,12 +25,12 @@ export default function({ getService }: FtrProviderContext) {
2525 } ) ;
2626 } ) ;
2727
28- describe ( 'POST /api/endpoint/endpoints when index is not empty' , ( ) => {
29- before ( ( ) => esArchiver . load ( 'endpoint/endpoints /api_feature' ) ) ;
30- after ( ( ) => esArchiver . unload ( 'endpoint/endpoints /api_feature' ) ) ;
31- it ( 'endpoints api should return one entry for each endpoint with default paging' , async ( ) => {
28+ describe ( 'POST /api/endpoint/metadata when index is not empty' , ( ) => {
29+ before ( ( ) => esArchiver . load ( 'endpoint/metadata /api_feature' ) ) ;
30+ after ( ( ) => esArchiver . unload ( 'endpoint/metadata /api_feature' ) ) ;
31+ it ( 'metadata api should return one entry for each endpoint with default paging' , async ( ) => {
3232 const { body } = await supertest
33- . post ( '/api/endpoint/endpoints ' )
33+ . post ( '/api/endpoint/metadata ' )
3434 . set ( 'kbn-xsrf' , 'xxx' )
3535 . send ( )
3636 . expect ( 200 ) ;
@@ -40,9 +40,9 @@ export default function({ getService }: FtrProviderContext) {
4040 expect ( body . request_page_index ) . to . eql ( 0 ) ;
4141 } ) ;
4242
43- it ( 'endpoints api should return page based on paging properties passed.' , async ( ) => {
43+ it ( 'metadata api should return page based on paging properties passed.' , async ( ) => {
4444 const { body } = await supertest
45- . post ( '/api/endpoint/endpoints ' )
45+ . post ( '/api/endpoint/metadata ' )
4646 . set ( 'kbn-xsrf' , 'xxx' )
4747 . send ( {
4848 paging_properties : [
@@ -61,12 +61,12 @@ export default function({ getService }: FtrProviderContext) {
6161 expect ( body . request_page_index ) . to . eql ( 1 ) ;
6262 } ) ;
6363
64- /* test that when paging properties produces no result, the total should reflect the actual number of endpoints
64+ /* test that when paging properties produces no result, the total should reflect the actual number of metadata
6565 in the index.
6666 */
67- it ( 'endpoints api should return accurate total endpoints if page index produces no result' , async ( ) => {
67+ it ( 'metadata api should return accurate total metadata if page index produces no result' , async ( ) => {
6868 const { body } = await supertest
69- . post ( '/api/endpoint/endpoints ' )
69+ . post ( '/api/endpoint/metadata ' )
7070 . set ( 'kbn-xsrf' , 'xxx' )
7171 . send ( {
7272 paging_properties : [
@@ -85,9 +85,9 @@ export default function({ getService }: FtrProviderContext) {
8585 expect ( body . request_page_index ) . to . eql ( 30 ) ;
8686 } ) ;
8787
88- it ( 'endpoints api should return 400 when pagingProperties is below boundaries.' , async ( ) => {
88+ it ( 'metadata api should return 400 when pagingProperties is below boundaries.' , async ( ) => {
8989 const { body } = await supertest
90- . post ( '/api/endpoint/endpoints ' )
90+ . post ( '/api/endpoint/metadata ' )
9191 . set ( 'kbn-xsrf' , 'xxx' )
9292 . send ( {
9393 paging_properties : [
@@ -103,9 +103,9 @@ export default function({ getService }: FtrProviderContext) {
103103 expect ( body . message ) . to . contain ( 'Value is [0] but it must be equal to or greater than [1]' ) ;
104104 } ) ;
105105
106- it ( 'endpoints api should return page based on filters passed.' , async ( ) => {
106+ it ( 'metadata api should return page based on filters passed.' , async ( ) => {
107107 const { body } = await supertest
108- . post ( '/api/endpoint/endpoints ' )
108+ . post ( '/api/endpoint/metadata ' )
109109 . set ( 'kbn-xsrf' , 'xxx' )
110110 . send ( { filter : 'not host.ip:10.101.149.26' } )
111111 . expect ( 200 ) ;
@@ -115,10 +115,10 @@ export default function({ getService }: FtrProviderContext) {
115115 expect ( body . request_page_index ) . to . eql ( 0 ) ;
116116 } ) ;
117117
118- it ( 'endpoints api should return page based on filters and paging passed.' , async ( ) => {
118+ it ( 'metadata api should return page based on filters and paging passed.' , async ( ) => {
119119 const notIncludedIp = '10.101.149.26' ;
120120 const { body } = await supertest
121- . post ( '/api/endpoint/endpoints ' )
121+ . post ( '/api/endpoint/metadata ' )
122122 . set ( 'kbn-xsrf' , 'xxx' )
123123 . send ( {
124124 paging_properties : [
@@ -143,10 +143,10 @@ export default function({ getService }: FtrProviderContext) {
143143 expect ( body . request_page_index ) . to . eql ( 0 ) ;
144144 } ) ;
145145
146- it ( 'endpoints api should return page based on host.os.variant filter.' , async ( ) => {
146+ it ( 'metadata api should return page based on host.os.variant filter.' , async ( ) => {
147147 const variantValue = 'Windows Pro' ;
148148 const { body } = await supertest
149- . post ( '/api/endpoint/endpoints ' )
149+ . post ( '/api/endpoint/metadata ' )
150150 . set ( 'kbn-xsrf' , 'xxx' )
151151 . send ( {
152152 filter : `host.os.variant.keyword:${ variantValue } ` ,
@@ -161,6 +161,40 @@ export default function({ getService }: FtrProviderContext) {
161161 expect ( body . request_page_size ) . to . eql ( 10 ) ;
162162 expect ( body . request_page_index ) . to . eql ( 0 ) ;
163163 } ) ;
164+
165+ it ( 'metadata api should return the latest event for all the events for an endpoint' , async ( ) => {
166+ const targetEndpointIp = '10.192.213.130' ;
167+ const { body } = await supertest
168+ . post ( '/api/endpoint/metadata' )
169+ . set ( 'kbn-xsrf' , 'xxx' )
170+ . send ( {
171+ filter : `host.ip:${ targetEndpointIp } ` ,
172+ } )
173+ . expect ( 200 ) ;
174+ expect ( body . total ) . to . eql ( 1 ) ;
175+ const resultIp : string = body . endpoints [ 0 ] . host . ip . filter (
176+ ( ip : string ) => ip === targetEndpointIp
177+ ) ;
178+ expect ( resultIp ) . to . eql ( [ targetEndpointIp ] ) ;
179+ expect ( body . endpoints [ 0 ] . event . created ) . to . eql ( '2020-01-24T16:06:09.541Z' ) ;
180+ expect ( body . endpoints . length ) . to . eql ( 1 ) ;
181+ expect ( body . request_page_size ) . to . eql ( 10 ) ;
182+ expect ( body . request_page_index ) . to . eql ( 0 ) ;
183+ } ) ;
184+
185+ it ( 'metadata api should return all endpoints when filter is empty string' , async ( ) => {
186+ const { body } = await supertest
187+ . post ( '/api/endpoint/metadata' )
188+ . set ( 'kbn-xsrf' , 'xxx' )
189+ . send ( {
190+ filter : '' ,
191+ } )
192+ . expect ( 200 ) ;
193+ expect ( body . total ) . to . eql ( 3 ) ;
194+ expect ( body . endpoints . length ) . to . eql ( 3 ) ;
195+ expect ( body . request_page_size ) . to . eql ( 10 ) ;
196+ expect ( body . request_page_index ) . to . eql ( 0 ) ;
197+ } ) ;
164198 } ) ;
165199 } ) ;
166200}
0 commit comments