| 2648 | |
| 2649 | |
| 2650 | def test_config_in_subdir(node_factory, chainparams): |
| 2651 | l1 = node_factory.get_node(start=False) |
| 2652 | network = chainparams['name'] |
| 2653 | |
| 2654 | subdir = os.path.join(l1.daemon.opts.get("lightning-dir"), network) |
| 2655 | with open(os.path.join(subdir, "config"), 'w') as f: |
| 2656 | f.write('alias=test_config_in_subdir') |
| 2657 | l1.start() |
| 2658 | |
| 2659 | assert l1.rpc.listconfigs('alias')['configs']['alias'] == {'source': os.path.join(subdir, "config") + ":1", 'value_str': 'test_config_in_subdir'} |
| 2660 | |
| 2661 | l1.stop() |
| 2662 | |
| 2663 | # conf is not allowed in any config file. |
| 2664 | with open(os.path.join(l1.daemon.opts.get("lightning-dir"), "config"), 'w') as f: |
| 2665 | f.write('conf={}/conf'.format(network)) |
| 2666 | |
| 2667 | out = subprocess.run(['lightningd/lightningd', |
| 2668 | '--lightning-dir={}'.format(l1.daemon.opts.get("lightning-dir"))], |
| 2669 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=TIMEOUT) |
| 2670 | assert out.returncode == 1 |
| 2671 | assert "conf: not permitted in configuration files" in out.stderr.decode('utf-8') |
| 2672 | |
| 2673 | # network is allowed in root config file. |
| 2674 | with open(os.path.join(l1.daemon.opts.get("lightning-dir"), "config"), 'w') as f: |
| 2675 | f.write('network={}'.format(network)) |
| 2676 | |
| 2677 | l1.start() |
| 2678 | l1.stop() |
| 2679 | |
| 2680 | # but not in network config file. |
| 2681 | with open(os.path.join(subdir, "config"), 'w') as f: |
| 2682 | f.write('network={}'.format(network)) |
| 2683 | |
| 2684 | out = subprocess.run(['lightningd/lightningd', |
| 2685 | '--lightning-dir={}'.format(l1.daemon.opts.get("lightning-dir"))], |
| 2686 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 2687 | assert out.returncode == 1 |
| 2688 | assert "network={}: not permitted in network-specific configuration files".format(network) in out.stderr.decode('utf-8') |
| 2689 | |
| 2690 | # lightning-dir only allowed if we explicitly use --conf |
| 2691 | os.unlink(os.path.join(subdir, "config")) |
| 2692 | with open(os.path.join(l1.daemon.opts.get("lightning-dir"), "config"), 'w') as f: |
| 2693 | f.write('lightning-dir={}/test'.format(l1.daemon.opts.get("lightning-dir"))) |
| 2694 | |
| 2695 | out = subprocess.run(['lightningd/lightningd', |
| 2696 | '--lightning-dir={}'.format(l1.daemon.opts.get("lightning-dir"))], |
| 2697 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 2698 | assert out.returncode == 1 |
| 2699 | assert "lightning-dir={}/test: not permitted in implicit configuration files".format(l1.daemon.opts.get("lightning-dir")) in out.stderr.decode('utf-8') |
| 2700 | |
| 2701 | l1.daemon.opts['conf'] = os.path.join(l1.daemon.opts.get("lightning-dir"), "config") |
| 2702 | l1.start() |
| 2703 | |
| 2704 | |
| 2705 | def restore_valgrind(node, subdir): |