source: ogServer-Git/tests/units/test_0015_wrong_headers.py

Last change on this file was 46d791a, checked in by OpenGnSys Support Team <soporte-og@…>, 5 years ago

#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.
  • Property mode set to 100644
File size: 1.2 KB
Line 
1import requests
2import unittest
3
4class TestPostWrongHeaders(unittest.TestCase):
5
6    def setUp(self):
7        self.url = 'http://localhost:8888/clients'
8        self.too_large_content_length_headers = {'Authorization' :
9                '07b3bfe728954619b58f0107ad73acc1', 'Content-Length' :
10                '999999999999999999999999999999999999999999999999999999999'}
11        self.too_large_auth_headers = {'Authorization' :
12                'TooLongoTooLongTooLongTooLongTooLongTooLongTooLongTooLong'
13                'TooLongoTooLongTooLongTooLongTooLongTooLongTooLongTooLong'
14                'TooLongoTooLongTooLongTooLongTooLongTooLongTooLongTooLong'}
15        self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ] }
16
17    def test_post_too_large_content(self):
18        with self.assertRaises(requests.exceptions.ConnectionError) as context:
19            returned = requests.post(self.url,
20                    headers=self.too_large_content_length_headers)
21
22        self.assertTrue('Connection aborted' in str(context.exception))
23
24    def test_post_too_large_auth(self):
25        returned = requests.post(self.url, headers=self.too_large_auth_headers)
26        self.assertEqual(returned.status_code, 401)
27
28if __name__ == '__main__':
29    unittest.main()
Note: See TracBrowser for help on using the repository browser.