[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Unassign MAPADDRESS when destination is None
commit cba4c3fbeb8f39e5dd494624c3fffba57628866a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Aug 15 14:47:20 2020 -0700
Unassign MAPADDRESS when destination is None
Integration tests should undo any configuration changes they make to avoid
unintentionally impacting later tests. Initially it was unclear to me how to
unassign MAPADDRESS, but I filed the following to clarify this...
https://gitlab.torproject.org/tpo/core/tor/-/issues/40104
---
stem/control.py | 10 +++-------
test/integ/control/controller.py | 30 +++++++++++++++++-------------
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index 9efc6e04..678afa8f 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -3872,12 +3872,8 @@ class Controller(BaseController):
async def map_address(self, mapping: Mapping[str, str]) -> Dict[str, str]:
"""
- Map addresses to replacement addresses. Tor replaces subseqent connections
- to the original addresses with the replacement addresses.
-
- If the original address is a null address, i.e., one of '0.0.0.0', '::0', or
- '.' Tor picks an original address itself and returns it in the reply. If the
- original address is already mapped to a different address the mapping is
+ Replace Tor connections for the given addresses with alternate
+ destionations. If the destination is **None** then its mapping will be
removed.
:param mapping: mapping of original addresses to replacement addresses
@@ -3889,7 +3885,7 @@ class Controller(BaseController):
* :class:`stem.OperationFailed` if Tor couldn't fulfill the request
"""
- mapaddress_arg = ' '.join(['%s=%s' % (k, v) for (k, v) in list(mapping.items())])
+ mapaddress_arg = ' '.join(['%s=%s' % (k, v if v else k) for (k, v) in list(mapping.items())])
response = await self.msg('MAPADDRESS %s' % mapaddress_arg)
return stem.response._convert_to_mapaddress(response).entries
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index db59ccf2..8fc0e099 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -1210,16 +1210,14 @@ class TestController(unittest.TestCase):
# try mapping one element, ensuring results are as expected
map1 = {'1.2.1.2': 'ifconfig.me'}
- x = await controller.map_address(map1)
- self.assertEqual(x, map1)
+ self.assertEqual(map1, await controller.map_address(map1))
# try mapping two elements, ensuring results are as expected
map2 = {'1.2.3.4': 'foobar.example.com',
'1.2.3.5': 'barfuzz.example.com'}
- x = await controller.map_address(map2)
- self.assertEqual(x, map2)
+ self.assertEqual(map2, await controller.map_address(map2))
# try mapping zero elements
@@ -1229,22 +1227,22 @@ class TestController(unittest.TestCase):
# try a virtual mapping to IPv4, the default virtualaddressrange is 127.192.0.0/10
map3 = {'0.0.0.0': 'quux'}
- x = await controller.map_address(map3)
- self.assertEquals(len(x), 1)
- addr1, target = list(x.items())[0]
+ response = await controller.map_address(map3)
+ self.assertEquals(len(response), 1)
+ addr1, target = list(response.items())[0]
- self.assertTrue(addr1.startswith('127.'), '%s did not start with 127.' % addr1)
- self.assertEquals(target, 'quux')
+ self.assertTrue('%s did not start with 127.' % addr1, addr1.startswith('127.'))
+ self.assertEquals('quux', target)
# try a virtual mapping to IPv6, the default IPv6 virtualaddressrange is FE80::/10
map4 = {'::': 'quibble'}
- x = await controller.map_address(map4)
- self.assertEquals(len(x), 1)
- addr2, target = list(x.items())[0]
+ response = await controller.map_address(map4)
+ self.assertEquals(1, len(response))
+ addr2, target = list(response.items())[0]
self.assertTrue(addr2.startswith('[fe'), '%s did not start with [fe.' % addr2)
- self.assertEquals(target, 'quibble')
+ self.assertEquals('quibble', target)
async def address_mappings(addr_type):
response = await controller.get_info(['address-mappings/%s' % addr_type])
@@ -1281,6 +1279,12 @@ class TestController(unittest.TestCase):
self.assertEquals({}, await address_mappings('config'))
+ # revert these address mappings
+
+ mapped_addresses = (await address_mappings('control')).keys()
+ await controller.map_address(dict([(addr, None) for addr in mapped_addresses]))
+ self.assertEquals({}, await address_mappings('control'))
+
@test.require.controller
@test.require.online
@async_test
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits