diff --git a/circle.yml b/circle.yml index a51980f..2ec86f9 100644 --- a/circle.yml +++ b/circle.yml @@ -16,6 +16,6 @@ deployment: npm: branch: master commands: - - npm version 1.2.$CIRCLE_BUILD_NUM --no-git-tag-version + - npm version 1.3.$CIRCLE_BUILD_NUM --no-git-tag-version - echo -e "$NPM_USERNAME\n$NPM_PASSWORD\n$NPM_EMAIL" | npm login - npm publish diff --git a/package.json b/package.json index f0582ba..191e5d4 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,12 @@ "main": "src/cipherlayer.js", "scripts": { "test": "npm run-script jshint && npm run-script mocha && npm run-script features", - "mocha": "mocha tests --recursive", - "features": "./node_modules/cucumber/bin/cucumber.js features -f pretty --tags ~@ignore", - "features-only": "./node_modules/cucumber/bin/cucumber.js features -f pretty --tags @only", - "jshint": "node_modules/.bin/jshint ./src ./tests ./features main.js", - "coverage-unit": "istanbul cover --root src --include-all-sources --lcovonly --dir ./coverage/unit _mocha -- tests --recursive --reporter mocha-lcov-reporter", - "coverage-acceptance": "istanbul cover --root src --include-all-sources --lcovonly --dir ./coverage/acceptance cucumber.js -- --tags ~@ignore --format json", + "mocha": "mocha tests-unit --recursive", + "features": "cucumber.js tests-acceptance -f pretty --tags ~@ignore", + "features-only": "cucumber.js tests-acceptance -f pretty --tags @only", + "jshint": "jshint ./src ./tests-unit ./tests-acceptance main.js", + "coverage-unit": "istanbul cover --root src --include-all-sources --lcovonly --dir ./coverage/unit _mocha -- tests-unit --recursive --reporter mocha-lcov-reporter", + "coverage-acceptance": "istanbul cover --root src --include-all-sources --lcovonly --dir ./coverage/acceptance cucumber.js -- tests-acceptance --tags ~@ignore --format json", "coverage-merge": "istanbul-combine coverage/**/coverage.json", "coverage": "npm run coverage-unit && npm run coverage-acceptance && npm run coverage-merge", "coveralls": "istanbul-coveralls", diff --git a/src/cipherlayer.js b/src/cipherlayer.js index 5d00628..702457e 100644 --- a/src/cipherlayer.js +++ b/src/cipherlayer.js @@ -1,269 +1,46 @@ -var log = require('./logger/service.js'); -var restify = require('restify'); +'use strict'; + var async = require('async'); -var fs = require('fs'); -var path = require('path'); -var config = require(process.cwd() + '/config.json'); -var passport = require('passport'); -var _ = require('lodash'); var userDao = require('./managers/dao'); var redisMng = require('./managers/redis'); -var checkAccessTokenParam = require('./middlewares/accessTokenParam'); -var checkAuthHeader = require('./middlewares/authHeaderRequired'); -var decodeToken = require('./middlewares/decodeToken'); -var findUser = require('./middlewares/findUser'); -var prepareOptions = require('./middlewares/prepareOptions'); -var platformsSetUp = require('./middlewares/platformsSetUp'); -var propagateRequest = require('./middlewares/propagateRequest'); -var permissions = require('./middlewares/permissions'); -var bodyParserWrapper = require('./middlewares/bodyParserWrapper'); - -var versionControl = require('version-control'); - -var pinValidation = require('./middlewares/pinValidation')(); -var userAppVersion = require('./middlewares/userAppVersion')(); - -var publicServer; -var internalServer; - -function startDaos(cbk) { - userDao.connect(function () { - cbk(); - }); -} - -function stopDaos(cbk) { - userDao.disconnect(function () { - cbk(); - }); -} - -function startRedis(cbk) { - redisMng.connect(function () { - cbk(); - }); -} - -function stopRedis(cbk) { - redisMng.disconnect(function () { - cbk(); - }); -} - -function startListener(publicPort, internalPort, cbk) { - async.series([ - function (done) { - publicServer = restify.createServer({ - name: 'cipherlayer-server', - log: log - }); - - log.info('PUBLIC SERVICE starting on PORT ' + publicPort); - - publicServer.on('after', function (req, res) { - var logInfo = { - request: { - method: req.method, - headers: req.headers, - url: req.url, - path: req._url.pathname, - query: req._url.query, - params: req.params, - time: req._time - }, - response: { - statusCode: res.statusCode, - hasBody: res.hasBody, - bodySize: _.size(res.body), - time: Date.now() - }, - user: req.user, - tokenInfo: req.tokenInfo - }; - delete(logInfo.request.params.password); - - req.log.info(logInfo, "response"); - }); - - if (config.accessControlAllow) { - publicServer.use(restify.CORS({ - origins: config.accessControlAllow.origins, - credentials: true, - headers: config.accessControlAllow.headers - })); - - publicServer.opts(/.*/, function (req, res, next) { - res.header("Access-Control-Allow-Methods", req.header("Access-Control-Request-Methods")); - res.header("Access-Control-Allow-Headers", req.header("Access-Control-Request-Headers")); - res.send(200); - return next(); - }); - } - - publicServer.use(restify.queryParser()); - publicServer.use(bodyParserWrapper(restify.bodyParser({maxBodySize: 1024 * 1024 * 3}))); - - var versionControlOptions = _.clone(config.version); - versionControlOptions.public = [ - "/auth/sf", - "/auth/sf/*", - "/auth/in", - "/auth/in/*", - "/auth/google", - "/auth/google/*", - "/auth/login/refreshToken*", - "/user/activate*", - "/heartbeat", - "/user/email/available" - ]; - publicServer.use(versionControl(versionControlOptions)); - - publicServer.on('uncaughtException', function (req, res, route, error) { - log.error({exception: {req: req, res: res, route: route, err: error}}); - if (!res.statusCode) { - res.send(500, {err: 'internal_error', des: 'uncaught exception'}); - } - }); - - var routesPath = path.join(__dirname, './public_routes/'); - fs.readdirSync(routesPath).forEach(function (filename) { - require(routesPath + filename)(publicServer); - }); - - var platformsPath = path.join(__dirname, '/platforms/'); - fs.readdirSync(platformsPath).forEach(function (filename) { - require(platformsPath + filename).addRoutes(publicServer, passport); - }); - - publicServer.get(/(.*)/, checkAccessTokenParam, checkAuthHeader, decodeToken, permissions, findUser, pinValidation, userAppVersion, prepareOptions, platformsSetUp, propagateRequest); - publicServer.post(/(.*)/, checkAccessTokenParam, checkAuthHeader, decodeToken, permissions, findUser, pinValidation, userAppVersion, prepareOptions, platformsSetUp, propagateRequest); - publicServer.del(/(.*)/, checkAccessTokenParam, checkAuthHeader, decodeToken, permissions, findUser, pinValidation, userAppVersion, prepareOptions, platformsSetUp, propagateRequest); - publicServer.put(/(.*)/, checkAccessTokenParam, checkAuthHeader, decodeToken, permissions, findUser, pinValidation, userAppVersion, prepareOptions, platformsSetUp, propagateRequest); - - publicServer.listen(publicPort, function () { - log.info('PUBLIC SERVICE listening on PORT ' + publicPort); - done(); - }); - }, - function (done) { - if (!internalPort) { - log.info('INTERNAL SERVICE not started because there is no internal_port in config'); - return done(); - } - - log.info('INTERNAL SERVICE starting on PORT ' + internalPort); - - internalServer = restify.createServer({ - name: 'cipherlayer-internal-server', - log: log - }); - - internalServer.on('after', function (req, res) { - var logInfo = { - request: { - method: req.method, - headers: req.headers, - url: req.url, - path: req._url.pathname, - query: req._url.query, - params: req.params, - time: req._time - }, - response: { - statusCode: res.statusCode, - hasBody: res.hasBody, - bodySize: _.size(res.body), - time: Date.now() - }, - user: req.user, - tokenInfo: req.tokenInfo - }; - delete(logInfo.request.params.password); - - req.log.info(logInfo, "response"); - }); - - internalServer.use(restify.queryParser()); - internalServer.use(bodyParserWrapper(restify.bodyParser({maxBodySize: 1024 * 1024 * 3}))); - - var routesPath = path.join(__dirname, './internal_routes/'); - fs.readdirSync(routesPath).forEach(function (filename) { - require(routesPath + filename)(internalServer); - }); - - internalServer.listen(internalPort, function () { - log.info('INTERNAL SERVICE listening on PORT ' + internalPort); - done(); - }); - } - ], cbk); -} - -function stopListener(cbk) { - async.parallel([ - function (done) { - publicServer.close(function () { - done(); - }); - }, - function (done) { - if (!internalServer) { - return done(); +var publicService = require('./public_service'); +var privateService = require('./internal_service'); + +module.exports = function () { + var cipherlayer = {}; + + cipherlayer.start = function (publicPort, internalPort, cbk) { + //Validate the current config.json with the schema + //if( !jsonValidator.isValidJSON(config, configSchema)) { + // return cbk({err:'invalid_config_json', des:'The config.json is not updated, check for the last version.'}); + //} + + async.series([ + userDao.connect, + redisMng.connect, + function (done) { + publicService.start(publicPort, done); + }, + function (done) { + privateService.start(internalPort, done); } - internalServer.close(function () { - done(); - }); - } - ], cbk); -} - -function start(publicPort, internalPort, cbk) { - //Validate the current config.json with the schema - //if( !jsonValidator.isValidJSON(config, configSchema)) { - // return cbk({err:'invalid_config_json', des:'The config.json is not updated, check for the last version.'}); - //} - - async.series([ - startDaos, - startRedis, - function (done) { - startListener(publicPort, internalPort, done); - } - ], function (err) { - cbk(err); - }); -} - -function stop(cbk) { - async.series([ - stopDaos, - stopRedis, - stopListener - ], function (err) { - cbk(err); - }); -} - -function getStatus(cbk) { - async.series([ - function (done) { - userDao.getStatus(done); - }, - function (done) { - redisMng.getStatus(done); - } - ], function (err) { - if (err) { - return cbk(err); - } - cbk(); - }); -} - -module.exports = { - start: start, - stop: stop, - getStatus: getStatus -}; + ], function (err) { + cbk(err); + }); + }; + + cipherlayer.stop = function stop(cbk) { + async.series([ + userDao.disconnect, + redisMng.disconnect, + publicService.stop, + privateService.stop + ], function (err) { + cbk(err); + }); + }; + + return cipherlayer; +}(); diff --git a/src/internal_service.js b/src/internal_service.js new file mode 100644 index 0000000..a91f1b0 --- /dev/null +++ b/src/internal_service.js @@ -0,0 +1,74 @@ +'use strict'; + +var restify = require('restify'); +var _ = require('lodash'); + +var log = require('./logger/service.js'); +var bodyParserWrapper = require('./middlewares/bodyParserWrapper'); + +var routes = require('./routes_internal/routes'); + +module.exports = function () { + var service = {}; + + var server; + service.start = function (internalPort, done) { + if (!internalPort) { + log.info('INTERNAL SERVICE not started because there is no internal_port in config'); + return done(); + } + + log.info('INTERNAL SERVICE starting on PORT ' + internalPort); + + server = restify.createServer({ + name: 'cipherlayer-internal-server', + log: log + }); + + server.on('after', function (req, res) { + var logInfo = { + request: { + method: req.method, + headers: req.headers, + url: req.url, + path: req._url.pathname, + query: req._url.query, + params: req.params, + time: req._time + }, + response: { + statusCode: res.statusCode, + hasBody: res.hasBody, + bodySize: _.size(res.body), + time: Date.now() + }, + user: req.user, + tokenInfo: req.tokenInfo + }; + delete(logInfo.request.params.password); + + req.log.info(logInfo, "response"); + }); + + server.use(restify.queryParser()); + server.use(bodyParserWrapper(restify.bodyParser({maxBodySize: 1024 * 1024 * 3}))); + + routes(server); + + server.listen(internalPort, function () { + log.info('INTERNAL SERVICE listening on PORT ' + internalPort); + done(); + }); + }; + + service.stop = function (done) { + if (!server) { + return done(); + } + server.close(function () { + done(); + }); + }; + + return service; +}(); diff --git a/src/logger/todo.js b/src/logger/todo.js deleted file mode 100644 index 9895824..0000000 --- a/src/logger/todo.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict'; - -var bunyan = require('bunyan'); -var fs = require('fs'); - -module.exports = function () { - - var dir = process.cwd() + '/logs'; - if (!fs.existsSync(dir)) { - fs.mkdirSync(dir); - } - - var log = bunyan.createLogger({ - name: 'cipherlayer-todo', - streams: [{ - type: 'rotating-file', - path: process.cwd() + '/logs/cipherlayer-todo.log', - period: '1d', - count: 30 - }] - }); - return log; -}(); diff --git a/src/managers/phone.js b/src/managers/phone.js index 05e06c2..117a1d6 100644 --- a/src/managers/phone.js +++ b/src/managers/phone.js @@ -2,7 +2,6 @@ var request = require('request'); var _ = require('lodash'); var countries = require('countries-info'); var redisMng = require('./redis'); -var todo = require('../logger/todo.js'); var _settings = {}; @@ -50,7 +49,6 @@ function sendPIN(phone, pin, cbk) { }; request(options, function (err) { - todo.warn('pin sms notification request must verify response code'); if (err) { return cbk(err); } diff --git a/src/middlewares/accessTokenParam.js b/src/middlewares/accessTokenParam.js index b636f38..e36de9b 100644 --- a/src/middlewares/accessTokenParam.js +++ b/src/middlewares/accessTokenParam.js @@ -1,12 +1,10 @@ -var todo = require('../logger/todo.js'); var config = require(process.cwd() + '/config.json'); function checkAccessTokenParam(req, res, next) { var paramAT = req.params.at; if (paramAT) { - todo.warn('config.authHeaderKey must not contain a space'); - req.headers.authorization = config.authHeaderKey + paramAT; + req.headers.authorization = config.authHeaderKey.trim() + ' ' + paramAT; } next(); diff --git a/src/public_routes/auth.js b/src/public_routes/auth.js deleted file mode 100644 index 8f2204d..0000000 --- a/src/public_routes/auth.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -var checkAuthBasic = require('../middlewares/checkAuthBasic'); -var login_post = require('./auth/login_post'); -var user_post = require('./auth/user_post'); -var user_del = require('./auth/user_del'); -var renew_post = require('./auth/renew_post'); -var logout_post = require('./auth/logout_post'); -var loginEmail_post = require('./auth/loginEmail_post'); -var loginRefreshToken_get = require('./auth/loginRefreshToken_get'); - -var authHeaderRequired = require('../middlewares/authHeaderRequired'); -var decodeAccessToken = require('../middlewares/decodeToken'); - -module.exports = function addRoutes(service) { - service.post('/auth/login', login_post); - service.post('/auth/login/email', loginEmail_post); - service.get('/auth/login/refreshToken', loginRefreshToken_get); - - service.post('/auth/renew', renew_post); - service.post('/auth/logout', authHeaderRequired, decodeAccessToken, logout_post); - - service.post('/auth/user', checkAuthBasic, user_post); - service.del('/auth/user', checkAuthBasic, user_del); -}; diff --git a/src/public_routes/heartbeat.js b/src/public_routes/heartbeat.js deleted file mode 100644 index 73c2a6e..0000000 --- a/src/public_routes/heartbeat.js +++ /dev/null @@ -1,18 +0,0 @@ -var cipherlayer = require('../cipherlayer'); - -function getStatus(req, res, next) { - cipherlayer.getStatus(function (err) { - if (err) { - res.send(500, err); - return next(); - } - res.send(204); - return next(); - }); -} - -function addRoutes(service) { - service.get('/heartbeat', getStatus); -} - -module.exports = addRoutes; diff --git a/src/public_routes/user.js b/src/public_routes/user.js deleted file mode 100644 index 19b7d90..0000000 --- a/src/public_routes/user.js +++ /dev/null @@ -1,70 +0,0 @@ -'use strict'; - -var config = require(process.cwd() + '/config.json'); -var userMng = require('../managers/user'); - -var checkAccessTokenParam = require('../middlewares/accessTokenParam'); -var checkAuthHeader = require('../middlewares/authHeaderRequired'); -var decodeToken = require('../middlewares/decodeToken'); -var findUser = require('../middlewares/findUser'); -var bodyRequired = require('../middlewares/bodyRequired'); - -var forgotPassword_get = require('./user/forgotPassword_get'); -var activateUser_get = require('./user/activateUser_get'); -var activateUser_post = require('./user/activateUser_get'); -var checkEmailAvailability_post = require('./user/checkEmailAvailability_post'); -var createUser_post = require('./user/createUser_post'); - -function validateOldPassword(req, res, next) { - var err; - if (!config.password.validateOldPassword) { - return next(); - } - - if (!req.body.oldPassword) { - err = { - err: 'missing_password', - des: 'Missing old password validation' - }; - res.send(400, err); - return next(false); - } - - userMng().validateOldPassword(req.user.username, req.body.oldPassword, function (err) { - if (err) { - res.send(401, err); - return next(false); - } - return next(); - }); -} - -function setPassword(req, res, next) { - userMng().setPassword(req.user._id, req.body, function (err) { - if (err) { - if (!err.code) { - res.send(500, err); - return next(false); - } - - var errCode = err.code; - delete(err.code); - res.send(errCode, err); - return next(false); - } - - res.send(204); - return next(); - }); -} - -function addRoutes(service) { - service.get('/user/:email/password', forgotPassword_get); - service.post(config.passThroughEndpoint.path, createUser_post); - service.get('/user/activate', activateUser_get); - service.post('/user/activate', activateUser_post); - service.post('/user/email/available', checkEmailAvailability_post); - service.put('/user/me/password', checkAccessTokenParam, checkAuthHeader, decodeToken, bodyRequired, findUser, validateOldPassword, setPassword); -} - -module.exports = addRoutes; diff --git a/src/public_service.js b/src/public_service.js new file mode 100644 index 0000000..bf25c80 --- /dev/null +++ b/src/public_service.js @@ -0,0 +1,131 @@ +'use strict'; + +var log = require('./logger/service.js'); +var restify = require('restify'); +var fs = require('fs'); +var path = require('path'); +var config = require(process.cwd() + '/config.json'); +var passport = require('passport'); +var _ = require('lodash'); + +var checkAccessTokenParam = require('./middlewares/accessTokenParam'); +var checkAuthHeader = require('./middlewares/authHeaderRequired'); +var decodeToken = require('./middlewares/decodeToken'); +var findUser = require('./middlewares/findUser'); +var prepareOptions = require('./middlewares/prepareOptions'); +var platformsSetUp = require('./middlewares/platformsSetUp'); +var propagateRequest = require('./middlewares/propagateRequest'); +var permissions = require('./middlewares/permissions'); +var bodyParserWrapper = require('./middlewares/bodyParserWrapper'); + +var versionControl = require('version-control'); + +var pinValidation = require('./middlewares/pinValidation')(); +var userAppVersion = require('./middlewares/userAppVersion')(); + +var routes = require('./routes_public/routes'); + +module.exports = function () { + var service = {}; + + var server; + + service.start = function (publicPort, done) { + server = restify.createServer({ + name: 'cipherlayer-server', + log: log + }); + + log.info('PUBLIC SERVICE starting on PORT ' + publicPort); + + server.on('after', function (req, res) { + var logInfo = { + request: { + method: req.method, + headers: req.headers, + url: req.url, + path: req._url.pathname, + query: req._url.query, + params: req.params, + time: req._time + }, + response: { + statusCode: res.statusCode, + hasBody: res.hasBody, + bodySize: _.size(res.body), + time: Date.now() + }, + user: req.user, + tokenInfo: req.tokenInfo + }; + delete(logInfo.request.params.password); + + req.log.info(logInfo, "response"); + }); + + if (config.accessControlAllow) { + server.use(restify.CORS({ + origins: config.accessControlAllow.origins, + credentials: true, + headers: config.accessControlAllow.headers + })); + + server.opts(/.*/, function (req, res, next) { + res.header("Access-Control-Allow-Methods", req.header("Access-Control-Request-Methods")); + res.header("Access-Control-Allow-Headers", req.header("Access-Control-Request-Headers")); + res.send(200); + return next(); + }); + } + + server.use(restify.queryParser()); + server.use(bodyParserWrapper(restify.bodyParser({maxBodySize: 1024 * 1024 * 3}))); + + var versionControlOptions = _.clone(config.version); + versionControlOptions.public = [ + "/auth/sf", + "/auth/sf/*", + "/auth/in", + "/auth/in/*", + "/auth/google", + "/auth/google/*", + "/auth/login/refreshToken*", + "/user/activate*", + "/heartbeat", + "/user/email/available" + ]; + server.use(versionControl(versionControlOptions)); + + server.on('uncaughtException', function (req, res, route, error) { + log.error({exception: {req: req, res: res, route: route, err: error}}); + if (!res.statusCode) { + res.send(500, {err: 'internal_error', des: 'uncaught exception'}); + } + }); + + routes(server); + + var platformsPath = path.join(__dirname, '/platforms/'); + fs.readdirSync(platformsPath).forEach(function (filename) { + require(platformsPath + filename).addRoutes(server, passport); + }); + + server.get(/(.*)/, checkAccessTokenParam, checkAuthHeader, decodeToken, permissions, findUser, pinValidation, userAppVersion, prepareOptions, platformsSetUp, propagateRequest); + server.post(/(.*)/, checkAccessTokenParam, checkAuthHeader, decodeToken, permissions, findUser, pinValidation, userAppVersion, prepareOptions, platformsSetUp, propagateRequest); + server.del(/(.*)/, checkAccessTokenParam, checkAuthHeader, decodeToken, permissions, findUser, pinValidation, userAppVersion, prepareOptions, platformsSetUp, propagateRequest); + server.put(/(.*)/, checkAccessTokenParam, checkAuthHeader, decodeToken, permissions, findUser, pinValidation, userAppVersion, prepareOptions, platformsSetUp, propagateRequest); + + server.listen(publicPort, function () { + log.info('PUBLIC SERVICE listening on PORT ' + publicPort); + done(); + }); + }; + + service.stop = function (done) { + server.close(function () { + done(); + }); + }; + + return service; +}(); diff --git a/src/public_routes/auth/user_del.js b/src/routes_internal/auth/user_del.js similarity index 100% rename from src/public_routes/auth/user_del.js rename to src/routes_internal/auth/user_del.js diff --git a/src/public_routes/auth/user_post.js b/src/routes_internal/auth/user_post.js similarity index 100% rename from src/public_routes/auth/user_post.js rename to src/routes_internal/auth/user_post.js diff --git a/src/internal_routes/realms.js b/src/routes_internal/realms/realms_get.js similarity index 55% rename from src/internal_routes/realms.js rename to src/routes_internal/realms/realms_get.js index 3e9c44d..b74825c 100644 --- a/src/internal_routes/realms.js +++ b/src/routes_internal/realms/realms_get.js @@ -1,6 +1,8 @@ -var daoMng = require('../managers/dao'); +'use strict'; -function getRealms(req, res, next) { +var daoMng = require('../../managers/dao'); + +module.exports = function getRealms(req, res, next) { daoMng.getRealms(function (err, realms) { if (err) { res.send(500, {err: 'internalError', des: 'Internal server error'}); @@ -12,10 +14,4 @@ function getRealms(req, res, next) { }); return next(); }); -} - -function addRoutes(service) { - service.get('/realms', getRealms); -} - -module.exports = addRoutes; +}; diff --git a/src/routes_internal/routes.js b/src/routes_internal/routes.js new file mode 100644 index 0000000..ddae622 --- /dev/null +++ b/src/routes_internal/routes.js @@ -0,0 +1,13 @@ +'use strict'; + +var checkAuthBasic = require('../middlewares/checkAuthBasic'); + +var realms_get = require('./realms/realms_get'); +var user_post = require('./auth/user_post'); +var user_del = require('./auth/user_del'); + +module.exports = function addRoutes(server) { + server.get('/realms', realms_get); + server.post('/auth/user', checkAuthBasic, user_post); + server.del('/auth/user', checkAuthBasic, user_del); +}; diff --git a/src/public_routes/auth/loginEmail_post.js b/src/routes_public/auth/loginEmail_post.js similarity index 100% rename from src/public_routes/auth/loginEmail_post.js rename to src/routes_public/auth/loginEmail_post.js diff --git a/src/public_routes/auth_facebook.js b/src/routes_public/auth/loginFacebook_post.js similarity index 91% rename from src/public_routes/auth_facebook.js rename to src/routes_public/auth/loginFacebook_post.js index 2beab52..43b83eb 100644 --- a/src/public_routes/auth_facebook.js +++ b/src/routes_public/auth/loginFacebook_post.js @@ -1,12 +1,14 @@ +'use strict'; + var request = require('request'); var _ = require('lodash'); -var log = require('../logger/service.js'); -var daoMng = require('../managers/dao'); -var userMng = require('../managers/user')(); -var tokenMng = require('../managers/token'); +var log = require('../../logger/service.js'); +var daoMng = require('../../managers/dao'); +var userMng = require('../../managers/user')(); +var tokenMng = require('../../managers/token'); var config = require(process.cwd() + '/config.json'); -var crypto = require('../managers/crypto'); +var crypto = require('../../managers/crypto'); var cryptoMng = crypto(config.password); var defaultOptions = { @@ -48,7 +50,7 @@ function mapFacebookData(body, fieldsMap) { return mappedData; } -function postAuthRegisterFacebook(req, res, next) { +module.exports = function postAuthRegisterFacebook(req, res, next) { var options = _.clone(defaultOptions); options.qs.access_token = req.body.accessToken; @@ -179,10 +181,4 @@ function postAuthRegisterFacebook(req, res, next) { }); }); -} - -function addRoutes(service) { - service.post('/auth/login/facebook', postAuthRegisterFacebook); -} - -module.exports = addRoutes; +}; diff --git a/src/public_routes/auth/loginRefreshToken_get.js b/src/routes_public/auth/loginRefreshToken_get.js similarity index 100% rename from src/public_routes/auth/loginRefreshToken_get.js rename to src/routes_public/auth/loginRefreshToken_get.js diff --git a/src/public_routes/auth/login_post.js b/src/routes_public/auth/login_post.js similarity index 100% rename from src/public_routes/auth/login_post.js rename to src/routes_public/auth/login_post.js diff --git a/src/public_routes/auth/logout_post.js b/src/routes_public/auth/logout_post.js similarity index 100% rename from src/public_routes/auth/logout_post.js rename to src/routes_public/auth/logout_post.js diff --git a/src/public_routes/auth/renew_post.js b/src/routes_public/auth/renew_post.js similarity index 100% rename from src/public_routes/auth/renew_post.js rename to src/routes_public/auth/renew_post.js diff --git a/src/public_routes/auth/session.js b/src/routes_public/auth/session.js similarity index 100% rename from src/public_routes/auth/session.js rename to src/routes_public/auth/session.js diff --git a/src/routes_public/heartbeat/heartbeat_get.js b/src/routes_public/heartbeat/heartbeat_get.js new file mode 100644 index 0000000..0bfd238 --- /dev/null +++ b/src/routes_public/heartbeat/heartbeat_get.js @@ -0,0 +1,33 @@ +'use strict'; + +var async = require('async'); + +var userDao = require('../../managers/dao'); +var redisMng = require('../../managers/redis'); + +function getStatus(cbk) { + async.series([ + function (done) { + userDao.getStatus(done); + }, + function (done) { + redisMng.getStatus(done); + } + ], function (err) { + if (err) { + return cbk(err); + } + cbk(); + }); +} + +module.exports = function (req, res, next) { + getStatus(function (err) { + if (err) { + res.send(500, err); + return next(); + } + res.send(204); + return next(); + }); +}; diff --git a/src/routes_public/routes.js b/src/routes_public/routes.js new file mode 100644 index 0000000..4569d42 --- /dev/null +++ b/src/routes_public/routes.js @@ -0,0 +1,47 @@ +'use strict'; + +var config = require(process.cwd() + '/config.json'); + +var authHeaderRequired = require('../middlewares/authHeaderRequired'); +var decodeAccessToken = require('../middlewares/decodeToken'); + +var login_post = require('./auth/login_post'); +var renew_post = require('./auth/renew_post'); +var logout_post = require('./auth/logout_post'); +var loginEmail_post = require('./auth/loginEmail_post'); +var loginRefreshToken_get = require('./auth/loginRefreshToken_get'); + +var heartbeat_get = require('./heartbeat/heartbeat_get'); + +var authloginFacebook_post = require('./auth/loginFacebook_post'); + +var checkAccessTokenParam = require('../middlewares/accessTokenParam'); +var checkAuthHeader = require('../middlewares/authHeaderRequired'); +var decodeToken = require('../middlewares/decodeToken'); +var findUser = require('../middlewares/findUser'); +var bodyRequired = require('../middlewares/bodyRequired'); + +var forgotPassword_get = require('./user/forgotPassword_get'); +var activateUser_get = require('./user/activateUser_get'); +var activateUser_post = require('./user/activateUser_get'); +var checkEmailAvailability_post = require('./user/checkEmailAvailability_post'); +var createUser_post = require('./user/createUser_post'); + +var validateOldPassword = require('./user/validateOldPassword_put'); +var setPassword = require('./user/setPassword_put'); + +module.exports = function(server){ + server.post('/auth/login', login_post); + server.post('/auth/login/email', loginEmail_post); + server.get('/auth/login/refreshToken', loginRefreshToken_get); + server.post('/auth/renew', renew_post); + server.post('/auth/logout', authHeaderRequired, decodeAccessToken, logout_post); + server.get('/heartbeat', heartbeat_get); + server.post('/auth/login/facebook', authloginFacebook_post); + server.get('/user/:email/password', forgotPassword_get); + server.post(config.passThroughEndpoint.path, createUser_post); + server.get('/user/activate', activateUser_get); + server.post('/user/activate', activateUser_post); + server.post('/user/email/available', checkEmailAvailability_post); + server.put('/user/me/password', checkAccessTokenParam, checkAuthHeader, decodeToken, bodyRequired, findUser, validateOldPassword, setPassword); +}; diff --git a/src/public_routes/user/activateUser_get.js b/src/routes_public/user/activateUser_get.js similarity index 100% rename from src/public_routes/user/activateUser_get.js rename to src/routes_public/user/activateUser_get.js diff --git a/src/public_routes/user/checkEmailAvailability_post.js b/src/routes_public/user/checkEmailAvailability_post.js similarity index 100% rename from src/public_routes/user/checkEmailAvailability_post.js rename to src/routes_public/user/checkEmailAvailability_post.js diff --git a/src/public_routes/user/createUser_post.js b/src/routes_public/user/createUser_post.js similarity index 100% rename from src/public_routes/user/createUser_post.js rename to src/routes_public/user/createUser_post.js diff --git a/src/public_routes/user/forgotPassword_get.js b/src/routes_public/user/forgotPassword_get.js similarity index 100% rename from src/public_routes/user/forgotPassword_get.js rename to src/routes_public/user/forgotPassword_get.js diff --git a/src/routes_public/user/setPassword_put.js b/src/routes_public/user/setPassword_put.js new file mode 100644 index 0000000..cf453ac --- /dev/null +++ b/src/routes_public/user/setPassword_put.js @@ -0,0 +1,22 @@ +'use strict'; + +var userMng = require('../../managers/user'); + +module.exports = function (req, res, next) { + userMng().setPassword(req.user._id, req.body, function (err) { + if (err) { + if (!err.code) { + res.send(500, err); + return next(false); + } + + var errCode = err.code; + delete(err.code); + res.send(errCode, err); + return next(false); + } + + res.send(204); + return next(); + }); +}; diff --git a/src/routes_public/user/validateOldPassword_put.js b/src/routes_public/user/validateOldPassword_put.js new file mode 100644 index 0000000..1aba948 --- /dev/null +++ b/src/routes_public/user/validateOldPassword_put.js @@ -0,0 +1,28 @@ +'use strict'; + +var config = require(process.cwd() + '/config.json'); +var userMng = require('../../managers/user'); + +module.exports = function validateOldPassword(req, res, next) { + var err; + if (!config.password.validateOldPassword) { + return next(); + } + + if (!req.body.oldPassword) { + err = { + err: 'missing_password', + des: 'Missing old password validation' + }; + res.send(400, err); + return next(false); + } + + userMng().validateOldPassword(req.user.username, req.body.oldPassword, function (err) { + if (err) { + res.send(401, err); + return next(false); + } + return next(); + }); +}; diff --git a/features/cors.feature b/tests-acceptance/cors.feature similarity index 100% rename from features/cors.feature rename to tests-acceptance/cors.feature diff --git a/features/forgot_passwd.feature b/tests-acceptance/forgot_passwd.feature similarity index 100% rename from features/forgot_passwd.feature rename to tests-acceptance/forgot_passwd.feature diff --git a/features/google.feature b/tests-acceptance/google.feature similarity index 100% rename from features/google.feature rename to tests-acceptance/google.feature diff --git a/features/linkedin.feature b/tests-acceptance/linkedin.feature similarity index 100% rename from features/linkedin.feature rename to tests-acceptance/linkedin.feature diff --git a/features/login.feature b/tests-acceptance/login.feature similarity index 100% rename from features/login.feature rename to tests-acceptance/login.feature diff --git a/features/post_profile.feature b/tests-acceptance/post_profile.feature similarity index 100% rename from features/post_profile.feature rename to tests-acceptance/post_profile.feature diff --git a/features/proxy.feature b/tests-acceptance/proxy.feature similarity index 100% rename from features/proxy.feature rename to tests-acceptance/proxy.feature diff --git a/features/restrictedArea.feature b/tests-acceptance/restrictedArea.feature similarity index 100% rename from features/restrictedArea.feature rename to tests-acceptance/restrictedArea.feature diff --git a/features/salesforce.feature b/tests-acceptance/salesforce.feature similarity index 100% rename from features/salesforce.feature rename to tests-acceptance/salesforce.feature diff --git a/features/step_definitions/client_application_with_valid_token.js b/tests-acceptance/step_definitions/client_application_with_valid_token.js similarity index 100% rename from features/step_definitions/client_application_with_valid_token.js rename to tests-acceptance/step_definitions/client_application_with_valid_token.js diff --git a/features/step_definitions/client_pass_through.js b/tests-acceptance/step_definitions/client_pass_through.js similarity index 100% rename from features/step_definitions/client_pass_through.js rename to tests-acceptance/step_definitions/client_pass_through.js diff --git a/features/step_definitions/client_pass_through_pin.js b/tests-acceptance/step_definitions/client_pass_through_pin.js similarity index 100% rename from features/step_definitions/client_pass_through_pin.js rename to tests-acceptance/step_definitions/client_pass_through_pin.js diff --git a/features/step_definitions/config_params.js b/tests-acceptance/step_definitions/config_params.js similarity index 100% rename from features/step_definitions/config_params.js rename to tests-acceptance/step_definitions/config_params.js diff --git a/features/step_definitions/google/google_callback_response.js b/tests-acceptance/step_definitions/google/google_callback_response.js similarity index 100% rename from features/step_definitions/google/google_callback_response.js rename to tests-acceptance/step_definitions/google/google_callback_response.js diff --git a/features/step_definitions/google/request_login_with_google.js b/tests-acceptance/step_definitions/google/request_login_with_google.js similarity index 100% rename from features/step_definitions/google/request_login_with_google.js rename to tests-acceptance/step_definitions/google/request_login_with_google.js diff --git a/features/step_definitions/linkedin_callback_response.js b/tests-acceptance/step_definitions/linkedin_callback_response.js similarity index 100% rename from features/step_definitions/linkedin_callback_response.js rename to tests-acceptance/step_definitions/linkedin_callback_response.js diff --git a/features/step_definitions/login_invalid_request.js b/tests-acceptance/step_definitions/login_invalid_request.js similarity index 100% rename from features/step_definitions/login_invalid_request.js rename to tests-acceptance/step_definitions/login_invalid_request.js diff --git a/features/step_definitions/login_invalid_username.js b/tests-acceptance/step_definitions/login_invalid_username.js similarity index 100% rename from features/step_definitions/login_invalid_username.js rename to tests-acceptance/step_definitions/login_invalid_username.js diff --git a/features/step_definitions/login_valid_request.js b/tests-acceptance/step_definitions/login_valid_request.js similarity index 100% rename from features/step_definitions/login_valid_request.js rename to tests-acceptance/step_definitions/login_valid_request.js diff --git a/features/step_definitions/method_request_to_path.js b/tests-acceptance/step_definitions/method_request_to_path.js similarity index 100% rename from features/step_definitions/method_request_to_path.js rename to tests-acceptance/step_definitions/method_request_to_path.js diff --git a/features/step_definitions/protected_service_call.js b/tests-acceptance/step_definitions/protected_service_call.js similarity index 100% rename from features/step_definitions/protected_service_call.js rename to tests-acceptance/step_definitions/protected_service_call.js diff --git a/features/step_definitions/protected_service_definiton.js b/tests-acceptance/step_definitions/protected_service_definiton.js similarity index 100% rename from features/step_definitions/protected_service_definiton.js rename to tests-acceptance/step_definitions/protected_service_definiton.js diff --git a/features/step_definitions/reques_login_with_linkedin.js b/tests-acceptance/step_definitions/reques_login_with_linkedin.js similarity index 100% rename from features/step_definitions/reques_login_with_linkedin.js rename to tests-acceptance/step_definitions/reques_login_with_linkedin.js diff --git a/features/step_definitions/response_body_contains_json_attribute.js b/tests-acceptance/step_definitions/response_body_contains_json_attribute.js similarity index 100% rename from features/step_definitions/response_body_contains_json_attribute.js rename to tests-acceptance/step_definitions/response_body_contains_json_attribute.js diff --git a/features/step_definitions/response_body_content.js b/tests-acceptance/step_definitions/response_body_content.js similarity index 100% rename from features/step_definitions/response_body_content.js rename to tests-acceptance/step_definitions/response_body_content.js diff --git a/features/step_definitions/response_has_no_error.js b/tests-acceptance/step_definitions/response_has_no_error.js similarity index 100% rename from features/step_definitions/response_has_no_error.js rename to tests-acceptance/step_definitions/response_has_no_error.js diff --git a/features/step_definitions/response_header_content.js b/tests-acceptance/step_definitions/response_header_content.js similarity index 100% rename from features/step_definitions/response_header_content.js rename to tests-acceptance/step_definitions/response_header_content.js diff --git a/features/step_definitions/response_headers_contains_attribute.js b/tests-acceptance/step_definitions/response_headers_contains_attribute.js similarity index 100% rename from features/step_definitions/response_headers_contains_attribute.js rename to tests-acceptance/step_definitions/response_headers_contains_attribute.js diff --git a/features/step_definitions/response_status_code_value.js b/tests-acceptance/step_definitions/response_status_code_value.js similarity index 100% rename from features/step_definitions/response_status_code_value.js rename to tests-acceptance/step_definitions/response_status_code_value.js diff --git a/features/step_definitions/salesforce/login_process.js b/tests-acceptance/step_definitions/salesforce/login_process.js similarity index 100% rename from features/step_definitions/salesforce/login_process.js rename to tests-acceptance/step_definitions/salesforce/login_process.js diff --git a/features/step_definitions/salesforce/salesforce_callback.js b/tests-acceptance/step_definitions/salesforce/salesforce_callback.js similarity index 100% rename from features/step_definitions/salesforce/salesforce_callback.js rename to tests-acceptance/step_definitions/salesforce/salesforce_callback.js diff --git a/features/step_definitions/salesforce/user_linked_to_salesforce.js b/tests-acceptance/step_definitions/salesforce/user_linked_to_salesforce.js similarity index 94% rename from features/step_definitions/salesforce/user_linked_to_salesforce.js rename to tests-acceptance/step_definitions/salesforce/user_linked_to_salesforce.js index 98cd96a..f62ca4d 100644 --- a/features/step_definitions/salesforce/user_linked_to_salesforce.js +++ b/tests-acceptance/step_definitions/salesforce/user_linked_to_salesforce.js @@ -16,7 +16,7 @@ module.exports = function () { }]; var options = { - url: 'http://localhost:' + config.public_port + '/auth/user', + url: 'http://localhost:' + config.internal_port + '/auth/user', headers: { 'Content-Type': 'application/json; charset=utf-8', 'Authorization': 'basic ' + new Buffer(config.management.clientId + ':' + config.management.clientSecret).toString('base64') diff --git a/features/step_definitions/salesforce/user_not_linked_to_salesforce.js b/tests-acceptance/step_definitions/salesforce/user_not_linked_to_salesforce.js similarity index 93% rename from features/step_definitions/salesforce/user_not_linked_to_salesforce.js rename to tests-acceptance/step_definitions/salesforce/user_not_linked_to_salesforce.js index a8e2716..8041df5 100644 --- a/features/step_definitions/salesforce/user_not_linked_to_salesforce.js +++ b/tests-acceptance/step_definitions/salesforce/user_not_linked_to_salesforce.js @@ -10,7 +10,7 @@ module.exports = function () { world.getUser().password = 'valid_password'; var options = { - url: 'http://localhost:' + config.public_port + '/auth/user', + url: 'http://localhost:' + config.internal_port + '/auth/user', headers: { 'Content-Type': 'application/json; charset=utf-8', 'Authorization': 'basic ' + new Buffer(config.management.clientId + ':' + config.management.clientSecret).toString('base64') diff --git a/features/step_definitions/the_app_requests_a_magic_link_for_a_valid_user.js b/tests-acceptance/step_definitions/the_app_requests_a_magic_link_for_a_valid_user.js similarity index 100% rename from features/step_definitions/the_app_requests_a_magic_link_for_a_valid_user.js rename to tests-acceptance/step_definitions/the_app_requests_a_magic_link_for_a_valid_user.js diff --git a/features/step_definitions/the_response_headers_contains_the_header_x.js b/tests-acceptance/step_definitions/the_response_headers_contains_the_header_x.js similarity index 100% rename from features/step_definitions/the_response_headers_contains_the_header_x.js rename to tests-acceptance/step_definitions/the_response_headers_contains_the_header_x.js diff --git a/features/step_definitions/the_user_clicks_the_received_magic_link.js b/tests-acceptance/step_definitions/the_user_clicks_the_received_magic_link.js similarity index 100% rename from features/step_definitions/the_user_clicks_the_received_magic_link.js rename to tests-acceptance/step_definitions/the_user_clicks_the_received_magic_link.js diff --git a/features/step_definitions/the_user_receives_a_magic_link_email.js b/tests-acceptance/step_definitions/the_user_receives_a_magic_link_email.js similarity index 100% rename from features/step_definitions/the_user_receives_a_magic_link_email.js rename to tests-acceptance/step_definitions/the_user_receives_a_magic_link_email.js diff --git a/features/step_definitions/user_with_valid_credentials.js b/tests-acceptance/step_definitions/user_with_valid_credentials.js similarity index 93% rename from features/step_definitions/user_with_valid_credentials.js rename to tests-acceptance/step_definitions/user_with_valid_credentials.js index f032c1a..4eba9f9 100644 --- a/features/step_definitions/user_with_valid_credentials.js +++ b/tests-acceptance/step_definitions/user_with_valid_credentials.js @@ -9,7 +9,7 @@ module.exports = function () { world.getUser().password = 'valid_password'; var options = { - url: 'http://localhost:' + config.public_port + '/auth/user', + url: 'http://localhost:' + config.internal_port + '/auth/user', headers: { 'Content-Type': 'application/json; charset=utf-8', 'Authorization': 'basic ' + new Buffer(config.management.clientId + ':' + config.management.clientSecret).toString('base64') diff --git a/features/support/hooks.js b/tests-acceptance/support/hooks.js similarity index 100% rename from features/support/hooks.js rename to tests-acceptance/support/hooks.js diff --git a/features/support/service.js b/tests-acceptance/support/service.js similarity index 93% rename from features/support/service.js rename to tests-acceptance/support/service.js index 920dc51..1073a33 100644 --- a/features/support/service.js +++ b/tests-acceptance/support/service.js @@ -12,7 +12,7 @@ module.exports = function () { cipherlayer.start(config.public_port, config.internal_port, function (err) { assert.equal(err, null); var options = { - url: 'http://localhost:' + config.public_port + '/auth/user', + url: 'http://localhost:' + config.internal_port + '/auth/user', headers: { 'Content-Type': 'application/json; charset=utf-8', 'Authorization': 'basic ' + new Buffer(config.management.clientId + ':' + config.management.clientSecret).toString('base64') diff --git a/features/support/serviceValidCors.js b/tests-acceptance/support/serviceValidCors.js similarity index 94% rename from features/support/serviceValidCors.js rename to tests-acceptance/support/serviceValidCors.js index ed0e5ec..be15118 100644 --- a/features/support/serviceValidCors.js +++ b/tests-acceptance/support/serviceValidCors.js @@ -17,7 +17,7 @@ module.exports = function () { cipherlayer.start(config.public_port, config.internal_port, function (err) { assert.equal(err, null); var options = { - url: 'http://localhost:' + config.public_port + '/auth/user', + url: 'http://localhost:' + config.internal_port + '/auth/user', headers: { 'Content-Type': 'application/json; charset=utf-8', 'Authorization': 'basic ' + new Buffer(config.management.clientId + ':' + config.management.clientSecret).toString('base64') diff --git a/features/support/world.js b/tests-acceptance/support/world.js similarity index 100% rename from features/support/world.js rename to tests-acceptance/support/world.js diff --git a/tests/auth.js b/tests-unit/auth.js similarity index 100% rename from tests/auth.js rename to tests-unit/auth.js diff --git a/tests/auth/facebook_token.js b/tests-unit/auth/facebook_token.js similarity index 100% rename from tests/auth/facebook_token.js rename to tests-unit/auth/facebook_token.js diff --git a/tests/auth/google.js b/tests-unit/auth/google.js similarity index 100% rename from tests/auth/google.js rename to tests-unit/auth/google.js diff --git a/tests/auth/in.js b/tests-unit/auth/in.js similarity index 100% rename from tests/auth/in.js rename to tests-unit/auth/in.js diff --git a/tests/auth/login.js b/tests-unit/auth/login.js similarity index 100% rename from tests/auth/login.js rename to tests-unit/auth/login.js diff --git a/tests/auth/logout.js b/tests-unit/auth/logout.js similarity index 100% rename from tests/auth/logout.js rename to tests-unit/auth/logout.js diff --git a/tests/auth/renew.js b/tests-unit/auth/renew.js similarity index 100% rename from tests/auth/renew.js rename to tests-unit/auth/renew.js diff --git a/tests/auth/sf.js b/tests-unit/auth/sf.js similarity index 100% rename from tests/auth/sf.js rename to tests-unit/auth/sf.js diff --git a/tests/auth/user.js b/tests-unit/auth/user.js similarity index 95% rename from tests/auth/user.js rename to tests-unit/auth/user.js index 7805501..f60a011 100644 --- a/tests/auth/user.js +++ b/tests-unit/auth/user.js @@ -26,7 +26,7 @@ module.exports = { it('POST 201 created', function (done) { var options = { - url: 'http://' + config.private_host + ':' + config.public_port + '/auth/user', + url: 'http://' + config.private_host + ':' + config.internal_port + '/auth/user', headers: HEADERS_WITH_AUTHORIZATION_BASIC, method: 'POST', body: JSON.stringify({username: username, password: password, phone: phone}) @@ -45,7 +45,7 @@ module.exports = { it('401 Not authorized when trying to POST to /auth/user without basic authorization', function (done) { var options = { - url: 'http://' + config.private_host + ':' + config.public_port + '/auth/user', + url: 'http://' + config.private_host + ':' + config.internal_port + '/auth/user', headers: HEADERS_WITHOUT_AUTHORIZATION_BASIC, method: 'POST', body: JSON.stringify({username: username, password: password}) @@ -65,7 +65,7 @@ module.exports = { assert.notEqual(createdUser, null); var options = { - url: 'http://' + config.private_host + ':' + config.public_port + '/auth/user', + url: 'http://' + config.private_host + ':' + config.internal_port + '/auth/user', headers: HEADERS_WITH_AUTHORIZATION_BASIC, method: 'POST', body: JSON.stringify({username: USER.username, password: USER.password}) @@ -88,7 +88,7 @@ module.exports = { assert.notEqual(createdUser, null); var options = { - url: 'http://' + config.private_host + ':' + config.public_port + '/auth/user', + url: 'http://' + config.private_host + ':' + config.internal_port + '/auth/user', headers: HEADERS_WITHOUT_AUTHORIZATION_BASIC, method: 'POST', body: JSON.stringify({username: USER.username, password: USER.password}) @@ -108,7 +108,7 @@ module.exports = { assert.notEqual(createdUser, null); var options = { - url: 'http://' + config.private_host + ':' + config.public_port + '/auth/user', + url: 'http://' + config.private_host + ':' + config.internal_port + '/auth/user', headers: HEADERS_WITH_AUTHORIZATION_BASIC, method: 'DELETE' }; @@ -133,7 +133,7 @@ module.exports = { assert.notEqual(createdUser, null); var options = { - url: 'http://' + config.private_host + ':' + config.public_port + '/auth/user', + url: 'http://' + config.private_host + ':' + config.internal_port + '/auth/user', headers: HEADERS_WITHOUT_AUTHORIZATION_BASIC, method: 'DELETE' }; diff --git a/tests/crypto.js b/tests-unit/crypto.js similarity index 100% rename from tests/crypto.js rename to tests-unit/crypto.js diff --git a/tests/dao.js b/tests-unit/dao.js similarity index 100% rename from tests/dao.js rename to tests-unit/dao.js diff --git a/tests/email.js b/tests-unit/email.js similarity index 100% rename from tests/email.js rename to tests-unit/email.js diff --git a/tests/emailAvailable.js b/tests-unit/emailAvailable.js similarity index 100% rename from tests/emailAvailable.js rename to tests-unit/emailAvailable.js diff --git a/tests/fileStore.js b/tests-unit/fileStore.js similarity index 100% rename from tests/fileStore.js rename to tests-unit/fileStore.js diff --git a/tests/fixtures/User.json b/tests-unit/fixtures/User.json similarity index 100% rename from tests/fixtures/User.json rename to tests-unit/fixtures/User.json diff --git a/tests/heartbeat.js b/tests-unit/heartbeat.js similarity index 100% rename from tests/heartbeat.js rename to tests-unit/heartbeat.js diff --git a/tests/jsonValidator.js b/tests-unit/jsonValidator.js similarity index 100% rename from tests/jsonValidator.js rename to tests-unit/jsonValidator.js diff --git a/tests/managerToken.js b/tests-unit/managerToken.js similarity index 100% rename from tests/managerToken.js rename to tests-unit/managerToken.js diff --git a/tests/managerUser.js b/tests-unit/managerUser.js similarity index 100% rename from tests/managerUser.js rename to tests-unit/managerUser.js diff --git a/tests/managers/crypto.js b/tests-unit/managers/crypto.js similarity index 100% rename from tests/managers/crypto.js rename to tests-unit/managers/crypto.js diff --git a/tests/managers/email.js b/tests-unit/managers/email.js similarity index 100% rename from tests/managers/email.js rename to tests-unit/managers/email.js diff --git a/tests/middlewares/authHeaderRequired.js b/tests-unit/middlewares/authHeaderRequired.js similarity index 100% rename from tests/middlewares/authHeaderRequired.js rename to tests-unit/middlewares/authHeaderRequired.js diff --git a/tests/middlewares/decodeToken.js b/tests-unit/middlewares/decodeToken.js similarity index 100% rename from tests/middlewares/decodeToken.js rename to tests-unit/middlewares/decodeToken.js diff --git a/tests/phone.js b/tests-unit/phone.js similarity index 100% rename from tests/phone.js rename to tests-unit/phone.js diff --git a/tests/pinValidation.js b/tests-unit/pinValidation.js similarity index 100% rename from tests/pinValidation.js rename to tests-unit/pinValidation.js diff --git a/tests/platforms/salesforce.js b/tests-unit/platforms/salesforce.js similarity index 100% rename from tests/platforms/salesforce.js rename to tests-unit/platforms/salesforce.js diff --git a/tests/prepareOptions.js b/tests-unit/prepareOptions.js similarity index 100% rename from tests/prepareOptions.js rename to tests-unit/prepareOptions.js diff --git a/tests/proxy.js b/tests-unit/proxy.js similarity index 100% rename from tests/proxy.js rename to tests-unit/proxy.js diff --git a/tests/proxy/protectedCallsPassThrough.js b/tests-unit/proxy/protectedCallsPassThrough.js similarity index 100% rename from tests/proxy/protectedCallsPassThrough.js rename to tests-unit/proxy/protectedCallsPassThrough.js diff --git a/tests/proxy/protectedCallsStandard-platformSF.js b/tests-unit/proxy/protectedCallsStandard-platformSF.js similarity index 100% rename from tests/proxy/protectedCallsStandard-platformSF.js rename to tests-unit/proxy/protectedCallsStandard-platformSF.js diff --git a/tests/proxy/protectedCallsStandard.js b/tests-unit/proxy/protectedCallsStandard.js similarity index 100% rename from tests/proxy/protectedCallsStandard.js rename to tests-unit/proxy/protectedCallsStandard.js diff --git a/tests/public_routes/auth/loginEmail_post.js b/tests-unit/public_routes/auth/loginEmail_post.js similarity index 96% rename from tests/public_routes/auth/loginEmail_post.js rename to tests-unit/public_routes/auth/loginEmail_post.js index 86a644a..64a1ef9 100644 --- a/tests/public_routes/auth/loginEmail_post.js +++ b/tests-unit/public_routes/auth/loginEmail_post.js @@ -83,7 +83,7 @@ describe('public routes', function () { done(); }; - var loginEmail_post = require('../../../src/public_routes/auth/loginEmail_post.js'); + var loginEmail_post = require('../../../src/routes_public/auth/loginEmail_post.js'); loginEmail_post(req, res, next); }); @@ -120,7 +120,7 @@ describe('public routes', function () { }; var nextSpy = sinon.spy(next, 'next'); - var loginEmail_post = require('../../../src/public_routes/auth/loginEmail_post.js'); + var loginEmail_post = require('../../../src/routes_public/auth/loginEmail_post.js'); loginEmail_post(req, res, next.next); }); }); diff --git a/tests/public_routes/auth/loginRefreshToken.js b/tests-unit/public_routes/auth/loginRefreshToken.js similarity index 93% rename from tests/public_routes/auth/loginRefreshToken.js rename to tests-unit/public_routes/auth/loginRefreshToken.js index 89a9d5b..78d0b7b 100644 --- a/tests/public_routes/auth/loginRefreshToken.js +++ b/tests-unit/public_routes/auth/loginRefreshToken.js @@ -68,7 +68,7 @@ describe('public routes', function () { }; var nextSpy = sinon.spy(next, 'next'); - var loginRefreshToken_get = require('../../../src/public_routes/auth/loginRefreshToken_get.js'); + var loginRefreshToken_get = require('../../../src/routes_public/auth/loginRefreshToken_get.js'); loginRefreshToken_get(req, res, next.next); }); @@ -114,7 +114,7 @@ describe('public routes', function () { }; var nextSpy = sinon.spy(next, 'next'); - var loginRefreshToken_get = require('../../../src/public_routes/auth/loginRefreshToken_get.js'); + var loginRefreshToken_get = require('../../../src/routes_public/auth/loginRefreshToken_get.js'); loginRefreshToken_get(req, res, next.next); }); @@ -148,7 +148,7 @@ describe('public routes', function () { }; var nextSpy = sinon.spy(next, 'next'); - var loginRefreshToken_get = require('../../../src/public_routes/auth/loginRefreshToken_get.js'); + var loginRefreshToken_get = require('../../../src/routes_public/auth/loginRefreshToken_get.js'); loginRefreshToken_get(req, res, next.next); }); }); diff --git a/tests/public_routes/user/forgotPassword_get.js b/tests-unit/public_routes/user/forgotPassword_get.js similarity index 98% rename from tests/public_routes/user/forgotPassword_get.js rename to tests-unit/public_routes/user/forgotPassword_get.js index 16c48ef..d582c41 100644 --- a/tests/public_routes/user/forgotPassword_get.js +++ b/tests-unit/public_routes/user/forgotPassword_get.js @@ -105,7 +105,7 @@ describe('public routes', function () { done(); }; - var forgotPassword_get = require('../../../src/public_routes/user/forgotPassword_get'); + var forgotPassword_get = require('../../../src/routes_public/user/forgotPassword_get'); forgotPassword_get(req, res, next); }); diff --git a/tests/redirect.js b/tests-unit/redirect.js similarity index 100% rename from tests/redirect.js rename to tests-unit/redirect.js diff --git a/tests/redis.js b/tests-unit/redis.js similarity index 100% rename from tests/redis.js rename to tests-unit/redis.js diff --git a/tests/resources/sfProfileTemplate.js b/tests-unit/resources/sfProfileTemplate.js similarity index 100% rename from tests/resources/sfProfileTemplate.js rename to tests-unit/resources/sfProfileTemplate.js diff --git a/tests/routesRealms.js b/tests-unit/routesRealms.js similarity index 100% rename from tests/routesRealms.js rename to tests-unit/routesRealms.js diff --git a/tests/routesUser.js b/tests-unit/routesUser.js similarity index 100% rename from tests/routesUser.js rename to tests-unit/routesUser.js diff --git a/tests/server.js b/tests-unit/server.js similarity index 100% rename from tests/server.js rename to tests-unit/server.js diff --git a/tests/test_files/1234.jpg b/tests-unit/test_files/1234.jpg similarity index 100% rename from tests/test_files/1234.jpg rename to tests-unit/test_files/1234.jpg diff --git a/tests/test_files/empty proj.zip b/tests-unit/test_files/empty proj.zip similarity index 100% rename from tests/test_files/empty proj.zip rename to tests-unit/test_files/empty proj.zip diff --git a/tests/test_files/empty.jpg b/tests-unit/test_files/empty.jpg similarity index 100% rename from tests/test_files/empty.jpg rename to tests-unit/test_files/empty.jpg diff --git a/tests/test_files/empty.png b/tests-unit/test_files/empty.png similarity index 100% rename from tests/test_files/empty.png rename to tests-unit/test_files/empty.png diff --git a/tests/userAppVersion.js b/tests-unit/userAppVersion.js similarity index 100% rename from tests/userAppVersion.js rename to tests-unit/userAppVersion.js diff --git a/tests/verifyPhone.js b/tests-unit/verifyPhone.js similarity index 100% rename from tests/verifyPhone.js rename to tests-unit/verifyPhone.js