(node_factory, old_hsmsecret)
| 4781 | @unittest.skipIf(VALGRIND, "It does not play well with prompt and key derivation.") |
| 4782 | @pytest.mark.parametrize("old_hsmsecret", [True, False]) |
| 4783 | def test_exposesecret(node_factory, old_hsmsecret): |
| 4784 | l1, l2 = node_factory.get_nodes(2, opts=[{'exposesecret-passphrase': "test_exposesecret", 'old_hsmsecret': old_hsmsecret}, {}]) |
| 4785 | |
| 4786 | # listconfigs will conceal the value for us, even if we ask directly. |
| 4787 | l1.rpc.listconfigs()['configs']['exposesecret-passphrase']['value_str'] == '...' |
| 4788 | l1.rpc.listconfigs('exposesecret-passphrase')['configs']['exposesecret-passphrase']['value_str'] == '...' |
| 4789 | |
| 4790 | # l2 won't expose the secret! |
| 4791 | with pytest.raises(RpcError, match="exposesecrets-passphrase is not set"): |
| 4792 | l2.rpc.exposesecret(passphrase='test_exposesecret') |
| 4793 | |
| 4794 | # check command does the same. |
| 4795 | with pytest.raises(RpcError, match="exposesecrets-passphrase is not set"): |
| 4796 | l2.rpc.check('exposesecret', passphrase='test_exposesecret') |
| 4797 | |
| 4798 | # l1, bad pass phrase |
| 4799 | with pytest.raises(RpcError, match="passphrase does not match exposesecrets-passphrase"): |
| 4800 | l1.rpc.exposesecret(passphrase='test_exposesecret2') |
| 4801 | |
| 4802 | # Bad identifier length |
| 4803 | for invalid in ('', 'x', 'xxxxx'): |
| 4804 | with pytest.raises(RpcError, match="must be 4 characters"): |
| 4805 | l1.rpc.exposesecret(passphrase='test_exposesecret', identifier=invalid) |
| 4806 | |
| 4807 | # Bad case |
| 4808 | for invalid in ('CLNX', 'Clnx', 'clnX'): |
| 4809 | with pytest.raises(RpcError, match="must be lower-case"): |
| 4810 | l1.rpc.exposesecret(passphrase='test_exposesecret', identifier=invalid) |
| 4811 | |
| 4812 | # Bad identifier chars |
| 4813 | for invalid in ('cln1', 'clno', 'clnb', 'clni'): |
| 4814 | with pytest.raises(RpcError, match="must be valid bech32 string"): |
| 4815 | l1.rpc.exposesecret(passphrase='test_exposesecret', identifier=invalid) |
| 4816 | |
| 4817 | if old_hsmsecret: |
| 4818 | # As given by lightning-hsmtool: |
| 4819 | # $ ./tools/lightning-hsmtool getcodexsecret /tmp/ltests-10uyxcnw/test_exposesecret_1/lightning-1/regtest/hsm_secret junr |
| 4820 | # cl10junrsd35kw6r5de5kueedxyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj00m675kxffh |
| 4821 | # $ ./tools/lightning-hsmtool getcodexsecret /tmp/ltests-10uyxcnw/test_exposesecret_1/lightning-1/regtest/hsm_secret junx |
| 4822 | # cl10junxsd35kw6r5de5kueedxyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6mdtn5lql6p8m |
| 4823 | # $ ./tools/lightning-hsmtool getcodexsecret /tmp/ltests-10uyxcnw/test_exposesecret_1/lightning-1/regtest/hsm_secret cln2 |
| 4824 | # cl10cln2sd35kw6r5de5kueedxyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq2v3y60yxxn4mq |
| 4825 | assert l1.rpc.exposesecret(passphrase='test_exposesecret') == {'codex32': 'cl10junrsd35kw6r5de5kueedxyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj00m675kxffh', |
| 4826 | 'identifier': 'junr'} |
| 4827 | |
| 4828 | assert l1.rpc.exposesecret(passphrase='test_exposesecret', identifier='cln2') == {'codex32': 'cl10cln2sd35kw6r5de5kueedxyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq2v3y60yxxn4mq', |
| 4829 | 'identifier': 'cln2'} |
| 4830 | else: |
| 4831 | # As given by lightning-hsmtool: |
| 4832 | # $ ./tools/lightning-hsmtool getcodexsecret /tmp/ltests-2xbjux9b/test_exposesecret_1/lightning-1/regtest/hsm_secret stra |
| 4833 | # cl10strasmms5axpgnml3svm0urkrvv2cuvxmz0xyd3dlfhaljvcy5wuu2gts07pad39rz85w6 |
| 4834 | # $ ./tools/lightning-hsmtool getcodexsecret /tmp/ltests-2xbjux9b/test_exposesecret_1/lightning-1/regtest/hsm_secret junx |
| 4835 | # cl10junxsmms5axpgnml3svm0urkrvv2cuvxmz0xyd3dlfhaljvcy5wuu2gtsfcrlankxlxmaa |
| 4836 | # $ ./tools/lightning-hsmtool getcodexsecret /tmp/ltests-2xbjux9b/test_exposesecret_1/lightning-1/regtest/hsm_secret cln2 |
| 4837 | # cl10cln2smms5axpgnml3svm0urkrvv2cuvxmz0xyd3dlfhaljvcy5wuu2gtse0ls5gdqx00px |
| 4838 | assert l1.rpc.exposesecret(passphrase='test_exposesecret') == {'codex32': 'cl10strasmms5axpgnml3svm0urkrvv2cuvxmz0xyd3dlfhaljvcy5wuu2gts07pad39rz85w6', |
| 4839 | 'identifier': 'stra', |
| 4840 | 'mnemonic': 'hockey enroll sure trip track rescue original plate abandon abandon abandon account'} |
nothing calls this directly
no test coverage detected