Last change
on this file since 741524f was
46d791a,
checked in by OpenGnSys Support Team <soporte-og@…>, 6 years ago
|
#915 add test for too large HTTP request fields
This test checks for wrong headers HTTP requests:
- POST /clients with a content length larger than a signed int.
- POST /clients with an auth token larger than 63 characters.
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | import requests |
---|
2 | import unittest |
---|
3 | |
---|
4 | class 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 | |
---|
28 | if __name__ == '__main__': |
---|
29 | unittest.main() |
---|
Note: See
TracBrowser
for help on using the repository browser.