@@ -1321,7 +1321,7 @@ def test_unsupported_algorithm(self):
13211321 )
13221322
13231323 @unittest .skipUnless (ssl , "ssl module required" )
1324- def test_url_with_control_char_rejected (self ):
1324+ def test_url_path_with_control_char_rejected (self ):
13251325 for char_no in range (0 , 0x21 ) + range (0x7f , 0x100 ):
13261326 char = chr (char_no )
13271327 schemeless_url = "//localhost:7777/test%s/" % char
@@ -1345,7 +1345,7 @@ def test_url_with_control_char_rejected(self):
13451345 self .unfakehttp ()
13461346
13471347 @unittest .skipUnless (ssl , "ssl module required" )
1348- def test_url_with_newline_header_injection_rejected (self ):
1348+ def test_url_path_with_newline_header_injection_rejected (self ):
13491349 self .fakehttp (b"HTTP/1.1 200 OK\r \n \r \n Hello." )
13501350 host = "localhost:7777?a=1 HTTP/1.1\r \n X-injected: header\r \n TEST: 123"
13511351 schemeless_url = "//" + host + ":8080/test/?test=a"
@@ -1357,14 +1357,32 @@ def test_url_with_newline_header_injection_rejected(self):
13571357 # calls urllib.parse.quote() on the URL which makes all of the
13581358 # above attempts at injection within the url _path_ safe.
13591359 InvalidURL = httplib .InvalidURL
1360- with self .assertRaisesRegexp (
1361- InvalidURL , r"contain control.*\\r.*(found at least . .)" ):
1362- urllib2 .urlopen ("http:" + schemeless_url )
1363- with self .assertRaisesRegexp (InvalidURL , r"contain control.*\\n" ):
1364- urllib2 .urlopen ("https:" + schemeless_url )
1360+ with self .assertRaisesRegexp (InvalidURL ,
1361+ r"contain control.*\\r.*(found at least . .)" ):
1362+ urllib2 .urlopen ("http:{}" .format (schemeless_url ))
1363+ with self .assertRaisesRegexp (InvalidURL ,
1364+ r"contain control.*\\n" ):
1365+ urllib2 .urlopen ("https:{}" .format (schemeless_url ))
13651366 finally :
13661367 self .unfakehttp ()
13671368
1369+ @unittest .skipUnless (ssl , "ssl module required" )
1370+ def test_url_host_with_control_char_rejected (self ):
1371+ for char_no in list (range (0 , 0x21 )) + [0x7f ]:
1372+ char = chr (char_no )
1373+ schemeless_url = "//localhost{}/test/" .format (char )
1374+ self .fakehttp (b"HTTP/1.1 200 OK\r \n \r \n Hello." )
1375+ try :
1376+ escaped_char_repr = repr (char ).replace ('\\ ' , r'\\' )
1377+ InvalidURL = httplib .InvalidURL
1378+ with self .assertRaisesRegexp (InvalidURL ,
1379+ "contain control.*{}" .format (escaped_char_repr )):
1380+ urllib2 .urlopen ("http:{}" .format (schemeless_url ))
1381+ with self .assertRaisesRegexp (InvalidURL ,
1382+ "contain control.*{}" .format (escaped_char_repr )):
1383+ urllib2 .urlopen ("https:{}" .format (schemeless_url ))
1384+ finally :
1385+ self .unfakehttp ()
13681386
13691387
13701388class RequestTests (unittest .TestCase ):
0 commit comments