-
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.
- Loading branch information
1 parent
ad9dad3
commit c653765
Showing
4 changed files
with
3,409 additions
and
0 deletions.
There are no files selected for viewing
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
153 changes: 153 additions & 0 deletions
153
x-pack/test/api_integration/apis/endpoint/metadata_status.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,153 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import uuid from 'uuid'; | ||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../ftr_provider_context'; | ||
import { getSupertestWithoutAuth } from '../fleet/agents/services'; | ||
|
||
export default function(providerContext: FtrProviderContext) { | ||
const { getService } = providerContext; | ||
const esArchiver = getService('esArchiver'); | ||
const supertest = getService('supertest'); | ||
const supertestWithoutAuth = getSupertestWithoutAuth(providerContext); | ||
const esClient = getService('es'); | ||
// agent that is enrolled and know to fleet | ||
const enrolledAgentId = '3efef370-8164-11ea-bc0d-9196b6de96eb'; | ||
// host that is connected to enrolledAgentId | ||
const enrolledHostId = 'fdb346d9-6f56-426a-90a7-a9328d1b0528'; | ||
// host that is not connected to an enrolled agent id | ||
const notEnrolledHostId = 'bcf0d070-d9f2-40aa-8620-cbc004747722'; | ||
|
||
let apiKey: { id: string; api_key: string }; | ||
|
||
describe('test metadata api status', () => { | ||
describe('/api/endpoint/metadata when index is not empty', () => { | ||
before(async () => { | ||
await esArchiver.load('endpoint/metadata/endpoint_status_feature'); | ||
const { body: apiKeyBody } = await esClient.security.createApiKey({ | ||
body: { | ||
name: `test access api key: ${uuid.v4()}`, | ||
}, | ||
}); | ||
apiKey = apiKeyBody; | ||
const { | ||
body: { _source: agentDoc }, | ||
} = await esClient.get({ | ||
index: '.kibana', | ||
id: `agents:${enrolledAgentId}`, | ||
}); | ||
|
||
agentDoc.agents.access_api_key_id = apiKey.id; | ||
|
||
await esClient.update({ | ||
index: '.kibana', | ||
id: `agents:${enrolledAgentId}`, | ||
refresh: 'true', | ||
body: { | ||
doc: agentDoc, | ||
}, | ||
}); | ||
}); | ||
|
||
after(async () => await esArchiver.unload('endpoint/metadata/endpoint_status_feature')); | ||
it('should return single metadata with status error when agent status is error', async () => { | ||
const { body: metadataResponse } = await supertest | ||
.get(`/api/endpoint/metadata/${enrolledHostId}`) | ||
.set('kbn-xsrf', 'xxx') | ||
This comment has been minimized.
Sorry, something went wrong. |
||
.expect(200); | ||
expect(metadataResponse.host_status).to.be('error'); | ||
}); | ||
|
||
it('should return single metadata with status error when agent is not enrolled', async () => { | ||
const { body: metadataResponse } = await supertest | ||
.get(`/api/endpoint/metadata/${notEnrolledHostId}`) | ||
.set('kbn-xsrf', 'xxx') | ||
.expect(200); | ||
expect(metadataResponse.host_status).to.be('error'); | ||
}); | ||
|
||
it('should return metadata list with status error when no agent is not enrolled', async () => { | ||
const { body } = await supertest | ||
.post('/api/endpoint/metadata') | ||
.set('kbn-xsrf', 'xxx') | ||
.expect(200); | ||
expect(body.total).to.eql(2); | ||
expect(body.hosts.length).to.eql(2); | ||
const enrolledHost = body.hosts.filter( | ||
(hostInfo: Record<string, any>) => hostInfo.metadata.host.id === enrolledHostId | ||
); | ||
const notEnrolledHost = body.hosts.filter( | ||
(hostInfo: Record<string, any>) => hostInfo.metadata.host.id === notEnrolledHostId | ||
); | ||
expect(enrolledHost.host_status === 'error'); | ||
expect(notEnrolledHost.host_status === 'error'); | ||
}); | ||
|
||
it('should return metadata list with status only when agent is checked in', async () => { | ||
const { body: checkInResponse } = await supertestWithoutAuth | ||
.post(`/api/ingest_manager/fleet/agents/${enrolledAgentId}/checkin`) | ||
.set('kbn-xsrf', 'xx') | ||
.set( | ||
'Authorization', | ||
`ApiKey ${Buffer.from(`${apiKey.id}:${apiKey.api_key}`).toString('base64')}` | ||
) | ||
.send({ | ||
events: [], | ||
local_metadata: {}, | ||
}) | ||
.expect(200); | ||
|
||
expect(checkInResponse.action).to.be('checkin'); | ||
expect(checkInResponse.success).to.be(true); | ||
|
||
const { body } = await supertest | ||
.post('/api/endpoint/metadata') | ||
.set('kbn-xsrf', 'xxx') | ||
.expect(200); | ||
expect(body.total).to.eql(2); | ||
expect(body.hosts.length).to.eql(2); | ||
const enrolledHost = body.hosts.filter( | ||
(hostInfo: Record<string, any>) => hostInfo.metadata.host.id === enrolledHostId | ||
); | ||
const notEnrolledHost = body.hosts.filter( | ||
(hostInfo: Record<string, any>) => hostInfo.metadata.host.id === notEnrolledHostId | ||
); | ||
expect(enrolledHost.host_status === 'online'); | ||
expect(notEnrolledHost.host_status === 'error'); | ||
}); | ||
|
||
it('should return single metadata with status online when agent status is online', async () => { | ||
await inactivity(); | ||
const { body: checkInResponse } = await supertestWithoutAuth | ||
.post(`/api/ingest_manager/fleet/agents/${enrolledAgentId}/checkin`) | ||
.set('kbn-xsrf', 'xx') | ||
.set( | ||
'Authorization', | ||
`ApiKey ${Buffer.from(`${apiKey.id}:${apiKey.api_key}`).toString('base64')}` | ||
) | ||
.send({ | ||
events: [], | ||
local_metadata: {}, | ||
}) | ||
.expect(200); | ||
|
||
expect(checkInResponse.action).to.be('checkin'); | ||
expect(checkInResponse.success).to.be(true); | ||
|
||
const { body: metadataResponse } = await supertest | ||
.get(`/api/endpoint/metadata/${enrolledHostId}`) | ||
.set('kbn-xsrf', 'xxx') | ||
.expect(200); | ||
expect(metadataResponse.host_status).to.be('online'); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function inactivity() { | ||
return new Promise(resolve => setTimeout(resolve, 35000)); | ||
} |
Binary file added
BIN
+33.4 KB
x-pack/test/functional/es_archives/endpoint/metadata/endpoint_status_feature/data.json.gz
Binary file not shown.
Oops, something went wrong.
kbn-xsrf isn't required for GETs