commit 3b8c9efa8546827fa7cc6f2d93bff6a5ccff6f12 Author: Damian Johnson atagar@torproject.org Date: Wed Jul 5 09:57:31 2017 -0700
Resilience to 'Tor' prefix in 'GETINFO version'
Spec mistakenly said 'GETINFO version' prefixed its response with 'Tor '. It didn't, so we changed this to a may clause...
https://trac.torproject.org/projects/tor/ticket/20014 https://gitweb.torproject.org/torspec.git/commit/?id=c5ff1b1
If tor ever did provide a 'Tor' prefix we'd choke, so making ourselves resilient to that. --- docs/change_log.rst | 1 + stem/control.py | 3 ++- test/unit/control/controller.py | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst index af697a5..7159288 100644 --- a/docs/change_log.rst +++ b/docs/change_log.rst @@ -55,6 +55,7 @@ The following are only available within Stem's `git repository * Tor change caused :func:`~stem.control.Controller.list_ephemeral_hidden_services` to provide empty strings if unset (:trac:`21329`) * Better error message when :func:`~stem.control.Controller.set_conf` fails due to an option being immutable * Failed to parse torrcs without a port on ipv6 exit policy entries + * Resilient to 'Tor' prefix in 'GETINFO version' result (:spec:`c5ff1b1`)
* **Descriptors**
diff --git a/stem/control.py b/stem/control.py index 6475af4..a88f6e0 100644 --- a/stem/control.py +++ b/stem/control.py @@ -1242,7 +1242,8 @@ class Controller(BaseController): version = self._get_cache('version')
if not version: - version = stem.version.Version(self.get_info('version')) + version_str = self.get_info('version') + version = stem.version.Version(version_str[4:] if version_str.startswith('Tor ') else version_str) self._set_cache({'version': version})
return version diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py index 124c115..17ca2bf 100644 --- a/test/unit/control/controller.py +++ b/test/unit/control/controller.py @@ -73,6 +73,11 @@ class TestControl(unittest.TestCase): # Return a version without caching, so it will be the new version. self.assertEqual(version_2_2_object, self.controller.get_version())
+ # Spec says the getinfo response may optionally be prefixed by 'Tor '. In + # practice it doesn't but we should accept that. + get_info_mock.return_value = 'Tor 0.2.1.32' + self.assertEqual(version_2_1_object, self.controller.get_version()) + # Raise an exception in the get_info() call. get_info_mock.side_effect = InvalidArguments
tor-commits@lists.torproject.org