Specify some new API commands for managing black/white list

This commit is contained in:
Lee Miller 2024-09-02 03:54:42 +03:00
parent f497d7ab51
commit 41f3774ac4
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63

View File

@ -301,6 +301,54 @@ class TestAPI(TestAPIProto):
self.assertEqual( self.assertEqual(
json.loads(self.api.listSubscriptions())['subscriptions'], []) json.loads(self.api.listSubscriptions())['subscriptions'], [])
def test_blackwhitelist(self):
"""Test API commands for managing the black/white list"""
# Initially it's black
self.assertEqual(self.api.getBlackWhitelistKind(), 'black')
# Initially they are empty
self.assertEqual(
json.loads(self.api.listBlacklistEntries()).get('addresses'), [])
self.assertEqual(
json.loads(self.api.listWhitelistEntries()).get('addresses'), [])
# For the Blacklist:
# Add known address
self.api.addBlacklistEntry(
sample_deterministic_addr4,
base64.encodestring('tiger_4')
)
# Check list entry
entry = json.loads(self.api.listBlacklistEntries()).get('addresses')[0]
self.assertEqual(entry['address'], sample_deterministic_addr4)
self.assertEqual(base64.decodestring(entry['label']), 'tiger_4')
# Remove known address
self.api.deleteBlacklistEntry(sample_deterministic_addr4)
self.assertEqual(
json.loads(self.api.listBlacklistEntries()).get('addresses'), [])
# Only two kinds - black and white
six.assertRegex(
self, self.api.setBlackWhitelistKind('yellow'),
r'^API Error 0028:')
# Change kind
self.api.setBlackWhitelistKind('white')
self.assertEqual(self.api.getBlackWhitelistKind(), 'white')
# For the Whitelist:
# Add known address
self.api.addWhitelistEntry(
sample_deterministic_addr4,
base64.encodestring('tiger_4')
)
# Check list entry
entry = json.loads(self.api.listWhitelistEntries()).get('addresses')[0]
self.assertEqual(entry['address'], sample_deterministic_addr4)
self.assertEqual(base64.decodestring(entry['label']), 'tiger_4')
# Remove known address
self.api.deleteWhitelistEntry(sample_deterministic_addr4)
self.assertEqual(
json.loads(self.api.listWhitelistEntries()).get('addresses'), [])
def test_send(self): def test_send(self):
"""Test message sending""" """Test message sending"""
addr = self._add_random_address('random_2') addr = self._add_random_address('random_2')