Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

🌱 Add prompt source for passphrases

Closes #318
  • Loading branch information...
willclarktech committed Nov 14, 2017
1 parent 1fc3138 commit a0ecad93f4683112fbe4864260f47c493c7a5abf
Showing with 55 additions and 4 deletions.
  1. +1 −1 src/utils/input/utils.js
  2. +12 −3 src/utils/options.js
  3. +42 −0 test/specs/utils/input/index.js
@@ -170,7 +170,7 @@ export const getPassphraseFromSource = async (source, { displayName }) => {

export const getPassphrase = async (vorpal, passphraseSource, options) => {
const optionsWithDefaults = Object.assign({ displayName: 'your secret passphrase' }, options);
return passphraseSource
return passphraseSource && passphraseSource !== 'prompt'
? getPassphraseFromSource(passphraseSource, optionsWithDefaults)
: getPassphraseFromPrompt(vorpal, optionsWithDefaults);
};
@@ -11,27 +11,36 @@ const messageDescription = `Specifies a source for providing a message to the co

const noJsonDescription = 'Sets output to text (default). You can change the default behaviour in your config.json file.';

const passphraseDescription = `Specifies a source for your secret passphrase. Lisky will prompt you for input if this option is not set. Source must be one of \`env\`, \`file\` or \`stdin\`. Except for \`stdin\`, a corresponding identifier must also be provided.
const passphraseDescription = `Specifies a source for your secret passphrase. Lisky will prompt you for input if this option is not set.
Source must be one of \`prompt\`, \`pass\`, \`env\`, \`file\` or \`stdin\`. For \`pass\`, \`env\` and \`file\` a corresponding identifier must also be provided.
Examples:
- --passphrase prompt (default behaviour)
- --passphrase 'pass:my secret passphrase' (should only be used where security is not important)
- --passphrase env:SECRET_PASSPHRASE
- --passphrase file:/path/to/my/passphrase.txt (takes the first line only)
- --passphrase stdin (takes one line only)
`;

const secondPassphraseDescription = `Specifies a source for your second secret passphrase. Lisky will prompt you for input if this option is not set. Source must be one of \`env\`, \`file\` or \`stdin\`. Except for \`stdin\`, a corresponding identifier must also be provided.
const secondPassphraseDescription = `Specifies a source for your second secret passphrase. For certain commands a second passphrase is necessary, in which case Lisky will prompt you for it if this option is not set. Otherwise, Lisky will assume you want to use one passphrase only.
Source must be one of \`prompt\`, \`pass\`, \`env\`, \`file\` or \`stdin\`. For \`pass\`, \`env\` and \`file\` a corresponding identifier must also be provided.
Examples:
- --second-passphrase prompt (to force a prompt even when a second passphrase is not always necessary)
- --second-passphrase 'pass:my second secret passphrase' (should only be used where security is not important)
- --second-passphrase env:SECOND_SECRET_PASSPHRASE
- --second-passphrase file:/path/to/my/secondPassphrase.txt (takes the first line only)
- --second-passphrase stdin (takes one line only)
`;

const passwordDescription = `Specifies a source for your secret password. Lisky will prompt you for input if this option is not set. Source must be one of \`env\`, \`file\` or \`stdin\`. Except for \`stdin\`, a corresponding identifier must also be provided.
const passwordDescription = `Specifies a source for your secret password. Lisky will prompt you for input if this option is not set.
Source must be one of \`prompt\`, \`pass\`, \`env\`, \`file\` or \`stdin\`. For \`pass\`, \`env\` and \`file\` a corresponding identifier must also be provided.
Examples:
- --password prompt (default behaviour)
- --password pass:password123 (should only be used where security is not important)
- --password env:PASSWORD
- --password file:/path/to/my/password.txt (takes the first line only)
@@ -89,6 +89,27 @@ describe('input utils', () => {
});
});
});
describe('Given the options object has a "passphrase" field with key "source" set to string "prompt"', () => {
beforeEach(given.theOptionsObjectHasAFieldWithKeySetToString);
describe('Given the passphrase is available from the source', () => {
beforeEach(given.thePassphraseIsAvailableFromTheSource);
describe('When getInputsFromSources is called with the Vorpal instance and the options', () => {
beforeEach(when.getInputsFromSourcesIsCalledWithTheVorpalInstanceAndTheOptions);
it('Then it should not ask for the passphrase from stdIn', then.itShouldNotAskForThePassphraseFromStdIn);
it('Then it should not ask for the second passphrase from stdIn', then.itShouldNotAskForTheSecondPassphraseFromStdIn);
it('Then it should not ask for the password from stdIn', then.itShouldNotAskForThePasswordFromStdIn);
it('Then it should not ask for the data from stdIn', then.itShouldNotAskForTheDataFromStdIn);
it('Then it should get the passphrase with a single prompt', then.itShouldGetThePassphraseWithASinglePrompt);
it('Then it should not get the second passphrase', then.itShouldNotGetTheSecondPassphrase);
it('Then it should not get the password', then.itShouldNotGetThePassword);
it('Then it should not get the data', then.itShouldNotGetTheData);
it('Then it should resolve with the passphrase', then.itShouldResolveWithThePassphrase);
it('Then it should resolve without the second passphrase', then.itShouldResolveWithoutTheSecondPassphrase);
it('Then it should resolve without the password', then.itShouldResolveWithoutThePassword);
it('Then it should resolve without the data', then.itShouldResolveWithoutTheData);
});
});
});
describe('Given the options object has a "passphrase" field with key "repeatPrompt" set to boolean true', () => {
beforeEach(given.theOptionsObjectHasAFieldWithKeySetToBoolean);
describe('Given the passphrase is available from the source', () => {
@@ -175,6 +196,27 @@ describe('input utils', () => {
});
});
});
describe('Given the options object has a "secondPassphrase" field with key "source" set to string "prompt"', () => {
beforeEach(given.theOptionsObjectHasAFieldWithKeySetToString);
describe('Given the second passphrase is available from the source', () => {
beforeEach(given.theSecondPassphraseIsAvailableFromTheSource);
describe('When getInputsFromSources is called with the Vorpal instance and the options', () => {
beforeEach(when.getInputsFromSourcesIsCalledWithTheVorpalInstanceAndTheOptions);
it('Then it should not ask for the passphrase from stdIn', then.itShouldNotAskForThePassphraseFromStdIn);
it('Then it should not ask for the second passphrase from stdIn', then.itShouldNotAskForTheSecondPassphraseFromStdIn);
it('Then it should not ask for the password from stdIn', then.itShouldNotAskForThePasswordFromStdIn);
it('Then it should not ask for the data from stdIn', then.itShouldNotAskForTheDataFromStdIn);
it('Then it should not get the passphrase', then.itShouldNotGetThePassphrase);
it('Then it should get the second passphrase with a single prompt', then.itShouldGetTheSecondPassphraseWithASinglePrompt);
it('Then it should not get the password', then.itShouldNotGetThePassword);
it('Then it should not get the data', then.itShouldNotGetTheData);
it('Then it should resolve without the passphrase', then.itShouldResolveWithoutThePassphrase);
it('Then it should resolve with the second passphrase', then.itShouldResolveWithTheSecondPassphrase);
it('Then it should resolve without the password', then.itShouldResolveWithoutThePassword);
it('Then it should resolve without the data', then.itShouldResolveWithoutTheData);
});
});
});
describe('Given the options object has a "secondPassphrase" field with key "repeatPrompt" set to boolean true', () => {
beforeEach(given.theOptionsObjectHasAFieldWithKeySetToBoolean);
describe('Given the second passphrase is available from the source', () => {

0 comments on commit a0ecad9

Please sign in to comment.
You can’t perform that action at this time.