Skip to content
Browse files

add https.Server support

  • Loading branch information...
1 parent e1d34a2 commit a9cca8392f302e076a4e51372956449d69b40aaa @fengmk2 fengmk2 committed Sep 24, 2012
Showing with 59 additions and 1 deletion.
  1. +3 −1 lib/test.js
  2. +16 −0 test/fixtures/test_cert.pem
  3. +15 −0 test/fixtures/test_key.pem
  4. +25 −0 test/supertest.js
View
4 lib/test.js
@@ -6,6 +6,7 @@
var request = require('superagent')
, util = require('util')
, http = require('http')
+ , https = require('https')
, assert = require('assert')
, Request = request.Request;
@@ -39,7 +40,8 @@ function Test(app, method, path) {
var addr = app.address();
var portno = addr ? addr.port : port++;
if (!addr) app.listen(portno);
- this.url = 'http://127.0.0.1:' + portno + path;
+ var protocol = app instanceof https.Server ? 'https' : 'http';
+ this.url = protocol + '://127.0.0.1:' + portno + path;
}
/**
View
16 test/fixtures/test_cert.pem
@@ -0,0 +1,16 @@
+-----BEGIN CERTIFICATE-----
+MIICjzCCAfgCCQCduAjYszOZ3DANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMC
+Q04xEzARBgNVBAgTCkd1YW5nIERvbmcxFDASBgNVBAcTC0d1YW5nIFpob3VlMQ4w
+DAYDVQQKEwVUQkVEUDENMAsGA1UECxMEVEVTVDEQMA4GA1UEAxMHZmVuZ21rMjEg
+MB4GCSqGSIb3DQEJARYRZmVuZ21rMkBnbWFpbC5jb20wHhcNMTIwOTIzMTQxMDI5
+WhcNMTIxMDIzMTQxMDI5WjCBizELMAkGA1UEBhMCQ04xEzARBgNVBAgTCkd1YW5n
+IERvbmcxFDASBgNVBAcTC0d1YW5nIFpob3VlMQ4wDAYDVQQKEwVUQkVEUDENMAsG
+A1UECxMEVEVTVDEQMA4GA1UEAxMHZmVuZ21rMjEgMB4GCSqGSIb3DQEJARYRZmVu
+Z21rMkBnbWFpbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALOEtchk
+KBK8WTqwXR2Aov2mc0+igyQTGbxBDSyyULHPiecMqO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
+7kph/SLEO0tzsGenEiHsJKFT9bhun8ape7h4YsSwOdrXPC0fzXlptVTe0S+/1Rpe
+FJ0SSGv2e0snIYsfRUECQQCP8VOp3IIE8beytDoqn3QbWvobx94NVhHKUX5UB6C+
+bhY0LpTTFb8VMfSkICZXhbpcKf5zIdRjOh0ZLDeZJl5v
+-----END RSA PRIVATE KEY-----
View
25 test/supertest.js
@@ -1,5 +1,8 @@
var request = require('..')
+ , https = require('https')
+ , fs = require('fs')
+ , path = require('path')
, express = require('express');
describe('request(app)', function(){
@@ -37,6 +40,28 @@ describe('request(app)', function(){
});
})
+ it('should work with a https server', function(done){
+ var app = express();
+
+ app.get('/', function(req, res){
+ res.send('hey');
+ });
+
+ var fixtures = path.join(__dirname, 'fixtures');
+ var server = https.createServer({
+ key: fs.readFileSync(path.join(fixtures, 'test_key.pem')),
+ cert: fs.readFileSync(path.join(fixtures, 'test_cert.pem'))
+ }, app);
+
+ request(server)
+ .get('/')
+ .end(function(err, res){
+ res.should.have.status(200);
+ res.text.should.equal('hey');
+ done();
+ });
+ })
+
it('should work with .send() etc', function(done){
var app = express();

0 comments on commit a9cca83

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