deno.land / x / opine@2.3.4 / test / units / req.ips.test.ts

req.ips.test.ts
نووسراو ببینە
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { opine } from "../../mod.ts";import { superdeno } from "../deps.ts";import { describe, it } from "../utils.ts";
describe("req", function () { describe(".ips", function () { describe("when X-Forwarded-For is present", function () { describe('when "trust proxy" is enabled', function () { it("should return an array of the specified addresses", function ( done, ) { const app = opine();
app.enable("trust proxy");
app.use(function (req, res, _next) { res.send(req.ips); });
superdeno(app) .get("/") .set("X-Forwarded-For", "client, p1, p2") .expect('["client","p1","p2"]', done); });
it("should stop at first untrusted", function (done) { const app = opine();
app.set("trust proxy", 2);
app.use(function (req, res, _next) { res.send(req.ips); });
superdeno(app) .get("/") .set("X-Forwarded-For", "client, p1, p2") .expect('["p1","p2"]', done); }); });
describe('when "trust proxy" is disabled', function () { it("should return an empty array", function (done) { const app = opine();
app.use(function (req, res, _next) { res.send(req.ips); });
superdeno(app) .get("/") .set("X-Forwarded-For", "client, p1, p2") .expect("[]", done); }); }); });
describe("when X-Forwarded-For is not present", function () { it("should return []", function (done) { const app = opine();
app.use(function (req, res, _next) { res.send(req.ips); });
superdeno(app) .get("/") .expect("[]", done); }); }); });});
opine

Version Info

Tagged at
2 years ago