Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

key-auth+cli e2e test connect #345 #377

Merged
merged 4 commits into from
Aug 30, 2017
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ example/keys/*.pem
**/.DS_Store
coverage
.nyc_output
coverage.lcov
1 change: 0 additions & 1 deletion lib/policies/basic-auth/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function authenticateBasic (req, clientId, clientSecret, done) {
if (!consumer) {
return done(null, false);
}

return authService.authorizeCredential(clientId, credentialType, endpointScopes || requestedScopes)
.then(authorized => {
if (!authorized) {
Expand Down
1 change: 0 additions & 1 deletion lib/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ s.authenticateCredential = function (id, password, type) {
return this.validateConsumer(credential.consumerId, {checkUsername: true});
});
}

return this.validateConsumer(id, { checkUsername: true })
.then((consumer) => {
if (!consumer) {
Expand Down
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
},
"scripts": {
"start": "node lib/index.js",
"getting-started": "node lib/index.js emulate",
"start-dev": "LOG_LEVEL=debug node lib/index.js",
"lint": "eslint --fix .",
"clean": "rimraf dist/",
"pretest": "eslint .",
"test": "npm run mocha-istanbul",
"test-all": "cross-env EG_CONFIG_DIR=test/config EG_DISABLE_CONFIG_WATCH=true mocha --recursive test --timeout 20000",
"dev-test": "cross-env EG_CONFIG_DIR=test/config mocha EG_DISABLE_CONFIG_WATCH=true --recursive test",
"test-all": "cross-env EG_CONFIG_DIR=test/config EG_DISABLE_CONFIG_WATCH=true mocha --recursive test --timeout 60000",
"test:unit": "cross-env EG_CONFIG_DIR=test/config EG_DISABLE_CONFIG_WATCH=true mocha --recursive \"./test/{,!(e2e)/**/}*.test.js\" --timeout 5000",
"test:e2e": "mocha --recursive test/e2e --timeout 60000",
"mocha-istanbul": "nyc --reporter=lcov npm run test-all && nyc report --report=lcov > coverage.lcov && codecov"
},
"bin": {
Expand Down
57 changes: 57 additions & 0 deletions test/common/cli.helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const path = require('path');
const { exec } = require('child_process');
const os = require('os');
const fs = require('fs');
const uuid = require('node-uuid');

const modulePath = path.resolve(__dirname, '..', '..', 'bin', 'index.js');

module.exports.bootstrapFolder = function (options) {
let tempDir = path.join(os.tmpdir(), uuid.v4());
fs.mkdirSync(tempDir);
let execOptions = {
env: Object.assign({}, process.env)
};
let cmd = modulePath + ' gateway create -t getting-started -n test -d ' + tempDir;
return new Promise((resolve, reject) => {
exec(cmd, execOptions, function (error, stdout, stderr) {
if (error !== null) {
reject(error);
}
resolve({
basePath: tempDir,
configDirectoryPath: path.join(tempDir, 'config'),
gatewayConfigPath: path.join(tempDir, 'config', 'gateway.config.yml'),
systemConfigPath: path.join(tempDir, 'config', 'system.config.yml')
});
});
});
};

module.exports.runCLICommand = function ({adminPort, adminUrl, configDirectoryPath, cliArgs}) {
// TODO: it should not depend on configFolder, API only, now the last dependency is models
let cliExecOptions = Object.assign({}, {
env: process.env
});
cliExecOptions.env.EG_CONFIG_DIR = configDirectoryPath;
cliExecOptions.env.EG_ADMIN_URL = adminUrl || `http://localhost:${adminPort}`;
const command = [modulePath].concat(cliArgs).join(' ');
return new Promise((resolve, reject) => {
exec(command, cliExecOptions, (err, stdout, stderr) => {
if (err) {
reject(err);
return;
}
try {
const obj = JSON.parse(stdout);
resolve(obj);
} catch (err) {
if (err instanceof SyntaxError) {
resolve(stdout);
} else {
reject(err);
}
}
});
});
};
Loading