Skip to content
This repository
Browse code

Merge pull request #24 from fengmk2/support-https

add https.Server support
  • Loading branch information...
commit 993bd8fc8930a63201c392ccd33fab85a2a2cb75 2 parents e1d34a2 + a9cca83
TJ Holowaychuk authored
4 lib/test.js
@@ -6,6 +6,7 @@
6 6 var request = require('superagent')
7 7 , util = require('util')
8 8 , http = require('http')
  9 + , https = require('https')
9 10 , assert = require('assert')
10 11 , Request = request.Request;
11 12
@@ -39,7 +40,8 @@ function Test(app, method, path) {
39 40 var addr = app.address();
40 41 var portno = addr ? addr.port : port++;
41 42 if (!addr) app.listen(portno);
42   - this.url = 'http://127.0.0.1:' + portno + path;
  43 + var protocol = app instanceof https.Server ? 'https' : 'http';
  44 + this.url = protocol + '://127.0.0.1:' + portno + path;
43 45 }
44 46
45 47 /**
16 test/fixtures/test_cert.pem
... ... @@ -0,0 +1,16 @@
  1 +-----BEGIN CERTIFICATE-----
  2 +MIICjzCCAfgCCQCduAjYszOZ3DANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMC
  3 +Q04xEzARBgNVBAgTCkd1YW5nIERvbmcxFDASBgNVBAcTC0d1YW5nIFpob3VlMQ4w
  4 +DAYDVQQKEwVUQkVEUDENMAsGA1UECxMEVEVTVDEQMA4GA1UEAxMHZmVuZ21rMjEg
  5 +MB4GCSqGSIb3DQEJARYRZmVuZ21rMkBnbWFpbC5jb20wHhcNMTIwOTIzMTQxMDI5
  6 +WhcNMTIxMDIzMTQxMDI5WjCBizELMAkGA1UEBhMCQ04xEzARBgNVBAgTCkd1YW5n
  7 +IERvbmcxFDASBgNVBAcTC0d1YW5nIFpob3VlMQ4wDAYDVQQKEwVUQkVEUDENMAsG
  8 +A1UECxMEVEVTVDEQMA4GA1UEAxMHZmVuZ21rMjEgMB4GCSqGSIb3DQEJARYRZmVu
  9 +Z21rMkBnbWFpbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALOEtchk
  10 +KBK8WTqwXR2Aov2mc0+igyQTGbxBDSyyULHPiecMqOBHs5bV4DL1pc/01hLKIp4T
  11 +2j2KNTTmeivrtKd3wMQL7A+IgyqdmeqRi98pYUylFZrHxb9Kiwm7mpHanodmgnTT
  12 +zOluEpi/K9h9zM0DbIOynsOh9/w4E2Aq6JvrAgMBAAEwDQYJKoZIhvcNAQEFBQAD
  13 +gYEAnPd0JvCKQQBrm9jI6TkJKmfBa4NH0wUpMQv/bo2NWw1tA8fTQYb0S4aTep5Q
  14 +JdYctLQeE7abY1fpXFIwFY/FC0rE3alkEK+4PlCXvHGTYMiq90oH0JtlEqYTdTWJ
  15 +i99gtHarMEfzejyY3VDa2XFGmZrQCP6Co5NGDjAEr2A4ECg=
  16 +-----END CERTIFICATE-----
15 test/fixtures/test_key.pem
... ... @@ -0,0 +1,15 @@
  1 +-----BEGIN RSA PRIVATE KEY-----
  2 +MIICXQIBAAKBgQCzhLXIZCgSvFk6sF0dgKL9pnNPooMkExm8QQ0sslCxz4nnDKjg
  3 +R7OW1eAy9aXP9NYSyiKeE9o9ijU05nor67Snd8DEC+wPiIMqnZnqkYvfKWFMpRWa
  4 +x8W/SosJu5qR2p6HZoJ008zpbhKYvyvYfczNA2yDsp7Doff8OBNgKuib6wIDAQAB
  5 +AoGAAp2tdHUZLGS4PCWzxalJNr8FMSTiGlV464hbI8qZaG3oyYgisdn5oPoO4U85
  6 +ElW0BOQTKxCI/pqT+ehd4WP25u+RXBqOSfpIRQvY2RjXmeyrkDEZWATP/BUa/Oqa
  7 +0YitEsAXvt3pQli+LVc9GZSFZQECgwDVdAs4n7DdQlkLwIECQQDmFL9rIE/6wF3h
  8 +fJkvPFs67MJgMF/T4omLnv/FGSH7KBpjFHts9AbPIGjD1dadRpmHxk7ahbSTKMxu
  9 +uoZ1R1irAkEAx73MW4fJDQZDdJHwskYyGXuL99Fcr8xz6YZv75tm5O3eF2a/UvoO
  10 +UIgDGpTIWFrm+gli27p3J0rJhhOiI4JJwQJAYOjUR3bwuRlVcahdjTvK4WLf7Evz
  11 +0PdWH+z0pjwTyAn4M0tpQVb3lz57YiErqEsYV8v7Yqd2i5VfpjQCdlt6yQJBAIpm
  12 +7kph/SLEO0tzsGenEiHsJKFT9bhun8ape7h4YsSwOdrXPC0fzXlptVTe0S+/1Rpe
  13 +FJ0SSGv2e0snIYsfRUECQQCP8VOp3IIE8beytDoqn3QbWvobx94NVhHKUX5UB6C+
  14 +bhY0LpTTFb8VMfSkICZXhbpcKf5zIdRjOh0ZLDeZJl5v
  15 +-----END RSA PRIVATE KEY-----
25 test/supertest.js
... ... @@ -1,5 +1,8 @@
1 1
2 2 var request = require('..')
  3 + , https = require('https')
  4 + , fs = require('fs')
  5 + , path = require('path')
3 6 , express = require('express');
4 7
5 8 describe('request(app)', function(){
@@ -37,6 +40,28 @@ describe('request(app)', function(){
37 40 });
38 41 })
39 42
  43 + it('should work with a https server', function(done){
  44 + var app = express();
  45 +
  46 + app.get('/', function(req, res){
  47 + res.send('hey');
  48 + });
  49 +
  50 + var fixtures = path.join(__dirname, 'fixtures');
  51 + var server = https.createServer({
  52 + key: fs.readFileSync(path.join(fixtures, 'test_key.pem')),
  53 + cert: fs.readFileSync(path.join(fixtures, 'test_cert.pem'))
  54 + }, app);
  55 +
  56 + request(server)
  57 + .get('/')
  58 + .end(function(err, res){
  59 + res.should.have.status(200);
  60 + res.text.should.equal('hey');
  61 + done();
  62 + });
  63 + })
  64 +
40 65 it('should work with .send() etc', function(done){
41 66 var app = express();
42 67

0 comments on commit 993bd8f

Please sign in to comment.
Something went wrong with that request. Please try again.