[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/main] Add bad language input test in translations module
commit ee08b6b172a9762c977af6ca8ad29582d703e003
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date: Mon May 31 13:01:46 2021 -0400
Add bad language input test in translations module
---
bridgedb/test/test_translations.py | 41 +++++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/bridgedb/test/test_translations.py b/bridgedb/test/test_translations.py
index 4b504f1..1fcfc3a 100644
--- a/bridgedb/test/test_translations.py
+++ b/bridgedb/test/test_translations.py
@@ -26,6 +26,9 @@ REALISH_HEADERS = {
ACCEPT_LANGUAGE_HEADER = {
b'Accept-Language': [b'de-de,en-gb;q=0.8,en;q=0.5,en-us;q=0.3'],
}
+BAD_ACCEPT_LANGUAGE_HEADER = {
+ b'Accept-Language': [b'hackityhackhack'],
+}
class TranslationsMiscTests(unittest.TestCase):
@@ -52,7 +55,7 @@ class TranslationsMiscTests(unittest.TestCase):
self.assertEqual(parsed[2], 'en_US')
def test_getLocaleFromHTTPRequest_withLangParam_AcceptLanguage(self):
- """This request uses a '?lang=ar' param, with an 'Accept-Language'
+ """This request uses a '?lang=fa' param, with an 'Accept-Language'
header which includes: ['de-de', 'en-gb', 'en', 'en-us'].
The request result should be: ['fa', 'de-de', 'en-gb', 'en', 'en-us'].
@@ -69,6 +72,42 @@ class TranslationsMiscTests(unittest.TestCase):
self.assertEqual(parsed[2], 'en_US')
#self.assertEqual(parsed[3], 'en-gb')
+ def test_getLocaleFromHTTPRequest_withBadLangParam(self):
+ """This request uses a '?lang=shouldfail' param, without an 'Accept-Language'
+ header.
+
+ The request result should be: ['en', 'en-US'].
+ """
+ request = DummyRequest([b"bridges"])
+ request.headers.update(REALISH_HEADERS)
+ request.args.update({
+ 'transport': ['obfs3',],
+ 'lang': ['shouldfail',],
+ })
+
+ parsed = translations.getLocaleFromHTTPRequest(request)
+
+ self.assertEqual(len(parsed), 2)
+ self.assertEqual(parsed[0], 'en')
+ self.assertEqual(parsed[1], 'en_US')
+
+ def test_getLocaleFromHTTPRequest_withLangParam_BadAcceptLanguage(self):
+ """This request uses a '?lang=fa' param, with an 'Accept-Language'
+ header which includes: ['hackityhackhack'].
+
+ The request result should be: ['fa', 'en', 'en-us'].
+ """
+ request = DummyRequest([b"options"])
+ request.headers.update(BAD_ACCEPT_LANGUAGE_HEADER)
+ request.args.update({'lang': ['fa']})
+
+ parsed = translations.getLocaleFromHTTPRequest(request)
+
+ self.assertEqual(len(parsed), 3)
+ self.assertEqual(parsed[0], 'fa')
+ self.assertEqual(parsed[1], 'en')
+ self.assertEqual(parsed[2], 'en_US')
+
def test_getLocaleFromPlusAddr(self):
emailAddr = 'bridges@xxxxxxxxxxxxxx'
replyLocale = translations.getLocaleFromPlusAddr(emailAddr)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits