Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hash parameter to GET/agents/groups/:group_id/files API call #166

Merged
merged 4 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
### Added
- Added support for queries in agents, rootcheck and syscheck API requests ([#128](https:/wazuh/wazuh-api/pull/128))
- Added API support for multigroups ([#159](https:/wazuh/wazuh-api/pull/159))
- Add `hash` parameter to GET/agents/groups/:group_id/files API call ([#166](https:/wazuh/wazuh-api/pull/166))
- Add GET/agents/:agent_id/config/:component/:configuration call ([#72](https:/wazuh/wazuh-api/pull/72)).

### Changed
Expand Down
Empty file modified controllers/active_response.js
100644 → 100755
Empty file.
9 changes: 6 additions & 3 deletions controllers/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ router.get('/groups/:group_id/configuration', cache(), function(req, res) {
* @apiName GetAgentGroupFile
* @apiGroup Groups
*
* @apiParam {String} group_id Group ID.
* @apiParam {String} file_name Filename
* @apiParam {String} [group_id] Group ID.
* @apiParam {String} [file_name] Filename
* @apiParam {String="conf","rootkit_files", "rootkit_trojans", "rcl"} [type] Type of file.
*
* @apiDescription Returns the specified file belonging to the group parsed to JSON.
Expand Down Expand Up @@ -274,6 +274,7 @@ router.get('/groups/:group_id/files/:filename', cache(), function(req, res) {
* @apiParam {Number} [limit=500] Maximum number of elements to return.
* @apiParam {String} [sort] Sorts the collection by a field or fields (separated by comma). Use +/- at the beginning to list in ascending or descending order.
* @apiParam {String} [search] Looks for elements with the specified string.
* @apiParam {String} [hash] Hash algorithm to use to calculate files checksums.
*
* @apiDescription Returns the files belonging to the group.
*
Expand All @@ -287,7 +288,7 @@ router.get('/groups/:group_id/files', cache(), function(req, res) {
req.apicacheGroup = "agents";

var data_request = {'function': '/agents/groups/:group_id/files', 'arguments': {}};
var filters = {'offset': 'numbers', 'limit': 'numbers', 'sort':'sort_param', 'search':'search_param'};
var filters = {'offset': 'numbers', 'limit': 'numbers', 'sort':'sort_param', 'search':'search_param', 'hash':'names'};

if (!filter.check(req.query, filters, req, res)) // Filter with error
return;
Expand All @@ -300,6 +301,8 @@ router.get('/groups/:group_id/files', cache(), function(req, res) {
data_request['arguments']['sort'] = filter.sort_param_to_json(req.query.sort);
if ('search' in req.query)
data_request['arguments']['search'] = filter.search_param_to_json(req.query.search);
if ('hash' in req.query)
data_request['arguments']['hash_algorithm'] = req.query.hash;

if (!filter.check(req.params, {'group_id':'names'}, req, res)) // Filter with error
return;
Expand Down
Empty file modified models/wazuh-api.py
100644 → 100755
Empty file.
66 changes: 66 additions & 0 deletions test/test_agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ describe('Agents', function() {

res.body.data.should.be.an.array;
res.body.data.should.have.properties(['totalItems','items']);
res.body.data[0].should.have.properties(['count','mergedSum','configSum','name']);
res.body.data.items.should.be.instanceOf(Array);

done();
Expand All @@ -1165,6 +1166,38 @@ describe('Agents', function() {
});
});

it('Hash algorithm', function(done) {
request(common.url)
.get("/agents/groups?hash=sha256")
.auth(common.credentials.user, common.credentials.password)
.expect("Content-type",/json/)
.expect(200)
.end(function(err,res){
if (err) return done(err);

res.body.should.have.properties(['error', 'data']);
res.body.error.should.equal(0);
res.body.data.should.have.properties(['totalItems','items']);
res.body.data.items[0].should.have.properties(['count','mergedSum','configSum','name']);
done();
});
});

it('Wrong Hash algorithm', function(done) {
request(common.url)
.get("/agents/groups?hash=aaaaaa")
.auth(common.credentials.user, common.credentials.password)
.expect("Content-type",/json/)
.expect(200)
.end(function(err,res){
if (err) return done(err);

res.body.should.have.properties(['error', 'message']);
res.body.error.should.equal(1723);
done();
});
});

}); // GET/agents/groups

describe('GET/agents/groups/:group_id', function() {
Expand Down Expand Up @@ -1337,6 +1370,7 @@ describe('Agents', function() {

res.body.should.have.properties(['error', 'data']);
res.body.error.should.equal(0);
res.body.data[0].should.have.properties(['hash','filename']);
done();
});
});
Expand Down Expand Up @@ -1371,6 +1405,38 @@ describe('Agents', function() {
});
});

it('Hash algorithm', function(done) {
request(common.url)
.get("/agents/groups/webserver/files?hash=sha256")
.auth(common.credentials.user, common.credentials.password)
.expect("Content-type",/json/)
.expect(200)
.end(function(err,res){
if (err) return done(err);

res.body.should.have.properties(['error', 'data']);
res.body.error.should.equal(0);
res.body.data.should.have.properties(['totalItems','items']);
res.body.data.items[0].should.have.properties(['hash','filename']);
done();
});
});

it('Wrong Hash algorithm', function(done) {
request(common.url)
.get("/agents/groups/webserver/files?hash=aaaaaa")
.auth(common.credentials.user, common.credentials.password)
.expect("Content-type",/json/)
.expect(200)
.end(function(err,res){
if (err) return done(err);

res.body.should.have.properties(['error', 'message']);
res.body.error.should.equal(1723);
done();
});
});

}); // GET/agents/groups/:group_id/files

describe('GET/agents/groups/:group_id/files/:filename', function() {
Expand Down