Add support for manually specifying cert/key files

This commit is contained in:
Andrew Stewart 2014-04-03 15:03:21 -07:00
parent ea022d3880
commit 29b7db0de8
3 changed files with 56 additions and 16 deletions

View File

@ -32,8 +32,8 @@ namespace("Cylon", function() {
master = opts.master;
var options = {
cert: fs.readFileSync(__dirname + "/ssl/server.crt"),
key: fs.readFileSync(__dirname + "/ssl/server.key")
cert: fs.readFileSync(opts.cert || __dirname + "/ssl/server.crt"),
key: fs.readFileSync(opts.key || __dirname + "/ssl/server.key")
}
this.server = express().https(options).io();

View File

@ -41,9 +41,15 @@ var Cylon = (function() {
this.self = this;
this.api_instance = null;
this.api_config = { host: '127.0.0.1', port: '3000' };
this.robots = [];
this.api_config = {
host: '127.0.0.1',
port: '3000',
cert: null,
key: null
};
this.robot = bind(this.robot, this);
if (process.platform === "win32") {
@ -94,9 +100,16 @@ var Cylon = (function() {
if (opts == null) { opts = {}; }
var host = opts.host || this.api_config.host,
port = opts.port || this.api_config.port;
port = opts.port || this.api_config.port,
cert = opts.cert || this.api_config.cert,
key = opts.key || this.api_config.key;
this.api_config = { host: host, port: port };
this.api_config = {
host: host,
port: port,
cert: cert,
key: key
};
return this.api_config;
};

View File

@ -40,41 +40,68 @@ describe("Cylon", function() {
});
describe("#api", function() {
afterEach(function() {
cylon.api_config = { host: "127.0.0.1", port: "3000" };
});
var expectedConfig;
beforeEach(function() {
expectedConfig = {
host: '127.0.0.1',
port: '3000',
cert: null,
key: null
};
// this is the shortest, cheapest way to dup an object in JS.
// I don't like it either.
cylon.api_config = JSON.parse(JSON.stringify(expectedConfig));
})
context("without arguments", function() {
it("returns the current API configuration", function() {
cylon.api();
var config = cylon.api_config;
expect(config).to.be.eql({ host: "127.0.0.1", port: "3000" });
expect(cylon.api_config).to.be.eql(expectedConfig);
});
});
context("only specifying port", function() {
it("changes the port, but not the host", function() {
expectedConfig.port = "4000";
cylon.api({ port: "4000" });
var config = cylon.api_config;
expect(config).to.be.eql({ host: "127.0.0.1", port: "4000" });
expect(cylon.api_config).to.be.eql(expectedConfig);
});
});
context("only specifying host", function() {
it("changes the host, but not the port", function() {
expectedConfig.host = "0.0.0.0";
cylon.api({ host: "0.0.0.0" });
var config = cylon.api_config;
expect(config).to.be.eql({ host: "0.0.0.0", port: "3000" });
expect(cylon.api_config).to.be.eql(expectedConfig);
});
});
context("specifying new host and port", function() {
it("changes both the host and port", function() {
expectedConfig.host = "0.0.0.0";
expectedConfig.port = "4000";
cylon.api({ host: "0.0.0.0", port: "4000" });
var config = cylon.api_config;
expect(config).to.be.eql({ host: "0.0.0.0", port: "4000" });
expect(cylon.api_config).to.be.eql(expectedConfig);
});
});
context("specifiying new SSL key and cert", function() {
it("changes the SSL key and cert", function() {
expectedConfig.cert = "/path/to/cert/file";
expectedConfig.key = "/path/to/key/file";
cylon.api({ cert: "/path/to/cert/file", key: "/path/to/key/file" });
expect(cylon.api_config).to.be.eql(expectedConfig);
})
});
});
describe("#findRobot", function() {