| 2618 | |
| 2619 | |
| 2620 | def test_config_in_subdir(node_factory, chainparams): |
| 2621 | l1 = node_factory.get_node(start=False) |
| 2622 | network = chainparams['name'] |
| 2623 | |
| 2624 | subdir = os.path.join(l1.daemon.opts.get("lightning-dir"), network) |
| 2625 | with open(os.path.join(subdir, "config"), 'w') as f: |
| 2626 | f.write('alias=test_config_in_subdir') |
| 2627 | l1.start() |
| 2628 | |
| 2629 | assert l1.rpc.listconfigs('alias')['configs']['alias'] == {'source': os.path.join(subdir, "config") + ":1", 'value_str': 'test_config_in_subdir'} |
| 2630 | |
| 2631 | l1.stop() |
| 2632 | |
| 2633 | # conf is not allowed in any config file. |
| 2634 | with open(os.path.join(l1.daemon.opts.get("lightning-dir"), "config"), 'w') as f: |
| 2635 | f.write('conf={}/conf'.format(network)) |
| 2636 | |
| 2637 | out = subprocess.run(['lightningd/lightningd', |
| 2638 | '--lightning-dir={}'.format(l1.daemon.opts.get("lightning-dir"))], |
| 2639 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=TIMEOUT) |
| 2640 | assert out.returncode == 1 |
| 2641 | assert "conf: not permitted in configuration files" in out.stderr.decode('utf-8') |
| 2642 | |
| 2643 | # network is allowed in root config file. |
| 2644 | with open(os.path.join(l1.daemon.opts.get("lightning-dir"), "config"), 'w') as f: |
| 2645 | f.write('network={}'.format(network)) |
| 2646 | |
| 2647 | l1.start() |
| 2648 | l1.stop() |
| 2649 | |
| 2650 | # but not in network config file. |
| 2651 | with open(os.path.join(subdir, "config"), 'w') as f: |
| 2652 | f.write('network={}'.format(network)) |
| 2653 | |
| 2654 | out = subprocess.run(['lightningd/lightningd', |
| 2655 | '--lightning-dir={}'.format(l1.daemon.opts.get("lightning-dir"))], |
| 2656 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 2657 | assert out.returncode == 1 |
| 2658 | assert "network={}: not permitted in network-specific configuration files".format(network) in out.stderr.decode('utf-8') |
| 2659 | |
| 2660 | # lightning-dir only allowed if we explicitly use --conf |
| 2661 | os.unlink(os.path.join(subdir, "config")) |
| 2662 | with open(os.path.join(l1.daemon.opts.get("lightning-dir"), "config"), 'w') as f: |
| 2663 | f.write('lightning-dir={}/test'.format(l1.daemon.opts.get("lightning-dir"))) |
| 2664 | |
| 2665 | out = subprocess.run(['lightningd/lightningd', |
| 2666 | '--lightning-dir={}'.format(l1.daemon.opts.get("lightning-dir"))], |
| 2667 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 2668 | assert out.returncode == 1 |
| 2669 | assert "lightning-dir={}/test: not permitted in implicit configuration files".format(l1.daemon.opts.get("lightning-dir")) in out.stderr.decode('utf-8') |
| 2670 | |
| 2671 | l1.daemon.opts['conf'] = os.path.join(l1.daemon.opts.get("lightning-dir"), "config") |
| 2672 | l1.start() |
| 2673 | |
| 2674 | |
| 2675 | def restore_valgrind(node, subdir): |