Esempio n. 1
0
    def test_garbage_in(self):
        # Connect without SSL regardless of server.scheme

        c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
        c._output(b'gjkgjklsgjklsgjkljklsg')
        c._send_output()
        response = c.response_class(c.sock, method='GET')
        try:
            response.begin()
            self.assertEqual(response.status, HTTP_BAD_REQUEST)
            self.assertEqual(response.fp.read(22), b'Malformed Request-Line')
            c.close()
        except socket.error as ex:
            # "Connection reset by peer" is also acceptable.
            if ex.errno != errno.ECONNRESET:
                raise
Esempio n. 2
0
 def test_garbage_in(self):
     # Connect without SSL regardless of server.scheme
     c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
     c._output(ntob('gjkgjklsgjklsgjkljklsg'))
     c._send_output()
     response = c.response_class(c.sock, method="GET")
     try:
         response.begin()
         self.assertEqual(response.status, 400)
         self.assertEqual(response.fp.read(22), ntob("Malformed Request-Line"))
         c.close()
     except socket.error:
         e = sys.exc_info()[1]
         # "Connection reset by peer" is also acceptable.
         if e.errno != errno.ECONNRESET:
             raise
Esempio n. 3
0
 def test_garbage_in(self):
     # Connect without SSL regardless of server.scheme
     c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
     c._output(ntob('gjkgjklsgjklsgjkljklsg'))
     c._send_output()
     response = c.response_class(c.sock, method="GET")
     try:
         response.begin()
         self.assertEqual(response.status, 400)
         self.assertEqual(response.fp.read(22),
                          ntob("Malformed Request-Line"))
         c.close()
     except socket.error:
         e = sys.exc_info()[1]
         # "Connection reset by peer" is also acceptable.
         if e.errno != errno.ECONNRESET:
             raise
Esempio n. 4
0
    def test_http_to_https(self):
        # Test what happens when a client tries to speak HTTP to an HTTPS server
        msg = ("The client sent a plain HTTP request, but this "
               "server only speaks HTTPS on this port.")

        c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
        c.putrequest("GET", "/hello")
        c.endheaders()
        try:
            response = c.getresponse()
        except socket.error:
            pass
        else:
            self.status, self.headers, self.body = webtest.shb(response)
            c.close()
            self.assertStatus(400)
            self.assertBody(msg)
        self.assertInLog(msg)
Esempio n. 5
0
    def test_http_to_https(self):
        # Test what happens when a client tries to speak HTTP to an HTTPS server
        msg = ("The client sent a plain HTTP request, but this "
               "server only speaks HTTPS on this port.")

        c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
        c.putrequest("GET", "/hello")
        c.endheaders()
        try:
            response = c.getresponse()
        except socket.error:
            pass
        else:
            self.status, self.headers, self.body = webtest.shb(response)
            c.close()
            self.assertStatus(400)
            self.assertBody(msg)
        self.assertInLog(msg)