[tor-commits] [gettor/master] Ensure replies to the help message will work
cohosh at torproject.org
cohosh at torproject.org
Thu Mar 12 17:14:14 UTC 2020
commit 0cd6443cdd8964fbfad00010d2cd0220f31e18f0
Author: Cecylia Bocovich <cohosh at torproject.org>
Date: Mon Feb 10 16:28:21 2020 -0500
Ensure replies to the help message will work
This commit makes some changes and adds some tests to ensure that
valid replies to the gettor help message will contain links.
Non-valid replies should still return the GetTor help message.
---
gettor/parse/email.py | 29 +++++++++++++++++------------
tests/test_email_service.py | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 12 deletions(-)
diff --git a/gettor/parse/email.py b/gettor/parse/email.py
index 38bc120..9409a99 100644
--- a/gettor/parse/email.py
+++ b/gettor/parse/email.py
@@ -13,6 +13,7 @@
from __future__ import absolute_import
import re
+import io
import dkim
import hashlib
@@ -117,18 +118,22 @@ class EmailParser(object):
def parse_keywords(self, text, request):
- for word in re.split(r"\s+", text.strip()):
- for locale in self.locales:
- if word.lower() == locale.lower():
- request["language"] = locale
- elif (not request["language"]) and (word.lower()[:2] ==
- locale.lower()[:2]):
- request["language"] = locale
- if word.lower() in self.platforms:
- request["command"] = "links"
- request["platform"] = word.lower()
- if (not request["command"]) and word.lower() == "help":
- request["command"] = "help"
+ buf = io.StringIO(text)
+ for line in buf:
+ if len(line.strip()) > 0 and line.strip()[0] == ">":
+ continue
+ for word in re.split(r"\s+", line.strip()):
+ for locale in self.locales:
+ if word.lower() == locale.lower():
+ request["language"] = locale
+ elif (not request["language"]) and (word.lower()[:2] ==
+ locale.lower()[:2]):
+ request["language"] = locale
+ if word.lower() in self.platforms:
+ request["command"] = "links"
+ request["platform"] = word.lower()
+ if (not request["command"]) and word.lower() == "help":
+ request["command"] = "help"
return request
def build_request(self, msg_str, norm_addr):
diff --git a/tests/test_email_service.py b/tests/test_email_service.py
index 45278bc..995ba55 100644
--- a/tests/test_email_service.py
+++ b/tests/test_email_service.py
@@ -210,6 +210,47 @@ class EmailServiceTests(unittest.TestCase):
assert "en-US" in ep.locales
del ep
+ def test_help_reply(self):
+ #Replying to GetTor Help with a valid links request should get you links
+ ep = conftests.EmailParser(self.settings, "gettor at torproject.org")
+ ep.locales = ["en-US", "es-ES", "es-AR", "pt-BR", "fa"]
+ request = ep.parse("From: \"silvia [hiro]\" <hiro at torproject.org>\n"
+ "Subject: Re: [GetTor] Help Email\r\n Reply-To: hiro at torproject.org \nTo:"
+ "gettor at torproject.org\n osx en\n")
+ self.assertEqual(request["command"], "links")
+ self.assertEqual(request["language"], "en-US")
+ self.assertEqual(request["platform"], "osx")
+
+ request = ep.parse("From: \"silvia [hiro]\" <hiro at torproject.org>\n"
+ "Subject: Re: [GetTor] Help Email\r\n Reply-To: hiro at torproject.org \nTo:"
+ "gettor at torproject.org\nlinux fa\n\n"
+ "On 2020-02-10 11:54 a.m., gettor at torproject.org wrote:\n"
+ "> This is how you can request a tor browser bundle link.\n"
+ ">\n"
+ "> Send an email to: gettor at torproject.org\n"
+ ">\n"
+ "> In the body of the email only write: <operating system> <language>.\n"
+ ">\n"
+ "> We only support windows, osx and linux as operating systems.\n"
+ ">\n")
+ self.assertEqual(request["command"], "links")
+ self.assertEqual(request["language"], "fa")
+ self.assertEqual(request["platform"], "linux")
+
+ request = ep.parse("From: \"silvia [hiro]\" <hiro at torproject.org>\n"
+ "Subject: Re: [GetTor] Help Email\r\n Reply-To: hiro at torproject.org \nTo:"
+ "gettor at torproject.org\n"
+ "On 2020-02-10 11:54 a.m., gettor at torproject.org wrote:\n"
+ "> This is how you can request a tor browser bundle link.\n"
+ ">\n"
+ "> Send an email to: gettor at torproject.org\n"
+ ">\n"
+ "> In the body of the email only write: <operating system> <language>.\n"
+ ">\n"
+ "> We only support windows, osx and linux as operating systems.\n"
+ ">\n")
+ self.assertEqual(request["command"], "help")
+
if __name__ == "__main__":
unittest.main()
More information about the tor-commits
mailing list