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

CLI arguments made order invariant #81

Merged
merged 10 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions cli/actions/encrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ module.exports = async (args, options, logger) => {
}
}

const encrypt = async ({ data, serviceAccount, namespace, kamusApiUrl, allowInsecureUrl, certFingerprint }, token = null) => {
const encrypt = async ({ data, serviceAccount, namespace, kamusUrl, allowInsecureUrl, certFingerprint }, token = null) => {
_logger.log('Encryption started...');
_logger.log('service account:', serviceAccount);
_logger.log('namespace:', namespace);

if (!allowInsecureUrl && url.parse(kamusApiUrl).protocol !== 'https:') {
if (!allowInsecureUrl && url.parse(kamusUrl).protocol !== 'https:') {
_logger.error("Insecure Kamus URL is not allowed");
process.exit(1);
}
try {
const response = await performEncryptRequestAsync(data, serviceAccount, namespace, kamusApiUrl, certFingerprint, token);
const response = await performEncryptRequestAsync(data, serviceAccount, namespace, kamusUrl, certFingerprint, token);
if (response && response.statusCode >= 300) {
_logger.error(`Encrypt request failed due to unexpected error. Status code: ${response.statusCode}`);
process.exit(1);
Expand All @@ -48,7 +48,7 @@ const encrypt = async ({ data, serviceAccount, namespace, kamusApiUrl, allowInse
}

const acquireToken = async ({ authTenant, authApplication, authResource }) => {
const context = new AuthenticationContext(activeDirectoryEndpoint + authTenant);
const context = new AuthenticationContext(`${activeDirectoryEndpoint}${authTenant}`);
bluebird.promisifyAll(context);
refreshToken = await acquireTokenWithDeviceCode(context, authApplication, authResource);
const refreshTokenResponse =
Expand Down
2 changes: 1 addition & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

var pjson = require('./package.json');
const pjson = require('./package.json');
const prog = require('caporal');
const encrypt = require('./actions/encrypt');
const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
Expand Down
4 changes: 2 additions & 2 deletions cli/is-docker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var fs = require('fs');
const fs = require('fs');

var isDocker;
let isDocker;

function hasDockerEnv() {
try {
Expand Down
6 changes: 3 additions & 3 deletions cli/test/encrypt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const logger =
log: console.log
};

const kamusApiUrl = 'https://kamus.com';
const kamusUrl = 'https://kamus.com';
const data = 'super-secret';
const serviceAccount = 'dummy';
const namespace = 'team-a';
Expand All @@ -22,13 +22,13 @@ let kamusApiScope;
describe('Encrypt', () => {
beforeEach(() => {
sinon.stub(process, 'exit');
kamusApiScope = nock(kamusApiUrl)
kamusApiScope = nock(kamusUrl)
.post('/api/v1/encrypt', { data, ['service-account']: serviceAccount, namespace})
.reply(200, '123ABC');
});

it('Should return encrypted data', async () => {
await encrypt({data, serviceAccount, namespace, kamusApiUrl}, logger);
await encrypt(null, {data, serviceAccount, namespace, kamusUrl}, logger);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why null is added here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caporal calls the action with 3 parameters: args, options, logger.
I removed the first parameter by mistake because we don't actually use it. But the order matters.

expect(kamusApiScope.isDone()).to.be.true;
expect(process.exit.called).to.be.true;
expect(process.exit.calledWith(0)).to.be.true;
Expand Down