wazuh-kibana-app/test/server/wazuh-api.js

148 lines
4.5 KiB
JavaScript
Raw Normal View History

2018-09-10 08:32:49 +00:00
const chai = require('chai');
const needle = require('needle');
2018-09-03 09:46:55 +00:00
chai.should();
2018-09-10 08:32:49 +00:00
const headers = {
headers: { 'kbn-xsrf': 'kibana', 'Content-Type': 'application/json' }
};
2018-09-03 09:46:55 +00:00
2018-09-10 08:32:49 +00:00
let API_ID = null;
2018-09-03 09:46:55 +00:00
let API_PORT = null;
2018-09-10 08:32:49 +00:00
let API_URL = null;
2018-09-03 09:46:55 +00:00
let API_USER = null;
describe('wazuh-api', () => {
2018-09-10 08:32:49 +00:00
before(async () => {
2018-11-02 17:23:00 +00:00
const res = await needle('get', `localhost:5601/elastic/apis`, {}, {});
2018-09-11 09:52:54 +00:00
/* eslint-disable */
2018-09-10 08:32:49 +00:00
if (!res.body || !res.body.length) {
console.log('There are no APIs stored in Elasticsearch, exiting...');
process.exit(1);
}
2018-09-11 09:52:54 +00:00
/* eslint-enable */
2018-09-10 08:32:49 +00:00
API_ID = res.body[0]._id;
API_URL = res.body[0]._source.url;
API_PORT = res.body[0]._source.api_port;
API_USER = res.body[0]._source.api_user;
});
2018-09-03 09:46:55 +00:00
2018-10-01 07:56:50 +00:00
it('POST /api/csv', async () => {
2018-09-10 08:32:49 +00:00
const res = await needle(
'post',
2018-10-01 07:56:50 +00:00
`localhost:5601/api/csv`,
2018-09-10 08:32:49 +00:00
{ path: '/agents', id: API_ID },
headers
);
res.body.should.be.a('string');
});
2018-09-03 09:46:55 +00:00
2018-10-01 07:56:50 +00:00
it('POST /api/check-api', async () => {
2018-09-10 08:32:49 +00:00
const res = await needle(
'post',
2018-10-01 07:56:50 +00:00
`localhost:5601/api/check-api`,
2018-09-10 08:32:49 +00:00
{ user: API_USER, url: API_URL, port: API_PORT, id: API_ID },
headers
);
res.body.should.be.a('object');
res.body.manager.should.be.a('string');
res.body.cluster.should.be.a('string');
res.body.status.should.be.a('string');
});
2018-09-03 09:46:55 +00:00
2018-10-01 07:56:50 +00:00
it('POST /api/check-stored-api', async () => {
2018-09-10 08:32:49 +00:00
const res = await needle(
'post',
2018-10-01 07:56:50 +00:00
`localhost:5601/api/check-stored-api`,
2018-09-10 08:32:49 +00:00
API_ID,
headers
);
res.body.should.be.a('object');
res.body.statusCode.should.be.eql(200);
res.body.data.should.be.a('object');
res.body.data.user.should.be.a('string');
res.body.data.password.should.be.a('string');
res.body.data.url.should.be.a('string');
res.body.data.port.should.be.a('string');
res.body.data.extensions.should.be.a('object');
2018-09-10 08:32:49 +00:00
res.body.data.cluster_info.should.be.a('object');
});
2018-09-03 09:46:55 +00:00
2018-10-01 07:56:50 +00:00
it('POST /api/request', async () => {
2018-09-10 08:32:49 +00:00
const res = await needle(
'post',
2018-10-01 07:56:50 +00:00
`localhost:5601/api/request`,
2018-09-10 08:32:49 +00:00
{ method: 'GET', path: '/agents/000', body: {}, id: API_ID },
headers
);
res.body.should.be.a('object');
res.body.error.should.be.eql(0);
res.body.data.should.be.a('object');
res.body.data.status.should.be.eql('Active');
res.body.data.id.should.be.eql('000');
});
2018-09-03 09:46:55 +00:00
2018-10-01 07:56:50 +00:00
it('GET /api/pci/{requirement}', async () => {
2018-11-02 17:23:00 +00:00
const res = await needle('get', `localhost:5601/api/pci/all`, {}, {});
2018-09-10 08:32:49 +00:00
res.body.should.be.a('object');
res.body['1.1.1'].should.be.eql(
'A formal process for approving and testing all network connections and changes to the firewall and router configurations'
);
});
2018-09-03 09:46:55 +00:00
2018-10-01 07:56:50 +00:00
it('GET /api/gdpr/{requirement}', async () => {
2018-11-02 17:23:00 +00:00
const res = await needle('get', `localhost:5601/api/gdpr/all`, {}, {});
2018-09-10 08:32:49 +00:00
res.body.should.be.a('object');
res.body['II_5.1.f'].should.be.eql(
'Ensure the ongoing confidentiality, integrity, availability and resilience of processing systems and services, verifying its modifications, accesses, locations and guarantee the safety of them.<br>File sharing protection and file sharing technologies that meet the requirements of data protection.'
);
});
2018-09-03 09:46:55 +00:00
2018-10-01 07:56:50 +00:00
it('GET /utils/configuration', async () => {
2018-09-10 08:32:49 +00:00
const res = await needle(
'get',
2018-10-01 07:56:50 +00:00
`localhost:5601/utils/configuration`,
2018-09-10 08:32:49 +00:00
{},
{}
);
res.body.should.be.a('object');
res.body.error.should.be.eql(0);
res.body.statusCode.should.be.eql(200);
res.body.data.should.be.a('object');
});
2018-09-03 09:46:55 +00:00
2018-10-01 07:56:50 +00:00
it('GET /utils/memory', async () => {
const res = await needle('get', `localhost:5601/utils/memory`, {}, {});
2018-09-10 08:32:49 +00:00
res.body.should.be.a('object');
res.body.error.should.be.eql(0);
res.body.ram.should.be.gt(1);
});
2018-09-03 09:46:55 +00:00
2018-10-01 07:56:50 +00:00
it('GET /api/agents-unique/{api}', async () => {
2018-09-10 08:32:49 +00:00
const res = await needle(
'get',
2018-10-01 07:56:50 +00:00
`localhost:5601/api/agents-unique/${API_ID}`,
2018-09-10 08:32:49 +00:00
{},
{}
);
res.body.should.be.a('object');
res.body.error.should.be.eql(0);
res.body.result.should.be.a('object');
res.body.result.groups.should.be.a('array');
res.body.result.nodes.should.be.a('array');
res.body.result.versions.should.be.a('array');
res.body.result.osPlatforms.should.be.a('array');
res.body.result.lastAgent.should.be.a('object');
res.body.result.summary.should.be.a('object');
});
2018-09-03 09:46:55 +00:00
2018-10-01 07:56:50 +00:00
it('GET /utils/logs', async () => {
2018-11-02 17:23:00 +00:00
const res = await needle('get', `localhost:5601/utils/logs`, {}, {});
2018-09-10 08:32:49 +00:00
res.body.should.be.a('object');
res.body.lastLogs.should.be.a('array');
res.body.error.should.be.eql(0);
});
});