MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_setconfig_access

Function test_setconfig_access

tests/test_misc.py:4647–4750  ·  view source on GitHub ↗

Test that we correctly fail (not crash) if config file/dir not writable

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

4645
4646
4647def test_setconfig_access(node_factory, bitcoind):
4648 """Test that we correctly fail (not crash) if config file/dir not writable"""
4649
4650 # Disable bookkeeper, with its separate db which gets upset under CI.
4651 options = {'disable-plugin': 'bookkeeper'}
4652
4653 # sqlite3 gets upset if the directory is non-writable when it tries to commit.
4654 if os.getenv('TEST_DB_PROVIDER', 'sqlite3') == 'sqlite3':
4655 options['wallet'] = 'sqlite3://' + os.path.join(node_factory.directory, 'l1.sqlite3')
4656
4657 l1 = node_factory.get_node(options=options)
4658
4659 netconfigfile = os.path.join(l1.daemon.opts.get("lightning-dir"), TEST_NETWORK, 'config')
4660
4661 # It's OK if the config file doesn't exist.
4662 l1.rpc.check("setconfig", config="min-capacity-sat", val=1000000)
4663
4664 # But not if we can't create it.
4665 os.chmod(os.path.dirname(netconfigfile), 0o550)
4666 with pytest.raises(RpcError, match=f'Cannot write to config file {netconfigfile}'):
4667 l1.rpc.check("setconfig", config="min-capacity-sat", val=1000000)
4668
4669 with pytest.raises(RpcError, match=f'Cannot write to config file {netconfigfile}'):
4670 l1.rpc.setconfig(config="min-capacity-sat", val=1000000)
4671
4672 # Empty config file (we need to be able to write dir)
4673 os.chmod(os.path.dirname(netconfigfile), 0o750)
4674 with open(netconfigfile, 'w') as file:
4675 pass
4676 l1.restart()
4677
4678 # check will fail
4679 os.chmod(os.path.dirname(netconfigfile), 0o550)
4680 with pytest.raises(RpcError, match=f'Cannot write to config file {netconfigfile}'):
4681 l1.rpc.check("setconfig", config="min-capacity-sat", val=1000000)
4682
4683 # real write will definitely fail
4684 with pytest.raises(RpcError, match=f'Cannot write to config file {netconfigfile}'):
4685 l1.rpc.setconfig(config="min-capacity-sat", val=1000000)
4686
4687 # Transient? Don't care that we can't change it.
4688 ret = l1.rpc.setconfig(config='min-capacity-sat', val=400001, transient=True)
4689 assert ret == {'config':
4690 {'config': 'min-capacity-sat',
4691 'source': 'setconfig transient',
4692 'value_int': 400001,
4693 'dynamic': True}}
4694
4695 # db also needs to write directory!
4696 os.chmod(os.path.dirname(netconfigfile), 0o750)
4697
4698 # Now put a setting in the main config file
4699 l1.stop()
4700 mainconfigfile = os.path.join(l1.daemon.opts.get("lightning-dir"), 'config')
4701 with open(mainconfigfile, 'w') as file:
4702 file.write("min-capacity-sat=100")
4703 l1.start()
4704

Callers

nothing calls this directly

Calls 8

joinMethod · 0.80
restartMethod · 0.80
get_nodeMethod · 0.45
getMethod · 0.45
checkMethod · 0.45
stopMethod · 0.45
writeMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected