Skip to content

Commit 44b9f70

Browse files
committedJul 16, 2019
feat(otplease): Expose getOneTimePassword() helper
1 parent cf56622 commit 44b9f70

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed
 

‎core/otplease/__tests__/otplease.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ describe("@lerna/otplease", () => {
214214

215215
expect.hasAssertions();
216216
});
217+
218+
describe("getOneTimePassword()", () => {
219+
it("defaults message argument", async () => {
220+
await otplease.getOneTimePassword();
221+
222+
expect(prompt.input).toHaveBeenCalledWith(
223+
"This operation requires a one-time password:",
224+
expect.any(Object)
225+
);
226+
});
227+
228+
it("accepts custom message", async () => {
229+
await otplease.getOneTimePassword("foo bar");
230+
231+
expect(prompt.input).toHaveBeenCalledWith("foo bar", expect.any(Object));
232+
});
233+
});
217234
});
218235

219236
function makeTestCallback(otp, result) {

‎core/otplease/otplease.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const semaphore = {
3636
};
3737

3838
module.exports = otplease;
39+
module.exports.getOneTimePassword = getOneTimePassword;
3940

4041
function otplease(fn, _opts, otpCache) {
4142
// NOTE: do not use 'otpCache' as a figgy-pudding provider directly as the
@@ -91,9 +92,9 @@ function attempt(fn, opts, otpCache) {
9192
});
9293
}
9394

94-
function getOneTimePassword() {
95+
function getOneTimePassword(message = "This operation requires a one-time password:") {
9596
// Logic taken from npm internals: https://git.io/fNoMe
96-
return prompt.input("This operation requires a one-time password:", {
97+
return prompt.input(message, {
9798
filter: otp => otp.replace(/\s+/g, ""),
9899
validate: otp =>
99100
(otp && /^[\d ]+$|^[A-Fa-f0-9]{64,64}$/.test(otp)) ||

0 commit comments

Comments
 (0)
Please sign in to comment.