コード例 #1
0
ファイル: test_core.py プロジェクト: N3MIS15/service.webui
    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)
コード例 #2
0
ファイル: test_core.py プロジェクト: N3MIS15/service.webui
    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)
コード例 #3
0
    def test_http_over_https(self):
        if self.scheme != 'https':
            return self.skip('skipped (not running HTTPS)... ')

        # Try connecting without SSL.
        conn = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
        conn.putrequest('GET', '/', skip_host=True)
        conn.putheader('Host', self.HOST)
        conn.endheaders()
        response = conn.response_class(conn.sock, method='GET')
        try:
            response.begin()
            self.assertEqual(response.status, 400)
            self.body = response.read()
            self.assertBody('The client sent a plain HTTP request, but this '
                            'server only speaks HTTPS on this port.')
        except socket.error as ex:
            # "Connection reset by peer" is also acceptable.
            if ex.errno != errno.ECONNRESET:
                raise