Skip to content

Commit 89a9aee

Browse files
authored
Merge pull request #994 from mulkieran/cpalv-verify_passphrase
Cpalv verify passphrase
2 parents 4e376d1 + 75dca33 commit 89a9aee

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/stratis_cli/_actions/_top.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
StratisCliKeyfileNotFoundError,
2828
StratisCliNameConflictError,
2929
StratisCliNoChangeError,
30+
StratisCliPassphraseMismatchError,
3031
StratisCliResourceNotFoundError,
3132
)
3233
from .._stratisd_constants import ReportKey, StratisdErrors
@@ -72,6 +73,10 @@ def _add_update_key(proxy, key_desc, capture_key, *, keyfile_path):
7273

7374
if capture_key:
7475
password = getpass(prompt="Enter key data followed by the return key: ")
76+
verify = getpass(prompt="Verify key data entered: ")
77+
78+
if password != verify:
79+
raise StratisCliPassphraseMismatchError()
7580

7681
(read, write) = os.pipe()
7782
os.write(write, password.encode("utf-8"))

src/stratis_cli/_errors.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,13 @@ def __str__(self):
500500
self.minimum_version,
501501
self.maximum_version,
502502
)
503+
504+
505+
class StratisCliPassphraseMismatchError(StratisCliUserError):
506+
"""
507+
Raised if the user specified passphrase did not match
508+
the verified passphrase.
509+
"""
510+
511+
def __str__(self):
512+
return "Passphrases do not match"

tests/whitebox/integration/key/test_set.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
StratisCliEngineError,
2626
StratisCliKeyfileNotFoundError,
2727
StratisCliNameConflictError,
28+
StratisCliPassphraseMismatchError,
2829
)
2930

3031
from .._keyutils import RandomKeyTmpFile
@@ -81,3 +82,11 @@ def test_set_key_capture_key(self):
8182
command_line = self._MENU + [self._KEYNAME, "--capture-key"]
8283
with patch.object(_top, "getpass", return_value="totally_secret"):
8384
TEST_RUNNER(command_line)
85+
86+
def test_set_key_capture_key_fail_verify(self):
87+
"""
88+
Test capture key fails if passphrase do not match
89+
"""
90+
command_line = self._MENU + [self._KEYNAME, "--capture-key"]
91+
with patch.object(_top, "getpass", side_effect=["totally_secret", "different"]):
92+
self.check_error(StratisCliPassphraseMismatchError, command_line, _ERROR)

0 commit comments

Comments
 (0)