Add enableAddress API command and a check for sending from disabled address

This commit is contained in:
Lee Miller 2022-07-26 02:25:38 +03:00
parent b25ed553bc
commit 20ce69b337
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
2 changed files with 15 additions and 0 deletions

View File

@ -883,6 +883,16 @@ class BMRPCDispatcher(object):
shared.reloadMyAddressHashes() shared.reloadMyAddressHashes()
return "success" return "success"
@command('enableAddress')
def HandleEnableAddress(self, address, enable=True):
"""Enable or disable the address depending on the *enable* value"""
self._verifyAddress(address)
address = addBMIfNotPresent(address)
config.set(address, 'enabled', str(enable))
self.config.save()
shared.reloadMyAddressHashes()
return "success"
@command('getAllInboxMessages') @command('getAllInboxMessages')
def HandleGetAllInboxMessages(self): def HandleGetAllInboxMessages(self):
""" """

View File

@ -413,6 +413,11 @@ class TestAPI(TestAPIProto):
self.assertEqual(self.api.deleteAndVacuum(), 'done') self.assertEqual(self.api.deleteAndVacuum(), 'done')
self.assertIsNone(json.loads( self.assertIsNone(json.loads(
self.api.getSentMessageById(sent_msgid))) self.api.getSentMessageById(sent_msgid)))
# Try sending from disabled address
self.assertEqual(self.api.enableAddress(addr, False), 'success')
result = self.api.sendBroadcast(
addr, base64.encodestring('test_subject'), msg)
self.assertRegexpMatches(result, r'^API Error 0014:')
finally: finally:
self.assertEqual(self.api.deleteAddress(addr), 'success') self.assertEqual(self.api.deleteAddress(addr), 'success')