Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ trim_trailing_whitespace = false
indent_style = tab
indent_size = 4

# NPM rewrites package.json after every install with this settings
[package.json]
indent_style = space
indent_size = 2

[*.feature]
indent_style = tab
indent_size = 2
13 changes: 10 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ machine:
services:
- mongodb
- redis
general:
artifacts:
- $CIRCLE_TEST_REPORTS
test:
pre:
- cp config_sample.json config.json
- mkdir -p $CIRCLE_TEST_REPORTS/mocha
- mkdir -p $CIRCLE_TEST_REPORTS/cucumber
- mkdir -p $CIRCLE_TEST_REPORTS/coverage
override:
- npm run test
- npm run test-ci
- npm run coverage
- npm run coveralls
- npm run codeclimate
- if [[ -z $CIRCLE_PR_REPONAME ]] ; then npm run coveralls ; fi
- if [[ -z $CIRCLE_PR_REPONAME ]] ; then npm run codeclimate ; fi
- cp coverage $CIRCLE_ARTIFACTS/coverage -r
deployment:
npm:
branch: master
Expand Down
21 changes: 0 additions & 21 deletions gulpfile.js

This file was deleted.

8 changes: 6 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ var cipherLayer = require('./src/cipherlayer');
var fs = require('fs');
var config = require(process.cwd() + '/config.json');

var PUBLIC_PORT = process.env.PORT || config.public_port;
var INTERNAL_PORT = process.env.INTERNAL_PORT || config.internal_port;

console.log('starting cipherlayer proxy');
cipherLayer.start(config.public_port, config.internal_port, function (err) {

cipherLayer.start(PUBLIC_PORT, INTERNAL_PORT, function (err) {
if (err) {
console.error('error on launch: ' + err);
} else {
console.log('listening on port ' + config.public_port);
console.log('listening on port ' + PUBLIC_PORT);
}

fs.watchFile('config.json', function () {
Expand Down
168 changes: 79 additions & 89 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,91 +1,81 @@
{
"name": "cipherlayer",
"version": "0.0.1",
"description": "cipherlayer",
"main": "src/cipherlayer.js",
"scripts": {
"test": "npm run-script jshint && npm run-script mocha && npm run-script features",
"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",
"codeclimate": "codeclimate-test-reporter < ./coverage/lcov.info"
},
"dependencies": {
"async": "^0.9.0",
"aws-sdk": "^2.1.0",
"bunyan": "^1.4.0",
"ciphertoken": "^0.9.5",
"countries-info": "^1.0.6",
"escape-regexp": "0.0.1",
"http-proxy": "^1.8.1",
"jsonschema": "^1.0.0",
"lodash": "^4.3.0",
"mongodb": "^1.4.22",
"passport": "^0.2.1",
"passport-forcedotcom": "^0.1.1",
"passport-google-oauth2": "^0.1.6",
"passport-linkedin-oauth2": "^1.2.1",
"randexp": "^0.4.2",
"redis": "^0.12.1",
"request": "^2.47.0",
"restify": "^2.8.5",
"version-control": "^1.2.4"
},
"devDependencies": {
"assert": "^1.1.2",
"blanket": "^1.1.7",
"chai": "^3.5.0",
"codeclimate-test-reporter": "^0.3.1",
"coveralls": "^2.11.4",
"cucumber": "^0.5.2",
"istanbul": "^0.3.22",
"istanbul-combine": "^0.3.0",
"istanbul-coveralls": "^1.0.3",
"jshint": "^2.8.0",
"lcov-result-merger": "^1.0.2",
"mocha": "^2.0.1",
"mocha-lcov-reporter": "0.0.2",
"mockery": "^1.4.0",
"nock": "^0.51.0",
"pre-commit": "^1.0.7",
"sinon": "^1.12.2",
"which": "^1.0.8"
},
"repository": {
"type": "git",
"url": "https://github.com/thegameofcode/cipherlayer.git"
},
"author": "luismesas",
"license": "ISC",
"bugs": {
"url": "https://github.com/thegameofcode/cipherlayer/issues"
},
"homepage": "https://github.com/thegameofcode/cipherlayer",
"pre-commit": [
"jshint"
],
"jshintConfig": {
"esnext": true,
"node": true,
"unused": true,
"mocha": true
},
"config": {
"blanket": {
"pattern": [
"src",
"tests"
],
"data-cover-never": [
"node_modules",
"tests"
]
}
}
"name": "cipherlayer",
"version": "0.0.1",
"description": "cipherlayer",
"main": "src/cipherlayer.js",
"scripts": {
"test": "npm run lint && npm run test-unit && npm run test-acceptance",
"test-unit": "mocha tests-unit --recursive",
"test-acceptance": "cucumber.js tests-acceptance -f pretty --tags ~@ignore",
"test-acceptance-only": "cucumber.js tests-acceptance -f pretty --tags @only",
"lint": "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",
"codeclimate": "codeclimate-test-reporter < ./coverage/lcov.info",
"test-ci": "npm run lint && npm run test-unit-ci && npm run test-acceptance-ci",
"test-unit-ci": "mocha tests-unit --recursive --reporter mocha-junit-reporter --reporter-options mochaFile=$CIRCLE_TEST_REPORTS/mocha/junit.xml",
"test-acceptance-ci": "cucumber.js tests-acceptance --tags ~@ignore --format json --out $CIRCLE_TEST_REPORTS/cucumber/tests.cucumber"
},
"dependencies": {
"async": "^1.5.2",
"aws-sdk": "^2.1.0",
"bunyan": "^1.4.0",
"ciphertoken": "^0.9.5",
"countries-info": "^1.0.6",
"escape-regexp": "0.0.1",
"http-proxy": "^1.8.1",
"jsonschema": "^1.0.0",
"lodash": "^4.3.0",
"mongodb": "^1.4.40",
"passport": "^0.3.2",
"passport-forcedotcom": "^0.1.1",
"passport-google-oauth2": "^0.1.6",
"passport-linkedin-oauth2": "^1.2.1",
"randexp": "^0.4.2",
"redis": "^2.4.2",
"request": "^2.47.0",
"restify": "^4.0.4",
"version-control": "^1.2.4"
},
"devDependencies": {
"assert": "^1.1.2",
"chai": "^3.5.0",
"codeclimate-test-reporter": "^0.3.1",
"coveralls": "^2.11.4",
"cucumber": "^0.9.5",
"istanbul": "^0.4.2",
"istanbul-combine": "^0.3.0",
"istanbul-coveralls": "^1.0.3",
"jshint": "^2.8.0",
"mocha": "^2.0.1",
"mocha-junit-reporter": "^1.9.1",
"mocha-lcov-reporter": "^1.2.0",
"mockery": "^1.4.0",
"nock": "^7.2.2",
"pre-commit": "^1.0.7",
"sinon": "^1.12.2",
"which": "^1.0.8"
},
"repository": {
"type": "git",
"url": "https://github.com/thegameofcode/cipherlayer.git"
},
"author": "luismesas",
"license": "ISC",
"bugs": {
"url": "https://github.com/thegameofcode/cipherlayer/issues"
},
"homepage": "https://github.com/thegameofcode/cipherlayer",
"pre-commit": [
"lint"
],
"jshintConfig": {
"esnext": true,
"node": true,
"unused": true,
"mocha": true
}
}
2 changes: 1 addition & 1 deletion tests-acceptance/post_profile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: client application POST a profile to create

@service
Scenario Outline: Client post data for a new profile
Given a protected service replies to a <METHOD> request with <PROTECTED_REQUEST_PAYLOAD> to <PATH> with status <STATUS> and a body <PROTECTED_PAYLOAD>
Given a protected service replies to a <METHOD> request with <PROTECTED_REQUEST_PAYLOAD> to <PATH> with status <STATUS> and a responseBody <PROTECTED_PAYLOAD>
And config has no param emailverification
When the client makes a pass through <METHOD> with the following <PUBLIC_REQUEST_PAYLOAD> in the body
Then the response status code is 403
Expand Down
2 changes: 1 addition & 1 deletion tests-acceptance/proxy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: reverse proxy protects an applicacion behind cipherlayer
@service
Scenario Outline: A protected service needs an accessToken auth to be called
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 a protected service replies to a <METHOD> request with <REQUEST_PAYLOAD> to <PATH> with status <STATUS> and a responseBody <RESPONSE_PAYLOAD>
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>
Expand Down
7 changes: 3 additions & 4 deletions tests-acceptance/restrictedArea.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ Feature: client application logs in with admin role
And the response body contains json attribute "refreshToken"
And the response body contains json attribute "expiresIn"


@service
Scenario Outline: A protected admin service needs an accessToken with admin role attribute auth to be called
Given a user with role admin 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 a protected service replies to a <METHOD> request with <REQUEST_PAYLOAD> to <PATH> with status <STATUS> and a responseBody <RESPONSE_PAYLOAD>
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>
Expand All @@ -25,7 +24,7 @@ Feature: client application logs in with admin role
@service
Scenario Outline: A protected admin service needs an accessToken with admin role attribute auth to be called
Given a user with role admin 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 ""
And a protected service replies to a <METHOD> request with <REQUEST_PAYLOAD> to <PATH> with status <STATUS> and a responseBody ""
When the application makes a <METHOD> with <REQUEST_PAYLOAD> to a protected <PATH>
Then the response status code is <STATUS>
Examples:
Expand All @@ -36,7 +35,7 @@ Feature: client application logs in with admin role
@service
Scenario Outline: Client with no admin role request restricted endpoints
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 a protected service replies to a <METHOD> request with <REQUEST_PAYLOAD> to <PATH> with status <STATUS> and a responseBody <RESPONSE_PAYLOAD>
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var nock = require('nock');
var config = require('../../config.json');

module.exports = function(){
this.Given(/^a protected service replies to a GET request with (.*) to (.*) with status (.*) and a body (.*)$/, function (REQUEST_PAYLOAD, PATH, STATUS, RESPONSE_PAYLOAD, callback){
this.Given(/^a protected service replies to a GET request with (.*) to (.*) with status (.*) and a responseBody (.*)$/, function (REQUEST_PAYLOAD, PATH, STATUS, RESPONSE_PAYLOAD, callback){
nock('http://localhost:'+config.private_port, {
reqheaders: {
'Content-Type': 'application/json; charset=utf-8',
Expand All @@ -27,7 +27,7 @@ module.exports = function(){
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){
this.Given(/^a protected service replies to a POST request with (.*) to (.*) with status (.*) and a responseBody (.*)$/, 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));
Expand All @@ -36,7 +36,7 @@ module.exports = function(){
});


this.Given(/^a protected service replies to a PUT request with (.*) to (.*) with status (.*) and a body (.*)$/, function (REQUEST_PAYLOAD, PATH, STATUS, RESPONSE_PAYLOAD, callback){
this.Given(/^a protected service replies to a PUT request with (.*) to (.*) with status (.*) and a responseBody (.*)$/, function (REQUEST_PAYLOAD, PATH, STATUS, RESPONSE_PAYLOAD, callback){
nock('http://localhost:'+config.private_port)
.put(PATH, JSON.parse(REQUEST_PAYLOAD))
.reply(Number(STATUS), JSON.parse(RESPONSE_PAYLOAD));
Expand Down
6 changes: 2 additions & 4 deletions tests-acceptance/support/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ var world = require('./world');
var config = require('../../config.json');

module.exports = function () {
this.Before(function (done) {
this.Before(function () {
world.resetUser();
world.config = _.clone(config);
done();
});

this.After(function (done) {
this.After(function () {
config = world.config;
done();
});
};
4 changes: 2 additions & 2 deletions tests-acceptance/support/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var world = require('./world');
var config = require('../../config.json');

module.exports = function () {
this.Before("@service", function (done) {
this.Before("@service", function (scenario, done) {
cipherlayer.start(config.public_port, config.internal_port, function (err) {
assert.equal(err, null);
var options = {
Expand All @@ -30,7 +30,7 @@ module.exports = function () {
});
});

this.After("@service", function (done) {
this.After("@service", function (scenario, done) {
cipherlayer.stop(done);
});
};
7 changes: 4 additions & 3 deletions tests-acceptance/support/serviceValidCors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ var world = require('./world');
var config = require('../../config.json');

module.exports = function () {
this.Before("@serviceValidCors", function (done) {
this.accessControlAllow = config.accessControlAllow = {
this.Before("@serviceValidCors", function (scenario, done) {
config.accessControlAllow = {
headers: ['custom-header-1', 'custom-header-2'],
origins: ['http://valid.origin.com']
};
this.accessControlAllow = config.accessControlAllow;

cipherlayer.start(config.public_port, config.internal_port, function (err) {
assert.equal(err, null);
Expand All @@ -35,7 +36,7 @@ module.exports = function () {
});
});

this.After("@serviceValidCors", function (done) {
this.After("@serviceValidCors", function (scenario, done) {
cipherlayer.stop(done);
});
};
Loading