Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1f08eaf
Added fixtures script to add users to DB
igznicolasjaremek Mar 17, 2015
49deffa
Merge branch 'cipher-users'
igznicolasjaremek Mar 17, 2015
e43a703
Merge branch 'master' of https://github.com/thegameofcode/cipherlayer
Mar 17, 2015
01f6def
Added env var for default password. Added default password for users.
igznicolasjaremek Mar 17, 2015
2fdd81e
added x-user-id header on directproxy request
Apr 8, 2015
9267a81
Merge remote-tracking branch 'upstream/master' into upstream-changes
Apr 21, 2015
50918ce
added verify old password functionality
Apr 21, 2015
1aca4bb
temporally skipped tests userAppVersion
Apr 21, 2015
9ca1c3e
Revert "Added middleware "userAppVersion" (update user info with his …
Apr 21, 2015
bbdcbf5
Merge branch 'master' of https://github.com/thegameofcode/cipherlayer
May 18, 2015
89a7a57
merged upstream master
Sep 9, 2015
fef9adf
fixed package and removed log
Sep 9, 2015
9fc9a9c
Added configuration parameter to define externalNotifications service…
igznicolasjaremek Sep 24, 2015
ca8d1ee
Updated tests for new configuration.
igznicolasjaremek Sep 24, 2015
ba61f47
Made JSON validator mandatory. Improved configuration file format.
igznicolasjaremek Sep 24, 2015
16cc102
Resetted hostnames for db and redis in config sample.
igznicolasjaremek Sep 30, 2015
7a3ad33
Merge pull request #1 from IGZgustavomarin/feature/improved-configura…
Sep 30, 2015
14cbf9f
add support to transfer a list of allowedHeaders in the configuration
Oct 13, 2015
f1e01d8
ADDED optional configuration to redirect to URL on email confirmation…
igznicolasjaremek Oct 14, 2015
ab4b620
Merge pull request #2 from IGZgustavomarin/feature/redirect-after-signup
Oct 14, 2015
971abde
Added from field to email endpoints.
igznicolasjaremek Oct 21, 2015
01bf244
Merge pull request #3 from IGZgustavomarin/feature/add-email-from-field
Oct 21, 2015
3a6214d
Removed buggy debug line causing a timeout error.
igznicolasjaremek Dec 3, 2015
b3503ca
Merge pull request #4 from IGZgustavomarin/fix/broken-password-validate
igznicolasjaremek Dec 3, 2015
4a075bd
Added begin/end characters to username lookup expression for exact ma…
igznicolasjaremek Dec 14, 2015
6bddeb3
Added Cucumber and Mocha tests to ensure the exact match during user …
igznicolasjaremek Dec 14, 2015
75e0ddc
Merge pull request #5 from IGZgustavomarin/fix/username-lookup-regex
Dec 14, 2015
b23caa8
merged upstream
Jan 26, 2016
d4274e2
Merge pull request #6 from IGZgustavomarin/merged-upstream
Jan 26, 2016
d2f9dac
added configurable email field
Jan 28, 2016
1ac06b6
Fixed security vulnerability and profile schema loader.
igznicolasjaremek Jan 28, 2016
5bd13a6
different approach to remove password from body
Jan 29, 2016
a34e694
fixed redis key to avoid undefined values
Jan 29, 2016
8ed779b
added autologin after email verification
Jan 29, 2016
af9eef4
Merge pull request #7 from IGZgustavomarin/feature/login-with-verific…
Jan 29, 2016
12566c3
Stringify body in prepareOptions middleware only if body exists, in o…
igznicolasjaremek Feb 1, 2016
c59293d
Merge pull request #8 from IGZgustavomarin/fix/prepare-options-body
Feb 1, 2016
ee430d2
Added public endpoint to check email availability.
igznicolasjaremek Feb 3, 2016
d08e263
Merge pull request #9 from IGZgustavomarin/feature/email-available
Feb 3, 2016
2ab164a
WIP login with facebook
Feb 4, 2016
8886af1
Added tests for facebook auth endpoint. Fixed auth endpoint. Updated …
igznicolasjaremek Feb 4, 2016
a9bed32
Merge pull request #11 from IGZgustavomarin/feature/facebook-login
Feb 4, 2016
8e8811b
hotfix config facebook
Feb 4, 2016
628a6e8
Added test for facebook login in case email is missing from request b…
igznicolasjaremek Feb 5, 2016
09542ce
Updated missing email facebook auth test case.
igznicolasjaremek Feb 5, 2016
7e62f7f
Merge pull request #12 from IGZgustavomarin/fix/facebook-login
Feb 5, 2016
4f55f22
indent refactor
luismesas Feb 8, 2016
aab45e2
Merged Gustavo branch with master branch
luismesas Feb 8, 2016
097fc71
added verbose option to coveralls script
luismesas Feb 8, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions config_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,28 @@
"clientSecret": "{{GOOGLE_CLIENT_SECRET}}",
"callbackURL": "http://localhost:3000/auth/google/callback"
},
"aws": {
"facebook": {
"registerByToken": true,
"requestFields": "name,email,picture",
"fieldsMap": {
"name": "fullname",
"email": "email"
}
},
"aws":{
"accessKeyId": "{{AWS_ACCESKEYID}}",
"secretAccessKey": "{{AWS_SECRETACCESKEY}}",
"region": "us-west-2",
"buckets": {
"avatars": "example-avatars"
}
},
"validators": {
"profile": {
"path": "",
"filename": "profile_create.json"
}
},
"phoneVerification": {
"pinSize": 4,
"attempts": 3,
Expand All @@ -104,6 +118,7 @@
},
"emailVerification": {
"subject": "Example email verification",
"from": "hello@example.com",
"body": "<p>Thanks for register into Example, here is a link to activate your account click</p> <p><a href='{link}' >here</a></p> <p>If you have any problems on this process, please contact <a href='mailto:support@example.com'>support@example.com</a> and we will be pleased to help you.</p>",
"compatibleEmailDevices": [
"*iPhone*",
Expand All @@ -116,10 +131,14 @@
"key": "user.{username}.transaction",
"expireInSec": 86400
},
"scheme": "mycomms"
"scheme":"mycomms",
"redirectUrl": "http://www.google.com"
},
"externalServices": {
"notifications": "http://localhost:3002"
"notifications": {
"base": "http://localhost:3002",
"pathEmail": "/api/notification/email"
}
},
"version": {
"header": "x-example-version",
Expand All @@ -133,9 +152,11 @@
"db": "mongodb://localhost/versionControl?w=1"
},
"allowedDomains": [
"*@a.com"
"*@a.com",
"*@facebook.com"
],
"password": {
"password":{
"validateOldPassword": false,
"regexValidation": "(?=.*\\d)(?=.*[A-Z])(?=.*[a-z]).{8}",
"message": "Your password must be at least 8 characters and must contain at least one capital, one lower and one number.",
"generatedRegex": "([a-z][\\d][A-Z]){3,4}",
Expand Down Expand Up @@ -178,5 +199,8 @@
},
"directProxyUrls": [
"\/upload$"
],
"allowedHeaders": [
"x-custom-header"
]
}
1 change: 1 addition & 0 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"properties": {
"path": {"type": "string", "required": true},
"username": {"type": "string", "required": true},
"email": {"type": "string", "required": false},
"password": {"type": "string", "required": true}
},
"required": true
Expand Down
12 changes: 6 additions & 6 deletions features/forgot_passwd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Feature: client application requests recover password
When the client makes a <METHOD> request to <PATH>
Then the response status code is 204

Examples:
| METHOD | PATH |
| GET | /user/:email/password |
Examples:
| METHOD | PATH |
| GET | /user/:email/password |


@service
Expand All @@ -22,6 +22,6 @@ Feature: client application requests recover password
And the response body contains json attribute "refreshToken"
And the response body contains json attribute "expiresIn"

Examples:
| METHOD | PATH |
| GET | /user/:email/password |
Examples:
| METHOD | PATH |
| GET | /user/:email/password |
18 changes: 15 additions & 3 deletions features/proxy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ Feature: reverse proxy protects an applicacion behind cipherlayer
Then the response status code is <STATUS>
And the response body must be <RESPONSE_PAYLOAD>
Examples:
| PATH | METHOD | STATUS | REQUEST_PAYLOAD | RESPONSE_PAYLOAD |
| /test/get200 | GET | 200 | | {"m":"GET", "s":"200"} |
| /test/post200 | POST | 200 | {"key":"value"} | {"m":"POST", "s":"200"} |
| PATH | METHOD | STATUS | REQUEST_PAYLOAD | RESPONSE_PAYLOAD |
| /test/get200 | GET | 200 | | {"m":"GET", "s":"200"} |
| /test/post200 | POST | 200 | {"key":"value"} | {"m":"POST", "s":"200"} |

@service
Scenario Outline: A protected service returns a response header
Given a user with role user and a valid access token
And a protected service replies to a <METHOD> request with <REQUEST_PAYLOAD> to <PATH> with status <STATUS> and a body <RESPONSE_PAYLOAD> and header <ALLOWED_HEADER> and value <HEADER_VALUE>
When the application makes a <METHOD> with <REQUEST_PAYLOAD> to a protected <PATH>
Then the response status code is <STATUS>
And the response body must be <RESPONSE_PAYLOAD>
And the response headers contains the <ALLOWED_HEADER> with <HEADER_VALUE>
Examples:
| PATH | METHOD | STATUS | REQUEST_PAYLOAD | RESPONSE_PAYLOAD | ALLOWED_HEADER | HEADER_VALUE |
| /test/get200 | GET | 200 | | {"m":"GET", "s":"200"} | x-custom-header | test |
20 changes: 10 additions & 10 deletions features/restrictedArea.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Feature: client application logs in with admin role
When the application makes a <METHOD> with <REQUEST_PAYLOAD> to a protected <PATH>
Then the response status code is <STATUS>
And the response body must be <RESPONSE_PAYLOAD>
Examples:
| PATH | METHOD | STATUS | REQUEST_PAYLOAD | RESPONSE_PAYLOAD |
| /api/profile | GET | 200 | {} | {"data":[]} |
Examples:
| PATH | METHOD | STATUS | REQUEST_PAYLOAD | RESPONSE_PAYLOAD |
| /api/profile | GET | 200 | {} | {"data":[]} |


@service
Expand All @@ -28,9 +28,9 @@ Feature: client application logs in with admin role
And a protected service replies to a <METHOD> request with <REQUEST_PAYLOAD> to <PATH> with status <STATUS> and a body ""
When the application makes a <METHOD> with <REQUEST_PAYLOAD> to a protected <PATH>
Then the response status code is <STATUS>
Examples:
| PATH | METHOD | STATUS | REQUEST_PAYLOAD |
| /api/profile | PUT | 204 | {} |
Examples:
| PATH | METHOD | STATUS | REQUEST_PAYLOAD |
| /api/profile | PUT | 204 | {} |


@service
Expand All @@ -40,7 +40,7 @@ Feature: client application logs in with admin role
When the application makes a <METHOD> with <REQUEST_PAYLOAD> to a protected <PATH>
Then the response status code is <STATUS>
And the response body must be <RESPONSE_PAYLOAD>
Examples:
| PATH | METHOD | STATUS | REQUEST_PAYLOAD | RESPONSE_PAYLOAD |
| /api/profile | GET | 401 | | {"err":"unauthorized"} |
| /api/profile | PUT | 401 | {"key":"value"} | {"err":"unauthorized"} |
Examples:
| PATH | METHOD | STATUS | REQUEST_PAYLOAD | RESPONSE_PAYLOAD |
| /api/profile | GET | 401 | | {"err":"unauthorized"} |
| /api/profile | PUT | 401 | {"key":"value"} | {"err":"unauthorized"} |
2 changes: 1 addition & 1 deletion features/step_definitions/client_pass_through.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var config = require('../../config.json');
module.exports = function(){
this.When(/^the client makes a pass through (.*) with the following (.*) in the body$/, function (METHOD, PUBLIC_PAYLOAD, callback) {

var notifServiceURL = config.externalServices.notifications;
var notifServiceURL = config.externalServices.notifications.base;

var options = {
url: 'http://localhost:' + config.public_port + config.passThroughEndpoint.path,
Expand Down
1 change: 1 addition & 0 deletions features/step_definitions/login_invalid_username.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var config = require('../../config.json');
module.exports = function(){
this.When(/^the client app requests log in the protected application with username substring/, function (callback) {
var username = world.getUser().username;
console.log('Email', username);
world.getUser().username = username.slice(0, username.length / 2);

var options = {
Expand Down
9 changes: 6 additions & 3 deletions features/step_definitions/method_request_to_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ var nock = require('nock');
var request = require('request');
var assert = require('assert');

var NOTIFICATION_SERVICE_URL = config.externalServices.notifications.base;
var NOTIFICATION_EMAIL_SERVICE_PATH = config.externalServices.notifications.pathEmail;

var myStepDefinitionsWrapper = function () {
this.When(/^the client makes a (.*) request to (.*)$/, function (METHOD, PATH, callback) {

Expand All @@ -20,12 +23,12 @@ var myStepDefinitionsWrapper = function () {
};
options.headers[config.version.header] = "test/1";

nock(config.externalServices.notifications)
.post('/notification/email')
nock(NOTIFICATION_SERVICE_URL)
.post(NOTIFICATION_EMAIL_SERVICE_PATH)
.reply(204);

request(options, function(err,res) {
assert.equal(err,null);
assert.equal(err,null);
world.getResponse().statusCode = res.statusCode;
world.getResponse().headers = res.headers;
callback();
Expand Down
2 changes: 2 additions & 0 deletions features/step_definitions/protected_service_call.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module.exports = function(){
} else {
world.getResponse().body = null;
}

world.getResponse().headers = res.headers;
callback();
});
});
Expand Down
15 changes: 14 additions & 1 deletion features/step_definitions/protected_service_definiton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,24 @@ module.exports = function(){
callback();
});

this.Given(/^a protected service replies to a GET request with (.*) to (.*) with status (.*) and a body (.*) and header (.*) and value (.*)$/, function (REQUEST_PAYLOAD, PATH, STATUS, RESPONSE_PAYLOAD, ALLOWED_HEADER, HEADER_VALUE, callback){
var headers = {};
headers[ALLOWED_HEADER] = HEADER_VALUE;
nock('http://localhost:'+config.private_port, {
reqheaders: {
'Content-Type': 'application/json; charset=utf-8',
'x-user-id' : world.getUser().id
}
}).get(PATH).reply(Number(STATUS), JSON.parse(RESPONSE_PAYLOAD), headers);

callback();
});

this.Given(/^a protected service replies to a POST request with (.*) to (.*) with status (.*) and a body (.*)$/, function (REQUEST_PAYLOAD, PATH, STATUS, RESPONSE_PAYLOAD, callback){
nock('http://localhost:'+config.private_port)
.post(PATH, JSON.parse(REQUEST_PAYLOAD))
.reply(Number(STATUS), JSON.parse(RESPONSE_PAYLOAD));

callback();
});

Expand Down
9 changes: 9 additions & 0 deletions features/step_definitions/response_header_content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var world = require('../support/world');
var assert = require('assert');

module.exports = function(){
this.Given(/^the response headers contains the (.*) with (.*)$/, function (ALLOWEDHEADER, HEADERVALUE, callback) {
assert.equal(world.getResponse().headers[ALLOWEDHEADER], HEADERVALUE);
callback();
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"coverage-2": "cp coverage/lcov.info coverage/cucumber.lcov",
"coverage-3": "node_modules/.bin/mocha tests --recursive --require blanket -R mocha-lcov-reporter > coverage/mocha.lcov",
"coverage-4": "node_modules/.bin/lcov-result-merger 'coverage/*.lcov' 'coverage/merged.lcov'",
"coverage-5": "cat ./coverage/merged.lcov | ./node_modules/coveralls/bin/coveralls.js"
"coverage-5": "cat ./coverage/merged.lcov | ./node_modules/coveralls/bin/coveralls.js --verbose"
},
"dependencies": {
"async": "^0.9.0",
Expand Down
98 changes: 98 additions & 0 deletions scripts/add_users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
var async = require('async'),
fs = require('fs'),
nock = require('nock'),
userMng = require('../src/managers/user'),
config = require('../config.json'),
userDao = require('../src/managers/dao.js');
/*
* Objects for `async.eachSeries`
*/

// Function to apply to each fixture
var addFixture = function(fixture, callback) {

var data = fixture;

// Define user object to be passed to userMng
var pin = null;
var profileBody = {
id: data._id.$oid || data._id,
email: data.email,
password: data.password || (process.env.DEFAULT_PASS ? process.env.DEFAULT_PASS : "qwerty")
};

if(!profileBody.id || !profileBody.email || !profileBody.password) {
console.log("Missing mandatory parameter(s)");
return callback();
}
// Nock the createUser URL
nock('http://' + config.private_host + ':' + config.private_port + config.passThroughEndpoint.path, { reqheaders: {
'Content-Type': 'application/json; charset=utf-8'
}})
.post(config.passThroughEndpoint.path)
.reply(201,profileBody);

// Save user data to database
userMng().createUser(profileBody, pin, function(err) {
if(err) {

if (err.err === 'auth_proxy_user_error') {
console.log(profileBody.email + " " + err.des);
return callback();
}
return callback(err);
}
console.log(profileBody.email + " added");
return callback();
});

};

/*
* Main part of the script:
* - Exports the function, or
* - Executes the function if running from CLI
*/
var runLoadFixtures = module.exports = function(fixtureFile, callback) {

console.log("running Load Fixtures");


async.eachSeries(fixtureFile, addFixture, callback);

};

if (!module.parent) { // Run as CLI command exec
async.series([

// Start cipherLayer components (mongodb, redis...)
function connect(done) {
userDao.connect(done);
},

function drop(done) {
if(!process.env.DROP_DB) return done();
console.log("Dropping database");
userDao.deleteAllUsers(done);
},

function load(done) {
fixtureFile = require(__dirname + '/' + '../tests/fixtures/' + 'User.json');
runLoadFixtures(fixtureFile,done);
},

function disconnect(done) {
userDao.disconnect(done);
}

], function(err) {
if (err) {
console.error(err);
process.exit(1);
}

console.info('Fixtures loaded');
process.exit();
});

}
3 changes: 2 additions & 1 deletion src/cipherlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ function startListener(publicPort, internalPort, cbk){
"/auth/google",
"/auth/google/*",
"/user/activate*",
"/heartbeat"
"/heartbeat",
"/user/email/available"
];
publicServer.use(versionControl(versionControlOptions));

Expand Down
Loading