Skip to content

Commit

Permalink
test(cli): add promptSecret() empty mask option test (denoland#6273)
Browse files Browse the repository at this point in the history
  • Loading branch information
timreichen authored Dec 17, 2024
1 parent 66ebe6c commit ca71428
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cli/prompt_secret_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,55 @@ Deno.test("promptSecret() handles mask option", () => {
restore();
});

Deno.test("promptSecret() handles empty mask option", () => {
stub(Deno.stdin, "setRaw");
stub(Deno.stdin, "isTerminal", () => true);

const expectedOutput = [
"Please provide the password: ",
"\n",
];

const actualOutput: string[] = [];

stub(
Deno.stdout,
"writeSync",
(data: Uint8Array) => {
const output = decoder.decode(data);
actualOutput.push(output);
return data.length;
},
);

let readIndex = 0;

const inputs = [
"d",
"e",
"n",
"o",
"\r",
];

stub(
Deno.stdin,
"readSync",
(data: Uint8Array) => {
const input = inputs[readIndex++];
const bytes = encoder.encode(input);
data.set(bytes);
return bytes.length;
},
);

const password = promptSecret("Please provide the password:", { mask: "" });

assertEquals(password, "deno");
assertEquals(expectedOutput, actualOutput);
restore();
});

Deno.test("promptSecret() returns null if Deno.stdin.isTerminal() is false", () => {
stub(Deno.stdin, "setRaw");
stub(Deno.stdin, "isTerminal", () => false);
Expand Down

0 comments on commit ca71428

Please sign in to comment.