From 20ce69b3370f5fa5fab95c6472eece0b0734bfbf Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Tue, 26 Jul 2022 02:25:38 +0300 Subject: [PATCH] Add enableAddress API command and a check for sending from disabled address --- src/api.py | 10 ++++++++++ src/tests/test_api.py | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/api.py b/src/api.py index 0d802d61..8e4ddda4 100644 --- a/src/api.py +++ b/src/api.py @@ -883,6 +883,16 @@ class BMRPCDispatcher(object): shared.reloadMyAddressHashes() 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') def HandleGetAllInboxMessages(self): """ diff --git a/src/tests/test_api.py b/src/tests/test_api.py index a1082383..fc0f4db2 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -413,6 +413,11 @@ class TestAPI(TestAPIProto): self.assertEqual(self.api.deleteAndVacuum(), 'done') self.assertIsNone(json.loads( 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: self.assertEqual(self.api.deleteAddress(addr), 'success')