File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1515Test 'set'.
1616"""
1717
18+ # isort: STDLIB
19+ from unittest .mock import patch
20+
1821# isort: LOCAL
1922from stratis_cli import StratisCliErrorCodes
2023from 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 )
You can’t perform that action at this time.
0 commit comments