-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1163 from alphagov/revert-1154-revert-1151-pp_570…
…9_ip_address_in_auth_request Revert "Revert "PP-5709: add ip address to auth request""
- Loading branch information
Showing
9 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
module.exports = req => { | ||
const xHeaderIpAddress = req.headers['x-forwarded-for'] | ||
let ipAddress | ||
if (xHeaderIpAddress !== undefined) { | ||
ipAddress = xHeaderIpAddress.split(',')[0] | ||
} else { | ||
ipAddress = (req.connection && req.connection.remoteAddress) || | ||
(req.socket && req.socket.remoteAddress) || | ||
(req.connection && req.connection.socket && req.connection.socket.remoteAddress) | ||
} | ||
return ipAddress !== undefined ? ipAddress.toString().trim() : null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const expect = require('chai').expect | ||
|
||
const userIpAddress = require('../../app/utils/user_ip_address') | ||
|
||
describe('user ip address', () => { | ||
it('returns the address provided in x-forwarded-for header', () => { | ||
const result = userIpAddress({ | ||
headers: { 'x-forwarded-for': '127.0.0.1, 0.0.0.0' }, | ||
connection: { remoteAddress: '0.0.0.0', socket: { remoteAddress: '0.0.0.0' } }, | ||
socket: { remoteAddress: '0.0.0.0' } | ||
}) | ||
expect(result).to.equal('127.0.0.1') | ||
}) | ||
|
||
it('returns the address provided as connection remote address', () => { | ||
const result = userIpAddress({ | ||
headers: {}, | ||
connection: { remoteAddress: '127.0.0.1', socket: { remoteAddress: '0.0.0.0' } }, | ||
socket: { remoteAddress: '0.0.0.0' } | ||
}) | ||
expect(result).to.equal('127.0.0.1') | ||
}) | ||
|
||
it('returns the address provided as socket remote address', () => { | ||
const result = userIpAddress({ | ||
headers: {}, | ||
socket: { remoteAddress: '127.0.0.1' }, | ||
connection: { socket: { remoteAddress: '0.0.0.0' } } | ||
}) | ||
expect(result).to.equal('127.0.0.1') | ||
}) | ||
|
||
it('returns the address provided as connection socket remote address', () => { | ||
const result = userIpAddress({ | ||
headers: {}, | ||
connection: { socket: { remoteAddress: '127.0.0.1' } } | ||
}) | ||
expect(result).to.equal('127.0.0.1') | ||
}) | ||
}) |