Skip to content

Commit

Permalink
Merge branch 'master' of github.com:apigee-internal/microgateway
Browse files Browse the repository at this point in the history
  • Loading branch information
theganyo committed Jun 19, 2019
2 parents d89327b + f5f07ee commit a80dc71
Show file tree
Hide file tree
Showing 34 changed files with 1,275 additions and 298 deletions.
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MOCHA_PASSWORD=$MOCHA_PASSWORD_CFG
MOCHA_KEY=$MOCHA_KEY_CFG
MOCHA_SECRET=$MOCHA_SECRET_CFG
MOCHA_USER=$MOCHA_USER_CFG
MOCHA_ORG=$MOCHA_ORG_CFG
MOCHA_ENV=$MOCHA_ENV_CFG
MOCHA_TOKEN_SECRET=$MOCHA_TOKEN_SECRET_CFG
MOCHA_TOKEN_ID=$MOCHA_TOKEN_ID_CFG
MOCHA_SAML_TOKEN=$MOCHA_SAML_TOKEN_CFG
MOCHA_ENDPOINT=$MOCHA_ENDPOINT_CFG
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,11 @@ default.yaml.bak
test-token.txt
env.sh
foo

.nyc_output
#.env
evars.sh
.vscode
tools
logging-report.txt
logstuf.txt
quick.sh
.nyc_output
3 changes: 2 additions & 1 deletion cli/lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ module.exports = function () {
return new Configure();
}

Configure.prototype.configure = function configure(options, cb) {
Configure.prototype.configure = function configure(options, cb) {
if (!fs.existsSync(configLocations.getDefaultPath(options.configDir))) {
console.error("Missing %s, Please run 'edgemicro init'",configLocations.getDefaultPath())
return cb("Please call edgemicro init first")
}

defaultConfig = edgeconfig.load({ source: configLocations.getDefaultPath(options.configDir) });
addEnvVars(defaultConfig);
deployAuth = deployAuthLib(defaultConfig.edge_config, null)
Expand Down
11 changes: 9 additions & 2 deletions cli/lib/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function() {
return new Gateway();
};

Gateway.prototype.start = (options) => {
Gateway.prototype.start = (options,cb) => {
const self = this;
try {
fs.accessSync(ipcPath, fs.F_OK);
Expand All @@ -41,7 +41,8 @@ Gateway.prototype.start = (options) => {

const source = configLocations.getSourcePath(options.org, options.env, options.configDir);
const cache = configLocations.getCachePath(options.org, options.env, options.configDir);
const configurl = options.configUrl;
const configurl = options.configUrl;

const keys = {
key: options.key,
secret: options.secret
Expand Down Expand Up @@ -214,6 +215,12 @@ Gateway.prototype.start = (options) => {
});
}, pollInterval * 1000);
}

if ( cb && (typeof cb == "function") ) {
console.log("Calling cb")
cb();
}

});
};

Expand Down
9 changes: 6 additions & 3 deletions cli/lib/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Token.prototype.verifyToken = function(options, cb) {
const secret = options.secret;
const keys = { key: key, secret: secret };

const token = fs.readFileSync(path.resolve(options.file), 'utf8').trim();
const token = fs.readFileSync(path.resolve(options.file), 'utf8').trim();

const config = edgeconfig.load({ source: targetPath, keys: keys });

Expand All @@ -51,11 +51,12 @@ Token.prototype.verifyToken = function(options, cb) {
config.edge_config['managementUri'] === 'https://api.e2e.apigee.net';

getPublicKey(options.org, options.env, authUri, this.isPublicCloud, function(err, certificate) {
//
if (err) {
cb(err);
return printError(err);
}

//
const opts = {
algorithms: ['RS256'],
ignoreExpiration: false
Expand Down Expand Up @@ -111,14 +112,16 @@ Token.prototype.getToken = function(options, cb) {
}

function getPublicKey(organization, environment, authUri, isPublicCloud, cb) {

//
const uri = isPublicCloud ? util.format(authUri + '/publicKey', organization, environment) : authUri + '/publicKey';
//
request({
uri: uri
}, function(err, res) {
if (err) { return cb(err); }
cb(null, res.body);
});
//
}

function printError(err) {
Expand Down
1 change: 1 addition & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ headers:
oauth:
allowNoAuthorization: false
allowInvalidAuthorization: false
gracePeriod: 10
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"cpr": "^1.0.0",
"debug": "^3.1.0",
"diff": "^3.4.0",
"dotenv": "^8.0.0",
"forever-monitor": "^1.7.1",
"fs-extra": "^0.20.1",
"js-yaml": "^3.5.4",
Expand Down Expand Up @@ -45,7 +46,9 @@
"minimist": "^1.1.1",
"mocha": "^5.2.0",
"nyc": "^13.3.0",
"request-promise": "^4.2.4",
"restify": "^4.0.4",
"test-until": "^1.1.1",
"run-sequence": "^1.1.0"
},
"eslintConfig": {
Expand All @@ -57,8 +60,7 @@
"start": "node app.js",
"stop": "node stop.js",
"package": "node cli/package.js",
"test": "mocha --timeout 17000 tests/*.unit.test.js",
"test:integration": "nyc mocha tests/*.*.integ.test.js --timeout 90000"
"test": "nyc mocha --timeout 17000 tests/*.unit.test.js && nyc mocha tests/*.*.integ.test.js --timeout 90000"
},
"directories": {
"doc": "docs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const os = require('os');
const path = require('path');
const assert = require('assert');
const fs = require('fs');
const denv = require('dotenv');
denv.config();
const envVars = require('./env')

const edgemicroCustomDir = 'edgemicroCustomDir';
const edgemicroCustomFilepath = path.join(edgemicroCustomDir, loc.defaultFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const os = require('os');
const path = require('path');
const fs = require('fs');
const jsyaml = require('js-yaml');
const denv = require('dotenv');
denv.config();
const envVars = require('./env.js');
const { user: username, password, env, org, tokenId, tokenSecret } = envVars;
const loc = require('../config/locations.js')
Expand All @@ -16,6 +18,7 @@ const mgwHome = path.join(loc.defaultDir, '..');
const init = require('../cli/lib/init.js');
const configure = require('../cli/lib/configure.js')();
const uuid = require('uuid');

let configDir;
let configLocation;
let customOrgEnvFilepath;
Expand Down Expand Up @@ -61,6 +64,7 @@ describe('configure module', () => {
);
});

/*
it('configures customDir and saves default config file to customDir location', (done) => {
configDir = uuid.v1();
Expand All @@ -86,12 +90,15 @@ describe('configure module', () => {
});
it('saves env/org config file to customDir location', (done) =>{
configDir = uuid.v1();
customOrgEnvFilepath = path.join(mgwHome, configDir, defaultOrgEnvFilename);
let customSourceConfigJSON = jsyaml.safeLoad(fs.readFileSync(customOrgEnvFilepath));
assert(customSourceConfigJSON.edge_config);
done();
});
*/

/*
it('configures mgw for org and env without error', done => {
configure.configure(
{
Expand All @@ -113,6 +120,7 @@ describe('configure module', () => {
assert(defaultSourceConfigJSON.edge_config);
done();
});
*/


});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

const assert = require('assert');
const cert = require('../cli/lib/cert')();
const denv = require('dotenv');
denv.config();
const envVars = require('./env.js');
const { user: username, password, env, org, tokenId, tokenSecret } = envVars;
const configure = require('../cli/lib/configure.js')();
Expand All @@ -25,6 +27,7 @@ describe('cert module', () => {
});

it('checks public cert', done => {
this.timeout(10000)
cert.checkCert(
{
username,
Expand Down
File renamed without changes.
File renamed without changes.
55 changes: 55 additions & 0 deletions test-quarantine/91.gateway.integ.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// gateway.test.js

'use strict';

const gateway = require('../cli/lib/gateway.js')();
const assert = require('assert');
const path = require('path');
const denv = require('dotenv');
denv.config();
const envVars = require('./env.js');
const {user:username, password, env, org, tokenId:id, tokenSecret, key, secret } = envVars;
const { spawn, spawnSync, execSync } = require("child_process");

describe('gateway module', () => {

it('starts mgw', (done) => {
let gatewayStart = spawn('node', ['tests/childProcs/gatewayStart.test.js']);

let outData = [];
gatewayStart.stdout.on('data', data=>{
outData.push(data);
let outDataStr = Buffer.concat(outData).toString();
if(outDataStr.includes('PROCESS PID :')) {
outData = [];
done();
}
});

gatewayStart.stderr.on('data', errData =>{
console.log('errData',Buffer.from(errData).toString());
});
});

it('provides mgw status when running',(done) => {
let gatewayStatus = spawnSync('node', ['tests/childProcs/gatewayStatus.test.js']);
let outString = Buffer.from(gatewayStatus.stdout).toString();
assert.equal(outString.includes('edgemicro is running with'), true)
done();
});

it('reloads mgw when running', (done) => {
let gatewayReload = spawnSync('node', ['tests/childProcs/gatewayReload.test.js']);
let outString = Buffer.from(gatewayReload.stdout).toString();
assert.equal(outString.includes('Reload Completed Successfully'), true);
done();
});

it('stop mgw when running', done=> {
let gatewayStop = spawnSync('node', ['tests/childProcs/gatewayStop.test.js']);
let outString = Buffer.from(gatewayStop.stdout).toString();
assert.equal(outString.includes('Stop Completed Succesfully'), true);
done();
});

});
File renamed without changes.
35 changes: 35 additions & 0 deletions test-quarantine/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

edge_config:
bootstrap: https://apigee.net/edgemicro/bootstrap/organization/org/environment/env...
jwt_public_key: http://apigee.net/edgemicro/publicKey...
managementUri: https://api.enterprise.apigee.com
vaultName: microgateway
authUri: https://%s-%s.apigee.net/edgemicro-auth
baseUri: https://edgemicroservices.apigee.net/edgemicro/%s/organization/%s/environment/%s
bootstrapMessage: Please copy the following property to the edge micro agent config
keySecretMessage: The following credentials are required to start edge micro

edgemicro:
port: 8000
max_connections: 1000
config_change_poll_interval: 600
logging:
level: error
dir: /var/tmp
stats_log_interval: 60
rotate_interval: 24
plugins:
sequence:
- oauth

headers:
x-forwarded-for: true
x-forwarded-host: true
x-request-id: true
x-response-time: true
via: true

oauth:
allowNoAuthorization: false
allowInvalidAuthorization: false
gracePeriod: 600
35 changes: 35 additions & 0 deletions test-quarantine/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const assert = require('assert');

const password = process.env.MOCHA_PASSWORD;
const key = process.env.MOCHA_KEY;
const secret = process.env.MOCHA_SECRET;
const user = process.env.MOCHA_USER;
const org = process.env.MOCHA_ORG;
const env = process.env.MOCHA_ENV;
const tokenSecret = process.env.MOCHA_TOKEN_SECRET;
const tokenId = process.env.MOCHA_TOKEN_ID;
const otoken = process.env.MOCHA_SAML_TOKEN || '';
const endpoint = process.env.MOCHA_ENDPOINT || false;


assert(password, 'Must set environment variable MOCHA_PASSWORD');
assert(user, 'Must set environment variable MOCHA_USER');
assert(org, 'Must set environment variable MOCHA_ORG');
assert(env, 'Must set environment variable MOCHA_ENV');
assert(key, 'Must set environment variable MOCHA_KEY');
assert(secret, 'Must set environment variable MOCHA_SECRET');
assert(tokenId, 'Must set environment variable MOCHA_TOKEN_ID');
assert(tokenSecret, 'Must set environment variable MOCHA_TOKEN_SECRET');

module.exports = {
password:password,
key:key,
secret:secret,
user:user,
org:org,
env:env,
tokenSecret:tokenSecret,
tokenId:tokenId,
otoken:otoken,
endpoint : endpoint
};
1 change: 1 addition & 0 deletions test-quarantine/jwtString.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eyJraWQiOiIxIiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYifQ.eyJhY2Nlc3NfdG9rZW4iOiJGSk9rZW5OV0sxWkw4RThOc2U1eFRSSU9pdDVkIiwiYXVkIjoibWljcm9nYXRld2F5IiwibmJmIjoxNTU5OTQzMzIzLCJhcGlfcHJvZHVjdF9saXN0IjpbImJha2VyeXRyaWFsIl0sImFwcGxpY2F0aW9uX25hbWUiOiJCYWtlcnlBcHAiLCJkZXZlbG9wZXJfZW1haWwiOiJoZWxsb3dvcmxkQGFwaWdlZS5jb20iLCJpc3MiOiJodHRwczovL2xlZGR5ci1ldmFsLXRlc3QuYXBpZ2VlLm5ldC9lZGdlbWljcm8tYXV0aC90b2tlbiIsImV4cCI6MTU1OTk0MzQzMSwiaWF0IjoxNTU5OTQzMzIzLCJqdGkiOiIyNDc3MTVjNC0yOTQ4LTQxNjUtODk5OS04N2JhYmU4NjM0YTIiLCJjbGllbnRfaWQiOiJkMHd6NXBWQm9VWnd6cVJVRXMzQTlFc3VBbVUyb2YyaCJ9.ppkYhO_hIWL2rgHoLvLIfPcd10NOk8Ie5MrhlhjsyEeWV_tHS8eGV7V8zHDixCsMJ9FH3DeoIYmaJxfRUQRlrXw40u2famu0sdTy4Is9Wi7vaYAp7xXBr9gv6JPMgojcIhnQEzWGiQcsnIgBl2qQ5D8BTvvT0CvWv3XHvKB6qJMGTCrykjhRNt1-z_qTMEOUgvlccpnJ_FQlg1Fyst3Rhoegoe32cws8s9sFI0-5li9WAO6UMP2VJLx1PGE51oBJX1OuBDTG8UH8Igjt5q5-v9F2U6Md7caLbRG7Ynz4wAJPTRCKXYeLr9PQsmzm5jdUA4HY7HSVrjfBNUe5l3c2Fg
Loading

0 comments on commit a80dc71

Please sign in to comment.