Merge pull request #161 from hybridgroup/api-basic-auth

Add HTTP Basic Auth support to API
This commit is contained in:
Ron Evans 2014-04-03 16:17:03 -07:00
commit c5f09133b0
3 changed files with 27 additions and 3 deletions

View File

@ -40,6 +40,16 @@ namespace("Cylon", function() {
this.server.set('title', 'Cylon API Server');
// configure basic auth, if requested
if (opts.auth.type && opts.auth.type === 'basic') {
var user = opts.auth.user,
pass = opts.auth.pass;
if (user && pass) {
this.server.use(express.basicAuth(user, pass));
}
}
this.server.use(express.json());
this.server.use(express.urlencoded());
this.server.use(express["static"](__dirname + "/../node_modules/robeaux/"));

View File

@ -47,7 +47,8 @@ var Cylon = (function() {
host: '127.0.0.1',
port: '3000',
cert: null,
key: null
key: null,
auth: {}
};
this.robot = bind(this.robot, this);
@ -101,6 +102,7 @@ var Cylon = (function() {
var host = opts.host || this.api_config.host,
port = opts.port || this.api_config.port,
auth = opts.auth || this.api_config.auth,
cert = opts.cert || this.api_config.cert,
key = opts.key || this.api_config.key;
@ -108,7 +110,8 @@ var Cylon = (function() {
host: host,
port: port,
cert: cert,
key: key
key: key,
auth: auth
};
return this.api_config;

View File

@ -47,7 +47,8 @@ describe("Cylon", function() {
host: '127.0.0.1',
port: '3000',
cert: null,
key: null
key: null,
auth: {}
};
// this is the shortest, cheapest way to dup an object in JS.
@ -102,6 +103,16 @@ describe("Cylon", function() {
expect(cylon.api_config).to.be.eql(expectedConfig);
})
});
context("specifying an auth strategy", function() {
it("changes the auth strategy", function() {
var auth = { type: 'basic', user: 'user', pass: 'pass'}
expectedConfig.auth = auth;
cylon.api({ auth: auth })
expect(cylon.api_config).to.be.eql(expectedConfig);
});
});
});
describe("#findRobot", function() {