forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote-ip.js
More file actions
40 lines (36 loc) · 1.21 KB
/
remote-ip.js
File metadata and controls
40 lines (36 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { get } from '../helpers/e2etest.js'
import { expect, jest } from '@jest/globals'
describe('remote ip debugging', () => {
jest.setTimeout(5 * 60 * 1000)
test('basics', async () => {
const res = await get('/_ip')
expect(res.statusCode).toBe(200)
expect(res.header['content-type']).toContain('application/json')
const kv = JSON.parse(res.text)
expect('ip' in kv).toBeTruthy()
expect('x-forwarded-for' in kv).toBeTruthy()
expect('fastly-client-ip' in kv).toBeTruthy()
})
test('carrying the x-forwarded-for header', async () => {
const res = await get('/_ip', {
headers: {
'X-Forwarded-For': '123.123.0.1',
},
})
expect(res.statusCode).toBe(200)
const kv = JSON.parse(res.text)
expect(kv['x-forwarded-for']).toBe('123.123.0.1')
})
test('req.ip becomes the first value from x-forwarded-for', async () => {
const xForwardedFor = '100.0.0.1, 100.0.0.2, 100.0.0.3'
const res = await get('/_ip', {
headers: {
'X-Forwarded-For': xForwardedFor,
},
})
expect(res.statusCode).toBe(200)
const kv = JSON.parse(res.text)
expect(kv.ip).toBe('100.0.0.1')
expect(kv['x-forwarded-for']).toBe(xForwardedFor)
})
})