docs: update homepage link http to https (#5920)
[express.git] / test / req.secure.js
blob0097ed6136ebc75c4bc5898a3fe82a53130471a3
1 'use strict'
3 var express = require('../')
4 , request = require('supertest');
6 describe('req', function(){
7 describe('.secure', function(){
8 describe('when X-Forwarded-Proto is missing', function(){
9 it('should return false when http', function(done){
10 var app = express();
12 app.get('/', function(req, res){
13 res.send(req.secure ? 'yes' : 'no');
14 });
16 request(app)
17 .get('/')
18 .expect('no', done)
23 describe('.secure', function(){
24 describe('when X-Forwarded-Proto is present', function(){
25 it('should return false when http', function(done){
26 var app = express();
28 app.get('/', function(req, res){
29 res.send(req.secure ? 'yes' : 'no');
30 });
32 request(app)
33 .get('/')
34 .set('X-Forwarded-Proto', 'https')
35 .expect('no', done)
38 it('should return true when "trust proxy" is enabled', function(done){
39 var app = express();
41 app.enable('trust proxy');
43 app.get('/', function(req, res){
44 res.send(req.secure ? 'yes' : 'no');
45 });
47 request(app)
48 .get('/')
49 .set('X-Forwarded-Proto', 'https')
50 .expect('yes', done)
53 it('should return false when initial proxy is http', function(done){
54 var app = express();
56 app.enable('trust proxy');
58 app.get('/', function(req, res){
59 res.send(req.secure ? 'yes' : 'no');
60 });
62 request(app)
63 .get('/')
64 .set('X-Forwarded-Proto', 'http, https')
65 .expect('no', done)
68 it('should return true when initial proxy is https', function(done){
69 var app = express();
71 app.enable('trust proxy');
73 app.get('/', function(req, res){
74 res.send(req.secure ? 'yes' : 'no');
75 });
77 request(app)
78 .get('/')
79 .set('X-Forwarded-Proto', 'https, http')
80 .expect('yes', done)
83 describe('when "trust proxy" trusting hop count', function () {
84 it('should respect X-Forwarded-Proto', function (done) {
85 var app = express();
87 app.set('trust proxy', 1);
89 app.get('/', function (req, res) {
90 res.send(req.secure ? 'yes' : 'no');
91 });
93 request(app)
94 .get('/')
95 .set('X-Forwarded-Proto', 'https')
96 .expect('yes', done)