Skip to content
This repository has been archived by the owner on Jan 7, 2018. It is now read-only.

Commit

Permalink
Add some missing tests for ip geocoding during logging functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
GUI committed Sep 23, 2015
1 parent 22cbec7 commit 6fc65e7
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/integration/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var _ = require('lodash'),
apiUmbrellaConfig = require('api-umbrella-config'),
async = require('async'),
Curler = require('curler').Curler,
crypto = require('crypto'),
execFile = require('child_process').execFile,
Factory = require('factory-lady'),
mkdirp = require('mkdirp'),
Expand Down Expand Up @@ -322,6 +323,67 @@ describe('logging', function() {
}.bind(this));
});

it('logs the geocoded ip related fields', function(done) {
this.timeout(4500);
var options = _.merge({}, this.options, {
headers: {
'X-Forwarded-For': '8.8.8.8',
},
});

request.get('http://localhost:9080/info/', options, function(error, response) {
should.not.exist(error);
response.statusCode.should.eql(200);
waitForLog(this.uniqueQueryId, function(error, response, hit, record) {
should.not.exist(error);
record.request_ip.should.eql('8.8.8.8');
record.request_ip_country.should.eql('US');
record.request_ip_region.should.eql('CA');
record.request_ip_city.should.eql('Mountain View');
record.request_ip_location.should.eql({
lat: 37.386,
lon: -122.0838,
});

done();
}.bind(this));
}.bind(this));
});

it('stores the most recently seen geocode for city in a separate index', function(done) {
this.timeout(4500);
var options = _.merge({}, this.options, {
headers: {
'X-Forwarded-For': '8.8.8.8',
},
});

request.get('http://localhost:9080/info/', options, function(error, response) {
should.not.exist(error);
response.statusCode.should.eql(200);
waitForLog(this.uniqueQueryId, function(error) {
should.not.exist(error);
global.elasticsearch.get({
index: 'api-umbrella',
type: 'city',
id: crypto.createHash('sha256').update('US-CA-Mountain View').digest('hex'),
}, function(error, res) {
should.not.exist(error);
_.omit(res._source, 'updated_at').should.eql({
country: 'US',
region: 'CA',
city: 'Mountain View',
location: {
lat: 37.386,
lon: -122.0838,
},
});
done();
});
}.bind(this));
}.bind(this));
});

it('logs the accept-encoding header prior to normalization', function(done) {
this.timeout(4500);
var options = _.merge({}, this.options, {
Expand Down

0 comments on commit 6fc65e7

Please sign in to comment.