Test checkhsm with various configurations
(node_factory, test_case)
| 1506 | }, id="wrong_mnemonic_should_fail") |
| 1507 | ]) |
| 1508 | def test_hsmtool_checkhsm_variants(node_factory, test_case): |
| 1509 | """Test checkhsm with various configurations""" |
| 1510 | l1 = node_factory.get_node(start=False) |
| 1511 | hsm_path = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "hsm_secret") |
| 1512 | os.remove(hsm_path) |
| 1513 | |
| 1514 | # Create hsm_secret with known mnemonic and passphrase |
| 1515 | hsmtool = HsmTool(node_factory.directory, "generatehsm", hsm_path) |
| 1516 | master_fd, slave_fd = os.openpty() |
| 1517 | hsmtool.start(stdin=slave_fd) |
| 1518 | hsmtool.wait_for_log(r"Introduce your BIP39 word list separated by space") |
| 1519 | write_all(master_fd, f"{test_case['mnemonic']}\n".encode("utf-8")) |
| 1520 | hsmtool.wait_for_log(r"Enter your passphrase:") |
| 1521 | write_all(master_fd, f"{test_case['passphrase']}\n".encode("utf-8")) |
| 1522 | assert hsmtool.proc.wait(WAIT_TIMEOUT) == 0 |
| 1523 | |
| 1524 | # Test checkhsm with credentials |
| 1525 | hsmtool = HsmTool(node_factory.directory, "checkhsm", hsm_path) |
| 1526 | master_fd, slave_fd = os.openpty() |
| 1527 | hsmtool.start(stdin=slave_fd) |
| 1528 | |
| 1529 | # If the original had a passphrase, we need to unlock the file first |
| 1530 | if test_case['passphrase']: |
| 1531 | hsmtool.wait_for_log(r"Enter hsm_secret password:") # Decrypt file |
| 1532 | write_all(master_fd, f"{test_case['passphrase']}\n".encode("utf-8")) |
| 1533 | |
| 1534 | hsmtool.wait_for_log(r"Enter your mnemonic passphrase:") # Backup verification |
| 1535 | write_all(master_fd, f"{test_case['check_passphrase']}\n".encode("utf-8")) |
| 1536 | hsmtool.wait_for_log(r"Introduce your BIP39 word list separated by space") |
| 1537 | write_all(master_fd, f"{test_case['check_mnemonic']}\n".encode("utf-8")) |
| 1538 | assert hsmtool.proc.wait(WAIT_TIMEOUT) == test_case['expected_exit'] |
| 1539 | hsmtool.is_in_log(test_case['expected_log']) |
| 1540 | |
| 1541 | |
| 1542 | def test_hsmtool_checkhsm_legacy_encrypted_with_mnemonic_no_passphrase(node_factory): |