Skip to content

Commit

Permalink
Merge pull request #391 from prey/revert-json-post
Browse files Browse the repository at this point in the history
Revert push as json and specs
  • Loading branch information
javo authored Jul 23, 2018
2 parents 4bcbd07 + 60b7753 commit f0e4607
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/agent/plugins/control-panel/api/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ var post = function(url, data, opts, cb) {
var opts = opts || {};

if (opts.status) {
opts.headers = { 'X-Prey-Status': opts.status };
var stats = JSON.stringify(opts.status);
opts.headers = { 'X-Prey-Status': stats };
delete opts['status'];
}
if (!opts.user_agent) opts.user_agent = common.system.user_agent;
if (!opts.json) opts.json = true;
if (!opts.user_agent)
opts.user_agent = common.system.user_agent;

request.post(url, data, opts, cb)
}
Expand Down
90 changes: 90 additions & 0 deletions lib/agent/plugins/control-panel/api/test/push_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
var sinon = require('sinon'),
should = require('should'),
keys = require('./../keys'),
request = require('./../request'),
push = require('./../push');

var data_spec = {
specs: {
processor_info: {
model: 'Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz',
speed: '1800',
cores: '4'
},
network_interfaces_list: [],
ram_module_list: [],
firmware_info: { device_type: 'Laptop',
model_name: 'MacBook',
vendor_name: 'Apple',
bios_vendor: 'Apple',
bios_version: 'MBAXX',
mb_version: '2.27f2',
serial_number: 'XXXXXXXXXXXXXs',
}
}
};

var opts_spec = {
multipart: false
}

var opts_json_spec = {
multipart: false,
json: true
}

var args;

describe('push', function() {
var keys_present_stub;
var keys_get_stub;
var post_stub;

before(function() {
keys_present_stub = sinon.stub(keys, 'present', function() {
return true;
})
keys_get_stub = sinon.stub(keys, 'get', function() {
return { api: 'aaaaaaaaaa', device: 'bbbbbb' }
})
post_stub = sinon.stub(request, 'post', function(url, data, opts, cb) {
args = opts;
cb();
})
})

after(function() {
keys_present_stub.restore();
keys_get_stub.restore();
post_stub.restore();
})

describe('all requests', function() {
it('includes user agent prey', function(done) {
push.response(data_spec, opts_spec, function(err, resp, body) {
args.user_agent.should.exist;
args.user_agent.should.containEql('Prey/')
done();
})
})
})

describe('when includes json true', function() {
it('includes the content-type as json', function(done) {
push.event(data_spec, opts_json_spec, function(err, resp, body) {
args.json.should.exist;
args.json.should.be.equal(true);
done();
})
})
})

describe('when doesnt include json option', function() {
it('includes the content-type as url-encoded', function(done) {
push.event(data_spec, opts_spec, function(err, resp, body) {
should.not.exist(args.json);
done();
})
})
})
})
3 changes: 2 additions & 1 deletion lib/agent/triggers/control-zones/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ var push_event = function(type, zone_id, coords) {
name: type,
info: coords
}
api.push['event'](data);
var opts = { json: true };
api.push['event'](data, opts);
}

var getDistance = function(latlng1, latlng2) {
Expand Down
2 changes: 1 addition & 1 deletion lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var send_update_event = function(status, old_version, new_version, cb) {
}
}

api.push['event'](data, {}, function(err, res) {
api.push['event'](data, {json: true}, function(err, res) {
if (err || res.statusCode != 200)
return cb(new Error("Error sending the upgrade event"));
else {
Expand Down

0 comments on commit f0e4607

Please sign in to comment.