koa-lite/test/request/ip.js

33 lines
875 B
JavaScript
Raw Permalink Normal View History

2014-07-06 08:43:14 +00:00
'use strict';
2014-07-06 08:43:14 +00:00
var request = require('../context').request;
describe('req.ip', function(){
describe('with req.ips present', function(){
it('should return req.ips[0]', function(){
var req = request();
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');
})
})
describe('with no req.ips present', function(){
2015-09-26 14:23:17 +00:00
it('should return req.socket.remoteAddress', function(){
2014-07-06 08:43:14 +00:00
var req = request();
req.socket.remoteAddress = '127.0.0.2';
req.ip.should.equal('127.0.0.2');
})
2015-10-03 01:49:20 +00:00
describe('with req.socket.remoteAddress not present', function(){
2015-10-03 00:18:05 +00:00
it('should return an empty string', function(){
var req = request();
req.socket.remoteAddress = null;
req.ip.should.equal('');
})
})
2014-07-06 08:43:14 +00:00
})
})