add ssh route tests and fixup the code accordingly
This commit is contained in:
+7
-2
@@ -10,7 +10,8 @@ exports = module.exports = {
|
||||
var assert = require('assert'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
ssh = require('../ssh.js');
|
||||
ssh = require('../ssh.js'),
|
||||
SshError = ssh.SshError;
|
||||
|
||||
function getAuthorizedKeys(req, res, next) {
|
||||
ssh.getAuthorizedKeys(function (error, result) {
|
||||
@@ -23,6 +24,7 @@ function getAuthorizedKey(req, res, next) {
|
||||
assert.strictEqual(typeof req.params.identifier, 'string');
|
||||
|
||||
ssh.getAuthorizedKey(req.params.identifier, function (error, result) {
|
||||
if (error && error.reason === SshError.NOT_FOUND) return next(new HttpError(404, error.message));
|
||||
if (error) return next(new HttpError(500, error));
|
||||
next(new HttpSuccess(200, { identifier: result.identifier, key: result.key }));
|
||||
});
|
||||
@@ -34,7 +36,9 @@ function addAuthorizedKey(req, res, next) {
|
||||
if (typeof req.body.key !== 'string' || !req.body.key) return next(new HttpError(400, 'key must be a non empty'));
|
||||
|
||||
ssh.addAuthorizedKey(req.body.key, function (error) {
|
||||
if (error && error.reason === SshError.INVALID_KEY) return next(new HttpError(400, error.message));
|
||||
if (error) return next(new HttpError(500, error));
|
||||
|
||||
next(new HttpSuccess(201, {}));
|
||||
});
|
||||
}
|
||||
@@ -43,7 +47,8 @@ function delAuthorizedKey(req, res, next) {
|
||||
assert.strictEqual(typeof req.params.identifier, 'string');
|
||||
|
||||
ssh.delAuthorizedKey(req.params.identifier, function (error) {
|
||||
if (error && error.reason === SshError.NOT_FOUND) return next(new HttpError(404, error.message));
|
||||
if (error) return next(new HttpError(500, error));
|
||||
next(new HttpSuccess(201, {}));
|
||||
next(new HttpSuccess(202, {}));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user