X-Git-Url: https://git.squeep.com/?p=squeep-authentication-module;a=blobdiff_plain;f=test%2Flib%2Fstdio-credential.js;fp=test%2Flib%2Fstdio-credential.js;h=54865cb2e5c0e9d3eded6542e4e3354b425b1fa5;hp=0000000000000000000000000000000000000000;hb=53ef948ea83106e82d55e60d6695a15e94bf725e;hpb=842a3da269de1ab82e9a2a12aae8ed5677f064d8 diff --git a/test/lib/stdio-credential.js b/test/lib/stdio-credential.js new file mode 100644 index 0000000..54865cb --- /dev/null +++ b/test/lib/stdio-credential.js @@ -0,0 +1,40 @@ +'use strict'; + +const assert = require('node:assert'); +const sinon = require('sinon'); +const stdioCredential = require('../../lib/stdio-credential'); +const readline = require('node:readline'); + +describe('stdioCredential', function () { + let answerCb, prompt; + + beforeEach(function () { + sinon.stub(readline, 'createInterface').callsFake(({ input, output, terminal }) => { + return { + close: () => undefined, + prompt: () => { + output.write(prompt); + }, + question: (_message, cb) => { + output.write(prompt); + answerCb = cb; + }, + setPrompt: (p) => { + prompt = p; + }, + }; + }); + }); + + afterEach(function () { + sinon.restore(); + }); + + it('covers', async function () { + const input = 'password'; + const resultP = stdioCredential('prompt>'); + answerCb(input); + const result = await resultP; + assert.strictEqual(result, input); + }); +}); // stdioCredential \ No newline at end of file