Skip to content

Commit a1f9cd4

Browse files
authored
Merge pull request #1271 from mulkieran/catch-KeyboardInterrupt-during-password-entry
Catch BaseException during password input
2 parents bf262b6 + bb94c81 commit a1f9cd4

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/stratis_cli/_actions/_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ def get_pass(prompt: str) -> str:
215215
password = None
216216
try:
217217
password = sys.stdin.readline()
218-
except Exception as err: # pragma: no cover
219-
if old_attrs is not None:
218+
except BaseException as err:
219+
if old_attrs is not None: # pragma: no cover
220220
termios.tcsetattr(sys.stdin, termios.TCSAFLUSH, old_attrs)
221221
raise err
222222

tests/integration/key/test_set.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
Test 'set'.
1616
"""
1717

18+
# isort: STDLIB
19+
from unittest.mock import patch
20+
1821
# isort: LOCAL
1922
from stratis_cli import StratisCliErrorCodes
2023
from stratis_cli._errors import (
@@ -127,3 +130,15 @@ def test_set_key_capture_key_empty_error(self):
127130
_ERROR,
128131
stdin="\n\n",
129132
)
133+
134+
def test_key_set_capture_key_keyboard_interrupt(self):
135+
"""
136+
Test coverage when a KeyboardInterrupt is sent while setting a
137+
passphrase. It's not possible to test that terminal is set back
138+
to correct value very easily in this infrastructure; but probably
139+
just exercising the code is enough.
140+
"""
141+
command_line = self._MENU + [self._KEYNAME, "--capture-key"]
142+
with patch("sys.stdin.readline", side_effect=KeyboardInterrupt):
143+
with self.assertRaises(KeyboardInterrupt):
144+
RUNNER(command_line)

0 commit comments

Comments
 (0)