Add support for manually specifying cert/key files
This commit is contained in:
parent
ea022d3880
commit
29b7db0de8
|
@ -32,8 +32,8 @@ namespace("Cylon", function() {
|
||||||
master = opts.master;
|
master = opts.master;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
cert: fs.readFileSync(__dirname + "/ssl/server.crt"),
|
cert: fs.readFileSync(opts.cert || __dirname + "/ssl/server.crt"),
|
||||||
key: fs.readFileSync(__dirname + "/ssl/server.key")
|
key: fs.readFileSync(opts.key || __dirname + "/ssl/server.key")
|
||||||
}
|
}
|
||||||
|
|
||||||
this.server = express().https(options).io();
|
this.server = express().https(options).io();
|
||||||
|
|
19
lib/cylon.js
19
lib/cylon.js
|
@ -41,9 +41,15 @@ var Cylon = (function() {
|
||||||
this.self = this;
|
this.self = this;
|
||||||
|
|
||||||
this.api_instance = null;
|
this.api_instance = null;
|
||||||
this.api_config = { host: '127.0.0.1', port: '3000' };
|
|
||||||
this.robots = [];
|
this.robots = [];
|
||||||
|
|
||||||
|
this.api_config = {
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: '3000',
|
||||||
|
cert: null,
|
||||||
|
key: null
|
||||||
|
};
|
||||||
|
|
||||||
this.robot = bind(this.robot, this);
|
this.robot = bind(this.robot, this);
|
||||||
|
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
|
@ -94,9 +100,16 @@ var Cylon = (function() {
|
||||||
if (opts == null) { opts = {}; }
|
if (opts == null) { opts = {}; }
|
||||||
|
|
||||||
var host = opts.host || this.api_config.host,
|
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;
|
return this.api_config;
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,41 +40,68 @@ describe("Cylon", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#api", function() {
|
describe("#api", function() {
|
||||||
afterEach(function() {
|
var expectedConfig;
|
||||||
cylon.api_config = { host: "127.0.0.1", port: "3000" };
|
|
||||||
});
|
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() {
|
context("without arguments", function() {
|
||||||
it("returns the current API configuration", function() {
|
it("returns the current API configuration", function() {
|
||||||
cylon.api();
|
cylon.api();
|
||||||
var config = cylon.api_config;
|
expect(cylon.api_config).to.be.eql(expectedConfig);
|
||||||
expect(config).to.be.eql({ host: "127.0.0.1", port: "3000" });
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context("only specifying port", function() {
|
context("only specifying port", function() {
|
||||||
it("changes the port, but not the host", function() {
|
it("changes the port, but not the host", function() {
|
||||||
|
expectedConfig.port = "4000";
|
||||||
|
|
||||||
cylon.api({ 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() {
|
context("only specifying host", function() {
|
||||||
it("changes the host, but not the port", function() {
|
it("changes the host, but not the port", function() {
|
||||||
|
expectedConfig.host = "0.0.0.0";
|
||||||
cylon.api({ 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() {
|
context("specifying new host and port", function() {
|
||||||
it("changes both the 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" });
|
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() {
|
describe("#findRobot", function() {
|
||||||
|
|
Loading…
Reference in New Issue