2014-07-06 08:43:14 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-12 04:59:30 +00:00
|
|
|
const request = require('../helpers/context').request;
|
2014-07-06 08:43:14 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('req.ip', () => {
|
|
|
|
describe('with req.ips present', () => {
|
|
|
|
it('should return req.ips[0]', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2014-07-06 08:43:14 +00:00
|
|
|
req.app.proxy = true;
|
|
|
|
req.header['x-forwarded-for'] = '127.0.0.1';
|
|
|
|
req.socket.remoteAddress = '127.0.0.2';
|
|
|
|
req.ip.should.equal('127.0.0.1');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-07-06 08:43:14 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('with no req.ips present', () => {
|
|
|
|
it('should return req.socket.remoteAddress', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2014-07-06 08:43:14 +00:00
|
|
|
req.socket.remoteAddress = '127.0.0.2';
|
|
|
|
req.ip.should.equal('127.0.0.2');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
2015-10-03 01:49:20 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('with req.socket.remoteAddress not present', () => {
|
|
|
|
it('should return an empty string', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2015-10-03 00:18:05 +00:00
|
|
|
req.socket.remoteAddress = null;
|
|
|
|
req.ip.should.equal('');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|