Skip to content
Snippets Groups Projects
Commit fcca7faf authored by juga's avatar juga
Browse files

stem: parse torrc options that are only a key

User torrc options in `extra_lines` that are only one key and not
a key value pair were not being parsed correctly.
Add a test.

Fixes bug #28715. Bugfix v0.1.1
parent 405b56a4
No related branches found
No related tags found
No related merge requests found
......@@ -134,15 +134,13 @@ def parse_user_torrc_config(torrc, torrc_text):
# Ignore blank lines
if len(line) < 1:
continue
# The way stem handles configuring Tor with a dictionary is the first
# word is a key and the remaining words are the value.
# Some torrc options are only a key, some are a key value pair.
kv = line.split(None, 1)
if len(kv) < 2:
fail_hard('All torrc lines must have 2 or more words. "%s" has '
'fewer', line)
key, value = kv
log.debug('Adding "%s %s" to torrc with which we are launching Tor',
key, value)
if len(kv) > 1:
key, value = kv
else:
key = kv[0]
value = None
# It's really easy to add to the torrc if the key doesn't exist
if key not in torrc:
torrc_dict.update({key: value})
......@@ -160,6 +158,8 @@ def parse_user_torrc_config(torrc, torrc_text):
assert isinstance(existing_val, list)
existing_val.append(value)
torrc_dict.update({key: existing_val})
log.debug('Adding "%s %s" to torrc with which we are launching Tor',
key, value)
return torrc_dict
......
......@@ -24,3 +24,11 @@ def test_parse_user_torrc_config_existing_keyvalue_options_fail(caplog):
# the existing value and the new value
assert torrc_dict_new != torrc_dict
assert torrc_dict_new == {'SocksPort': ['auto', '9050']}
def test_parse_user_torrc_config_new_key_option_success():
config_torrc_extra_lines = """
LongLivedPorts
"""
torrc_dict = parse_user_torrc_config({}, config_torrc_extra_lines)
assert torrc_dict == {'LongLivedPorts': None}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment