Commit 0ffadaaa authored by Hiro's avatar Hiro 🏄
Browse files

Add test for email limit

parent 7b1dbc34
......@@ -198,6 +198,23 @@ class EmailParser(object):
return request
def check_num_request(self, request_id, request_service, limit):
now_str = datetime.now().strftime("%Y%m%d%H%M%S")
dbname = self.settings.get("dbname")
conn = SQLite3(dbname)
hid = hashlib.sha256(request['id'].encode('utf-8'))
# check limits first
num_requests = yield conn.get_num_requests(
id=hid.hexdigest(), service=request_service
)
if num_requests[0][0] < email_requests_limit:
return 1
else:
return 0
@defer.inlineCallbacks
def parse_callback(self, request):
"""
......@@ -212,30 +229,13 @@ class EmailParser(object):
execution details.
"""
email_requests_limit = self.settings.get("email_requests_limit")
log.msg(
"Found request for {}.".format(request['command']),
system="email parser"
)
if request["command"]:
now_str = datetime.now().strftime("%Y%m%d%H%M%S")
dbname = self.settings.get("dbname")
conn = SQLite3(dbname)
hid = hashlib.sha256(request['id'].encode('utf-8'))
# check limits first
num_requests = yield conn.get_num_requests(
id=hid.hexdigest(), service=request['service']
)
if num_requests[0][0] > email_requests_limit:
log.msg(
"Discarded. Too many requests from {}.".format(
hid.hexdigest
), system="email parser"
log.msg(
"Found request for {}.".format(request['command']),
system="email parser"
)
else:
if check_num_request(request['id'], request['service'], email_request_limit):
conn.new_request(
id=request['id'],
command=request['command'],
......@@ -245,6 +245,18 @@ class EmailParser(object):
date=now_str,
status="ONHOLD",
)
else:
log.msg(
"Discarded. Too many requests from {}.".format(
hid.hexdigest
), system="email parser"
)
else:
log.msg(
"Request not found",
system="email parser"
)
def parse_errback(self, error):
"""
......
......@@ -7,7 +7,7 @@
"help_config": "Custom config file location (optional)",
"smtp_links_subject": "[GetTor] Links for your request",
"smtp_mirrors_subject": "[GetTor] Mirrors",
"smtp_help_subject": "[GetTor] Help",
"smtp_help_subject": "[GetTor] Ayuda",
"smtp_unsupported_locale_subject": "[GetTor] Unsupported locale",
"smtp_unsupported_locale_msg": "The locale you requested '{}' is not supported.",
"smtp_vlinks_msg": "You requested Tor Browser for {}.\n\nYou will need only one of the links below to download the bundle. If a link does not work for you, try the next one.\n\n{}\n\nShould you have issues with any of the links above you can access the following Google Drive folder: https://drive.google.com/open?id=13CADQTsCwrGsIID09YQbNz2DfRMUoxUU\n\n Download the file: {}\n\n \n--\nGetTor",
......
......@@ -58,6 +58,17 @@ class EmailServiceTests(unittest.TestCase):
self.assertEqual(request["platform"], "osx")
self.assertEqual(request["language"], "es")
def test_remove_limits(self):
ep = conftests.EmailParser(self.settings, "gettor@torproject.org")
msg_str = "From: \"GetTor Test\" <test.gettor.browser@gmail.com>\n Subject: \r\n Reply-To: test.gettor.browser@gmail.com \nTo: gettor@torproject.org\r\n osx es"
msg = conftests.message_from_string(msg_str)
languages = [*self.locales.keys()]
platforms = self.settings.get('platforms')
request = ep.build_request(msg_str, "hiro@torproject.org", languages, platforms)
email_requests_limit = self.settings.get("email_requests_limit")
check = check_num_request(request['id'], request['service'], email_request_limit)
assert check
def test_language_email_parser(self):
ep = conftests.EmailParser(self.settings, "gettor@torproject.org")
request = ep.parse("From: \"silvia [hiro]\" <hiro@torproject.org>\n Subject: \r\n Reply-To: hiro@torproject.org \nTo: gettor@torproject.org\n osx en")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment