Skip to content

Commit

Permalink
Mocha Testing changes (#48)
Browse files Browse the repository at this point in the history
* Mocha Testing changes
* Removed deprecated dependency 'supertest-as-promised'
* Maintaining testing format consistency
* Added tests to verify that server does not always bind to both HTTP and HTTPS ports (#46)

* reverted to using promises instead of done() callback

* Added more node versions to run mocha tests

* removing testing for node v0.10, since when presented with any SSL files, it asks for a passphrase, effectively halting the testing

* tweaked CHANGELOG

* updated CHANGELOG and downgraded dangerjs to v0.8.0

* re-upgraded dangerjs to 0.11.2

* dropping travis-CI support for node v0.12 to node v5 for now

* fixed POST requests checking for 200 code when verify is set to true
  • Loading branch information
tejashah88 authored and dblock committed Jan 31, 2017
1 parent 9e1b2a9 commit c92fbc3
Show file tree
Hide file tree
Showing 13 changed files with 395 additions and 126 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
language: node_js

node_js:
- 6.1

sudo: false

node_js:
- '6'
- '7'

cache:
directories:
- node_modules
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### 2.3.2 (Next)

* [#48](https://github.com/alexa-js/alexa-app-server/pull/48): Added more node versions to run mocha tests on Travis-CI - [@tejashah88](https://github.com/tejashah88).
* [#48](https://github.com/alexa-js/alexa-app-server/pull/48): Removed deprecated dependency 'supertest-as-promised' - [@tejashah88](https://github.com/tejashah88).
* [#48](https://github.com/alexa-js/alexa-app-server/pull/48): Added tests to verify that server does not always bind to both HTTP and HTTPS ports [#46](https://github.com/alexa-js/alexa-app-server/issues/46) - [@tejashah88](https://github.com/tejashah88).
* [#48](https://github.com/alexa-js/alexa-app-server/pull/48): Added more node versions to run mocha tests on Travis-CI - [@tejashah88](https://github.com/tejashah88).
* [#51](https://github.com/alexa-js/alexa-app-server/pull/51): Enable `strictHeaderCheck` in verifier middleware [#50](https://github.com/alexa-js/alexa-app-server/issues/50) - [@mreinstein](https://github.com/mreinstein).
* [#45](https://github.com/alexa-js/alexa-app-server/pull/45): Added support for ca chain certificates [#17](https://github.com/alexa-js/alexa-app-server/pull/17) - [@tejashah88](https://github.com/tejashah88).
* [#45](https://github.com/alexa-js/alexa-app-server/pull/45): Added option to specify passphrase for unlocking specified SSL files - [@tejashah88](https://github.com/tejashah88).
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
"mocha": "^3.2.0",
"chai": "^3.5.0",
"supertest": "^3.0.0",
"supertest-as-promised": "^4.0.2",
"istanbul": "0.4.5",
"coveralls": "^2.11.15",
"danger": "0.10.0"
"danger": "0.11.2"
}
}
2 changes: 1 addition & 1 deletion test/test-examples-server-app-loading-fail-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var chai = require("chai");
var expect = chai.expect;
chai.config.includeStack = true;
var request = require("supertest-as-promised");
var request = require("supertest");
var alexaAppServer = require("../index");

describe("Alexa App Server with invalid examples", function() {
Expand Down
2 changes: 1 addition & 1 deletion test/test-examples-server-custom-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var chai = require("chai");
var expect = chai.expect;
chai.config.includeStack = true;
var request = require("supertest-as-promised");
var request = require("supertest");
var alexaAppServer = require("../index");

describe("Alexa App Server with Examples & Custom Server Bindings", function() {
Expand Down
2 changes: 1 addition & 1 deletion test/test-examples-server-debug-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var chai = require("chai");
var expect = chai.expect;
chai.config.includeStack = true;
var request = require("supertest-as-promised");
var request = require("supertest");
var alexaAppServer = require("../index");

describe("Alexa App Server with Examples & App loading fail checking", function() {
Expand Down
96 changes: 63 additions & 33 deletions test/test-examples-server-https-fail-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var chai = require("chai");
var expect = chai.expect;
chai.config.includeStack = true;
var request = require("supertest-as-promised");
var request = require("supertest");
var alexaAppServer = require("../index");

describe("Alexa App Server with Examples & HTTPS fail checking", function() {
Expand All @@ -28,45 +28,74 @@ describe("Alexa App Server with Examples & HTTPS fail checking", function() {
});

it("fails to mount due to invalid private key and certificate", function() {
testServer = alexaAppServer.start({
port: 3000,
server_root: 'invalid_examples',
httpsEnabled: true,
httpsPort: 6000,
privateKey: 'invalid-private-key.pem',
certificate: 'invalid-cert.cer'
});
testServer = alexaAppServer.start({
port: 3000,
server_root: 'invalid_examples',
httpsEnabled: true,
httpsPort: 6000,
privateKey: 'invalid-private-key.pem',
certificate: 'invalid-cert.cer'
});

return request(testServer.express)
.get('/')
.expect(200).then(function(response) {
expect(response.text).to.contain("alexa-app-server is running");
}
);
return request(testServer.express)
.get('/')
.expect(200).then(function(response) {
expect(response.text).to.contain("alexa-app-server is running");
});
});

it("fails to mount due to invalid CA chain file", function() {
testServer = alexaAppServer.start({
port: 3000,
server_root: 'invalid_examples',
httpsEnabled: true,
httpsPort: 6000,
privateKey: 'private-key.pem',
certificate: 'cert.cer',
chain: 'invalid-cert.ca_bundle'
testServer = alexaAppServer.start({
port: 3000,
server_root: 'invalid_examples',
httpsEnabled: true,
httpsPort: 6000,
privateKey: 'private-key.pem',
certificate: 'cert.cer',
chain: 'invalid-cert.ca_bundle'
});

return request(testServer.express)
.get('/')
.expect(200).then(function(response) {
expect(response.text).to.contain("alexa-app-server is running");
});
});

it("fails to mount due to no passphrase given", function() {
testServer = alexaAppServer.start({
port: 3000,
server_root: 'invalid_examples',
httpsEnabled: true,
httpsPort: 6000,
privateKey: 'private-key.pem',
certificate: 'cert.cer',
chain: 'cert.ca_bundle'
});

return request(testServer.express)
.get('/')
.expect(200).then(function(response) {
expect(response.text).to.contain("alexa-app-server is running");
});
});

it("fails to mount due to invalid passphrase", function() {
testServer = alexaAppServer.start({
port: 3000,
server_root: 'invalid_examples',
httpsEnabled: true,
httpsPort: 6000,
privateKey: 'private-key.pem',
certificate: 'cert.cer',
chain: 'cert.ca_bundle',
passphrase: "test321"
testServer = alexaAppServer.start({
port: 3000,
server_root: 'invalid_examples',
httpsEnabled: true,
httpsPort: 6000,
privateKey: 'private-key.pem',
certificate: 'cert.cer',
chain: 'cert.ca_bundle',
passphrase: "test321"
});

return request(testServer.express)
.get('/')
.expect(200).then(function(response) {
expect(response.text).to.contain("alexa-app-server is running");
});
});

Expand All @@ -77,7 +106,8 @@ describe("Alexa App Server with Examples & HTTPS fail checking", function() {
httpsEnabled: true,
httpsPort: -1,
privateKey: 'private-key.pem',
certificate: 'cert.cer'
certificate: 'cert.cer',
passphrase: "test123"
});

return request(testServer.express)
Expand Down
183 changes: 183 additions & 0 deletions test/test-examples-server-https-support-extended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*jshint expr: true*/
"use strict";
var chai = require("chai");
var expect = chai.expect;
chai.config.includeStack = true;
var request = require("supertest");
var alexaAppServer = require("../index");
var fs = require("fs");

describe("Alexa App Server with Examples & more HTTPS support", function() {
var testServer;
var sampleLaunchReq;

function isPortTaken(config, fn) {
var port = config.port;
var address = config.host;

var success_ix = 0;
var net = require('net');

var test_ipv4 = net.createServer()
.once('error', function(err) {
if (err.code != 'EADDRINUSE')
return fn(err)
fn(null, true);
})
.once('listening', function() {
test_ipv4.once('close', function() {
success_ix++;
if (success_ix == 2)
fn(null, false);
})
.close()
})
.listen(port, (address !== undefined) ? address : '0.0.0.0');

var test_ipv6 = net.createServer()
.once('error', function (err) {
if (err.code != 'EADDRINUSE')
return fn(err)
fn(null, true)
})
.once('listening', function() {
test_ipv6.once('close', function() {
success_ix++;
if (success_ix == 2)
fn(null, false)
})
.close()
})
.listen(port, (address !== undefined) ? '::1' : '::');
};

before(function() {
sampleLaunchReq = JSON.parse(fs.readFileSync("test/sample-launch-req.json", 'utf8'));
});

afterEach(function() {
testServer.stop();
});

describe("No specific address given", function() {
it("should only have the HTTP server instance running", function() {
testServer = alexaAppServer.start({
port: 3000,
server_root: 'examples'
});

return request(testServer.express)
.get('/alexa/helloworld')
.expect(200).then(function(response) {
// First, check that the actual server instances exist or not
expect(testServer.httpInstance).to.exist;
expect(testServer.httpsInstance).to.not.exist;

// Then, check if the ports are actually bound or not
isPortTaken({ port: 3000 }, function(err, result) {
expect(err).to.not.exist;
expect(result).to.be.true;

isPortTaken({ port: 6000 }, function(err, result) {
expect(err).to.not.exist;
expect(result).to.be.false;
});
});
});
});

it("should have the HTTP and HTTPS server instances running", function() {
testServer = alexaAppServer.start({
port: 3000,
server_root: 'examples',
httpsEnabled: true,
httpsPort: 6000,
privateKey: 'private-key.pem',
certificate: 'cert.cer',
chain: 'cert.ca_bundle',
passphrase: "test123"
});

return request(testServer.express)
.get('/alexa/helloworld')
.expect(200).then(function(response) {
// First, check that the actual server instances exist or not
expect(testServer.httpInstance).to.exist;
expect(testServer.httpsInstance).to.exist;

// Then, check if the ports are actually bound or not
isPortTaken({ port: 3000 }, function(err, result) {
expect(err).to.not.exist;
expect(result).to.be.true;

isPortTaken({ port: 3000 }, function(err, result) {
expect(err).to.not.exist;
expect(result).to.be.true;
});
});
});
});
});

describe("Specific address given (127.0.0.1)", function() {
it("should only have the HTTP server instance running", function() {
testServer = alexaAppServer.start({
port: 3000,
host: '127.0.0.1',
server_root: 'examples'
});

return request(testServer.express)
.get('/alexa/helloworld')
.expect(200).then(function(response) {
// First, check that the actual server instances exist or not
expect(testServer.httpInstance).to.exist;
expect(testServer.httpsInstance).to.not.exist;

// Then, check if the ports are actually bound or not
isPortTaken({ port: 3000, host: '127.0.0.1' }, function(err, result) {
expect(err).to.not.exist;
expect(result).to.be.true;

isPortTaken({ port: 6000, host: '127.0.0.1' }, function(err, result) {
expect(err).to.not.exist;
expect(result).to.be.false;
});
});
});
});

it("should have the HTTP and HTTPS server instances running", function() {
testServer = alexaAppServer.start({
port: 3000,
host: '127.0.0.1',
server_root: 'examples',
httpsEnabled: true,
httpsPort: 6000,
privateKey: 'private-key.pem',
certificate: 'cert.cer',
chain: 'cert.ca_bundle',
passphrase: "test123"
});

return request(testServer.express)
.get('/alexa/helloworld')
.expect(200).then(function(response) {
// First, check that the actual server instances exist or not
expect(testServer.httpInstance).to.exist;
expect(testServer.httpsInstance).to.exist;

// Then, check if the ports are actually bound or not
isPortTaken({ port: 3000, host: '127.0.0.1' }, function(err, result) {
expect(err).to.not.exist;
expect(result).to.be.true;

isPortTaken({ port: 3000, host: '127.0.0.1' }, function(err, result) {
expect(err).to.not.exist;
expect(result).to.be.true;
});
});
});
});
});
});
Loading

0 comments on commit c92fbc3

Please sign in to comment.