Skip to content

Commit

Permalink
fixing http_test for secure main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Tryneus committed Jan 8, 2016
1 parent 8e43f32 commit 825bcdc
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion server/test/http_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,37 @@ const fs = require('fs');
const all_tests = () => {
[ 'http', 'https' ].forEach((transport) => {
describe(transport, () => {
let port, proc;
let port, proc, key_file, cert_file;

before('Generate key and cert', (done) => {
if (transport === 'http') { done(); return; }

key_file = `key.${process.pid}.pem`;
cert_file = `cert.${process.pid}.pem`;

child_process.exec(
`openssl req -x509 -nodes -batch -newkey rsa:2048 -keyout ${key_file} -days 1`,
(err, stdout) => {
assert.ifError(err);
const cert_start = stdout.indexOf('-----BEGIN CERTIFICATE-----');
const cert_end = stdout.indexOf('-----END CERTIFICATE-----');
assert(cert_start !== -1 && cert_end !== -1);

const cert = stdout.slice(cert_start, cert_end) + '-----END CERTIFICATE-----\n';
fs.writeFile(cert_file, cert, done);
});
});

after('Remove key and cert', () => {
[ key_file, cert_file ].forEach((f) => { if (f) { fs.unlinkSync(f); } });
});

before('Start standalone fusion server', (done) => {
let args = [ '--connect', `localhost:${utils.rdb_port()}`, '--port', '0' ];
if (transport === 'http') {
args.push('--unsecure');
} else {
args.push('--key-file', key_file, '--cert-file', cert_file);
}
proc = child_process.fork('./src/main.js', args, { silent: true });

Expand Down

0 comments on commit 825bcdc

Please sign in to comment.