예제 #1
0
파일: ssl_test.py 프로젝트: 2xyo/transfervm
def assertVdiEqualsUsingHttps(self, record, data):
    headers = {'Authorization': http_test.auth_header(record['username'], record['password'])}
    conn = httplib.HTTPSConnection(record['ip'], int(record['port']))
    try:
        conn.request('GET', record['url_path'], None, headers)
        resp = conn.getresponse()
        respdata = resp.read()

        self.assertEqual(resp.status, 200)
        self.assertEqual(len(data), len(respdata))
        self.assertEqual(data, respdata)
    finally:
        conn.close()
예제 #2
0
def assertVdiEqualsUsingHttps(self, record, data):
    headers = {
        'Authorization':
        http_test.auth_header(record['username'], record['password'])
    }
    conn = httplib.HTTPSConnection(record['ip'], int(record['port']))
    try:
        conn.request('GET', record['url_path'], None, headers)
        resp = conn.getresponse()
        respdata = resp.read()

        self.assertEqual(resp.status, 200)
        self.assertEqual(len(data), len(respdata))
        self.assertEqual(data, respdata)
    finally:
        conn.close()
예제 #3
0
def do_test(self, packet_type=None, session_id=None, data=None, headers=None, expected_status=0, expected_session_id=None, expected_error_code=None, expected_error_context=None, expected_headers=None, connection=None, record=None, vhd=False, vdi_raw=False, ret_headers=False):
    # Setup the host if a record was not passed in
    if not record:
        record = setup_and_get_record(vdi_raw=vdi_raw)

    # Create a new connection if one was not passed in
    if connection:
        conn = connection
    else:
        conn = httplib.HTTPConnection(record['ip'], record['port'])

    reqheaders = {'Authorization': http_test.auth_header(record['username'], record['password'])}
    if packet_type is not None: reqheaders['BITS-Packet-Type'] = packet_type
    logging.debug(session_id)
    if session_id is not None: reqheaders['BITS-Session-Id'] = session_id
    if headers:
        for k, v in headers.iteritems():
            reqheaders[k] = v
    try:
        url_path = record['url_path']
        if vhd:
            url_path = record['url_path'] + ".vhd"
        conn.request('BITS_POST', url_path, data, reqheaders)
        resp = conn.getresponse()
        respheaders = dict((k.lower(), v) for (k, v) in resp.getheaders())
        logging.debug('Got Response headers %r' % respheaders)
	assertHeaderIfValueSet(self, respheaders, 'Content-Length', '0')  # All BITS Acks must have no data.
        resp.read(0)
    finally:
        # Close the connection only if we created it
        if connection:
            conn.close()

    self.assertEqual(expected_status, resp.status)
    assertHeaderIfValueSet(self, respheaders, 'BITS-Packet-Type', 'Ack')
    if expected_session_id:
        assertHeaderIfValueSet(self, respheaders, 'BITS-Session-Id', expected_session_id)
    assertHeaderIfValueSet(self, respheaders, 'BITS-Error-Code', expected_error_code)
    assertHeaderIfValueSet(self, respheaders, 'BITS-Error-Context', expected_error_context)
    if expected_headers:
        for k, v in expected_headers.iteritems():
            assertHeaderIfValueSet(self, respheaders, k, v)

    if ret_headers:
        return (record, respheaders)
    return record
예제 #4
0
def do_test(self,
            packet_type=None,
            session_id=None,
            data=None,
            headers=None,
            expected_status=0,
            expected_session_id=None,
            expected_error_code=None,
            expected_error_context=None,
            expected_headers=None,
            connection=None,
            record=None,
            vhd=False,
            vdi_raw=False,
            ret_headers=False):
    # Setup the host if a record was not passed in
    if not record:
        record = setup_and_get_record(vdi_raw=vdi_raw)

    # Create a new connection if one was not passed in
    if connection:
        conn = connection
    else:
        conn = httplib.HTTPConnection(record['ip'], record['port'])

    reqheaders = {
        'Authorization':
        http_test.auth_header(record['username'], record['password'])
    }
    if packet_type is not None: reqheaders['BITS-Packet-Type'] = packet_type
    logging.debug(session_id)
    if session_id is not None: reqheaders['BITS-Session-Id'] = session_id
    if headers:
        for k, v in headers.iteritems():
            reqheaders[k] = v
    try:
        url_path = record['url_path']
        if vhd:
            url_path = record['url_path'] + ".vhd"
        conn.request('BITS_POST', url_path, data, reqheaders)
        resp = conn.getresponse()
        respheaders = dict((k.lower(), v) for (k, v) in resp.getheaders())
        logging.debug('Got Response headers %r' % respheaders)
        assertHeaderIfValueSet(self, respheaders, 'Content-Length',
                               '0')  # All BITS Acks must have no data.
        resp.read(0)
    finally:
        # Close the connection only if we created it
        if connection:
            conn.close()

    self.assertEqual(expected_status, resp.status)
    assertHeaderIfValueSet(self, respheaders, 'BITS-Packet-Type', 'Ack')
    if expected_session_id:
        assertHeaderIfValueSet(self, respheaders, 'BITS-Session-Id',
                               expected_session_id)
    assertHeaderIfValueSet(self, respheaders, 'BITS-Error-Code',
                           expected_error_code)
    assertHeaderIfValueSet(self, respheaders, 'BITS-Error-Context',
                           expected_error_context)
    if expected_headers:
        for k, v in expected_headers.iteritems():
            assertHeaderIfValueSet(self, respheaders, k, v)

    if ret_headers:
        return (record, respheaders)
    return record