summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2019-09-10 09:06:13 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2019-09-10 11:10:34 +0200
commit46d791ae444eeaf2fb904a06868546756ba277a4 (patch)
tree80d3c39701e8d1bd64ba51050c66eb7631e486c3 /tests
parent36ad0061d76efb9ae774f7043aaaece550eb17c2 (diff)
#915 add test for too large HTTP request fields
This test checks for wrong headers HTTP requests: 1. POST /clients with a content length larger than a signed int. 2. POST /clients with an auth token larger than 63 characters.
Diffstat (limited to 'tests')
-rw-r--r--tests/units/test_0015_wrong_headers.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/units/test_0015_wrong_headers.py b/tests/units/test_0015_wrong_headers.py
new file mode 100644
index 0000000..8a35321
--- /dev/null
+++ b/tests/units/test_0015_wrong_headers.py
@@ -0,0 +1,29 @@
+import requests
+import unittest
+
+class TestPostWrongHeaders(unittest.TestCase):
+
+ def setUp(self):
+ self.url = 'http://localhost:8888/clients'
+ self.too_large_content_length_headers = {'Authorization' :
+ '07b3bfe728954619b58f0107ad73acc1', 'Content-Length' :
+ '999999999999999999999999999999999999999999999999999999999'}
+ self.too_large_auth_headers = {'Authorization' :
+ 'TooLongoTooLongTooLongTooLongTooLongTooLongTooLongTooLong'
+ 'TooLongoTooLongTooLongTooLongTooLongTooLongTooLongTooLong'
+ 'TooLongoTooLongTooLongTooLongTooLongTooLongTooLongTooLong'}
+ self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ] }
+
+ def test_post_too_large_content(self):
+ with self.assertRaises(requests.exceptions.ConnectionError) as context:
+ returned = requests.post(self.url,
+ headers=self.too_large_content_length_headers)
+
+ self.assertTrue('Connection aborted' in str(context.exception))
+
+ def test_post_too_large_auth(self):
+ returned = requests.post(self.url, headers=self.too_large_auth_headers)
+ self.assertEqual(returned.status_code, 401)
+
+if __name__ == '__main__':
+ unittest.main()