Esempio n. 1
0
    def test_create(self):
        self.assertRaises(TypeError, client.RemotingService)
        x = client.RemotingService('http://example.org')

        self.assertEqual(x.url, ('http', 'example.org', '', '', '', ''))

        # amf version
        x = client.RemotingService('http://example.org', pyamf.AMF3)
        self.assertEqual(x.amf_version, pyamf.AMF3)
Esempio n. 2
0
    def test_schemes(self):
        x = client.RemotingService('http://example.org')
        self.assertEquals(x.connection.port, 80)

        x = client.RemotingService('https://example.org')
        self.assertEquals(x.connection.port, 443)

        self.assertRaises(ValueError, client.RemotingService,
                          'ftp://example.org')
Esempio n. 3
0
    def test_schemes(self):
        x = client.RemotingService('http://example.org')
        self.assertEqual(x.url, ('http', 'example.org', '', '', '', ''))

        x = client.RemotingService('https://example.org')
        self.assertEqual(x.url, ('https', 'example.org', '', '', '', ''))

        self.assertRaises(ValueError, client.RemotingService,
                          'ftp://example.org')
Esempio n. 4
0
    def test_execute(self):
        gw = client.RemotingService('http://example.org/x/y/z')
        dc = DummyConnection()
        gw.connection = dc

        dc.tc = self
        dc.expected_headers = {
            'Content-Type': 'application/x-amf',
            'User-Agent': client.DEFAULT_USER_AGENT
        }

        baz = gw.getService('baz', auto_execute=False)
        spam = gw.getService('spam', auto_execute=False)
        wrapper = baz.gak()
        wrapper2 = spam.eggs()

        response = DummyResponse(
            200, '\x00\x00\x00\x00\x00\x02\x00\x0b/1/onRe'
            'sult\x00\x04null\x00\x00\x00\x00\x00\x02\x00\x05hello\x00\x0b/2/o'
            'nResult\x00\x04null\x00\x00\x00\x00\x00\x02\x00\x05hello',
            {'Content-Type': 'application/x-amf'})
        response.tc = self

        dc.expected_url = '/x/y/z'
        dc.expected_value = '\x00\x00\x00\x00\x00\x02\x00\x07baz.gak\x00\x02' + \
            '/1\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\tspam.eggs\x00\x02/2' + \
            '\x00\x00\x00\x00\n\x00\x00\x00\x00'
        dc.response = response

        gw.execute()
        self.assertEquals(gw.requests, [])
Esempio n. 5
0
    def test_get_amf_request(self):
        gw = client.RemotingService('http://example.org', pyamf.AMF3,
                                    pyamf.ClientTypes.FlashCom)

        service = gw.getService('baz')
        method_proxy = service.gak
        wrapper = gw.addRequest(method_proxy, 1, 2, 3)

        envelope = gw.getAMFRequest([wrapper])

        self.assertEquals(envelope.amfVersion, pyamf.AMF3)
        self.assertEquals(envelope.clientType, pyamf.ClientTypes.FlashCom)
        self.assertEquals(envelope.keys(), ['/1'])

        request = envelope['/1']
        self.assertEquals(request.target, 'baz.gak')
        self.assertEquals(request.body, [1, 2, 3])

        envelope2 = gw.getAMFRequest(gw.requests)

        self.assertEquals(envelope2.amfVersion, pyamf.AMF3)
        self.assertEquals(envelope2.clientType, pyamf.ClientTypes.FlashCom)
        self.assertEquals(envelope2.keys(), ['/1'])

        request = envelope2['/1']
        self.assertEquals(request.target, 'baz.gak')
        self.assertEquals(request.body, [1, 2, 3])
Esempio n. 6
0
    def test_add_request(self):
        gw = client.RemotingService('http://spameggs.net')

        self.assertEqual(gw.request_number, 1)
        self.assertEqual(gw.requests, [])
        service = gw.getService('baz')
        wrapper = gw.addRequest(service, 1, 2, 3)

        self.assertEqual(gw.requests, [wrapper])
        self.assertEqual(wrapper.gw, gw)
        self.assertEqual(gw.request_number, 2)
        self.assertEqual(wrapper.id, '/1')
        self.assertEqual(wrapper.service, service)
        self.assertEqual(wrapper.args, (1, 2, 3))

        # add 1 arg
        wrapper2 = gw.addRequest(service, None)

        self.assertEqual(gw.requests, [wrapper, wrapper2])
        self.assertEqual(wrapper2.gw, gw)
        self.assertEqual(gw.request_number, 3)
        self.assertEqual(wrapper2.id, '/2')
        self.assertEqual(wrapper2.service, service)
        self.assertEqual(wrapper2.args, (None, ))

        # add no args
        wrapper3 = gw.addRequest(service)

        self.assertEqual(gw.requests, [wrapper, wrapper2, wrapper3])
        self.assertEqual(wrapper3.gw, gw)
        self.assertEqual(gw.request_number, 4)
        self.assertEqual(wrapper3.id, '/3')
        self.assertEqual(wrapper3.service, service)
        self.assertEqual(wrapper3.args, tuple())
Esempio n. 7
0
    def test_add_http_header(self):
        gw = client.RemotingService('http://example.org/amf-gateway')

        self.assertEquals(gw.http_headers, {})

        gw.addHTTPHeader('ETag', '29083457239804752309485')

        self.assertEquals(gw.http_headers, {'ETag': '29083457239804752309485'})
Esempio n. 8
0
    def test_remove_http_header(self):
        gw = client.RemotingService('http://example.org/amf-gateway')

        gw.http_headers = {'Set-Cookie': 'foo-bar'}

        gw.removeHTTPHeader('Set-Cookie')

        self.assertEquals(gw.http_headers, {})
        self.assertRaises(KeyError, gw.removeHTTPHeader, 'foo-bar')
Esempio n. 9
0
    def test_create(self):
        self.assertRaises(TypeError, client.RemotingService)
        x = client.RemotingService('http://example.org')

        self.assertEquals(x.url, ('http', 'example.org', '', '', '', ''))

        self.assertEquals(x.connection.host, 'example.org')
        self.assertEquals(x.connection.port, 80)

        # amf version
        x = client.RemotingService('http://example.org', pyamf.AMF3)
        self.assertEquals(x.amf_version, pyamf.AMF3)

        # client type
        x = client.RemotingService('http://example.org', pyamf.AMF3,
                                   pyamf.ClientTypes.FlashCom)

        self.assertEquals(x.client_type, pyamf.ClientTypes.FlashCom)
Esempio n. 10
0
    def test_get_service(self):
        x = client.RemotingService('http://example.org')

        y = x.getService('spam')

        self.assertTrue(isinstance(y, client.ServiceProxy))
        self.assertEqual(y._name, 'spam')
        self.assertEqual(y._gw, x)

        self.assertRaises(TypeError, x.getService, 1)
Esempio n. 11
0
    def test_close_http_response(self):
        gw = client.RemotingService('http://example.org/amf-gateway')
        dc = DummyConnection()
        gw.connection = dc
        dc.response = DummyResponse(200, '\x00\x00\x00\x01\x00\x11ReplaceGatewayUrl'
            '\x01\x00\x00\x00\x00\x02\x00\x10http://spam.eggs\x00\x00', {
            'Content-Type': 'application/x-amf'})

        gw._getResponse()
        self.assertTrue(dc.response.closed, True)
Esempio n. 12
0
    def test_append_url_header(self):
        gw = client.RemotingService('http://example.org/amf-gateway')
        dc = DummyConnection()
        gw.connection = dc

        response = DummyResponse(200, '\x00\x00\x00\x01\x00\x12AppendToGatewayUrl'
            '\x01\x00\x00\x00\x00\x02\x00\x05hello\x00\x00', {
            'Content-Type': 'application/x-amf'})

        dc.response = response

        response = gw._getResponse()
        self.assertEquals(gw.original_url, 'http://example.org/amf-gatewayhello')
Esempio n. 13
0
    def test_replace_url_header(self):
        gw = client.RemotingService('http://example.org/amf-gateway')
        dc = DummyConnection()
        gw.connection = dc

        response = DummyResponse(200, '\x00\x00\x00\x01\x00\x11ReplaceGatewayUrl'
            '\x01\x00\x00\x00\x00\x02\x00\x10http://spam.eggs\x00\x00', {
            'Content-Type': 'application/x-amf'})

        dc.response = response

        response = gw._getResponse()
        self.assertEquals(gw.original_url, 'http://spam.eggs')
Esempio n. 14
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.response = MockResponse()
        self.opener = MockOpener(self, self.response)

        self.gw = client.RemotingService('http://example.org/amf-gateway',
                                         opener=self.opener.open)

        self.headers = self.__class__.headers.copy()
        self.headers['Content-Length'] = len(self.canned_response)

        self.setResponse(200, self.canned_response, self.headers)
Esempio n. 15
0
    def test_get_request(self):
        gw = client.RemotingService('http://spameggs.net')

        service = gw.getService('baz')
        wrapper = gw.addRequest(service, 1, 2, 3)

        wrapper2 = gw.getRequest(str(wrapper))
        self.assertEqual(wrapper, wrapper2)

        wrapper2 = gw.getRequest('/1')
        self.assertEqual(wrapper, wrapper2)

        wrapper2 = gw.getRequest(wrapper.id)
        self.assertEqual(wrapper, wrapper2)
Esempio n. 16
0
    def test_credentials(self):
        gw = client.RemotingService('http://example.org/amf-gateway')

        self.assertFalse('Credentials' in gw.headers)
        gw.setCredentials('spam', 'eggs')
        self.assertTrue('Credentials' in gw.headers)
        self.assertEquals(gw.headers['Credentials'],
            {'userid' : u'spam', 'password': u'eggs'})

        envelope = gw.getAMFRequest([])
        self.assertTrue('Credentials' in envelope.headers)

        cred = envelope.headers['Credentials']

        self.assertEquals(envelope.headers['Credentials'], gw.headers['Credentials'])
Esempio n. 17
0
    def test_bad_content_length(self):
        gw = client.RemotingService('http://example.org/amf-gateway')
        dc = DummyConnection()
        gw.connection = dc

        # test a really borked content-length header
        http_response = DummyResponse(
            200, '\x00\x00\x00\x01\x00\x11ReplaceGatewayUrl'
            '\x01\x00\x00\x00\x00\x02\x00\x10http://spam.eggs\x00\x00', {
                'Content-Type': 'application/x-amf',
                'Content-Length': 'asdfasdf'
            })

        dc.response = http_response
        self.assertRaises(ValueError, gw._getResponse)
Esempio n. 18
0
    def test_remove_request(self):
        gw = client.RemotingService('http://spameggs.net')
        self.assertEqual(gw.requests, [])

        service = gw.getService('baz')
        wrapper = gw.addRequest(service, 1, 2, 3)
        self.assertEqual(gw.requests, [wrapper])

        gw.removeRequest(wrapper)
        self.assertEqual(gw.requests, [])

        wrapper = gw.addRequest(service, 1, 2, 3)
        self.assertEqual(gw.requests, [wrapper])

        gw.removeRequest(service, 1, 2, 3)
        self.assertEqual(gw.requests, [])

        self.assertRaises(LookupError, gw.removeRequest, service, 1, 2, 3)
Esempio n. 19
0
    def test_execute_single(self):
        gw = client.RemotingService('http://example.org/x/y/z')
        dc = DummyConnection()
        gw.connection = dc

        dc.tc = self
        dc.expected_headers = {
            'Content-Type': remoting.CONTENT_TYPE,
            'User-Agent': client.DEFAULT_USER_AGENT
        }

        service = gw.getService('baz', auto_execute=False)
        wrapper = service.gak()

        response = DummyResponse(
            200, '\x00\x00\x00\x00\x00\x01\x00\x0b/1/onRe'
            'sult\x00\x04null\x00\x00\x00\x00\x00\x02\x00\x05hello', {
                'Content-Type': 'application/x-amf',
                'Content-Length': 50
            })
        response.tc = self

        dc.expected_url = '/x/y/z'
        dc.expected_value = '\x00\x00\x00\x00\x00\x01\x00\x07baz.gak\x00' + \
            '\x02/1\x00\x00\x00\x00\x0a\x00\x00\x00\x00'
        dc.response = response

        gw.execute_single(wrapper)
        self.assertEquals(gw.requests, [])

        wrapper = service.gak()

        response = DummyResponse(
            200, '\x00\x00\x00\x00\x00\x01\x00\x0b/2/onRe'
            'sult\x00\x04null\x00\x00\x00\x00\x00\x02\x00\x05hello',
            {'Content-Type': 'application/x-amf'})
        response.tc = self

        dc.expected_url = '/x/y/z'
        dc.expected_value = '\x00\x00\x00\x00\x00\x01\x00\x07baz.gak\x00' + \
            '\x02/2\x00\x00\x00\x00\n\x00\x00\x00\x00'
        dc.response = response

        gw.execute_single(wrapper)
Esempio n. 20
0
    def test_http_request_headers(self):
        gw = client.RemotingService('http://example.org/amf-gateway')
        dc = DummyConnection()
        gw.connection = dc
        dc.tc = self
        dc.expected_url = '/amf-gateway'
        dc.expected_value = '\x00\x00\x00\x00\x00\x00'

        gw.addHTTPHeader('ETag', '29083457239804752309485')
        dc.expected_headers = {
            'ETag': '29083457239804752309485',
            'Content-Type': 'application/x-amf',
            'User-Agent': gw.user_agent
        }

        dc.response = DummyResponse(
            200, '\x00\x00\x00\x01\x00\x11ReplaceGatewayUrl'
            '\x01\x00\x00\x00\x00\x02\x00\x10http://spam.eggs\x00\x00',
            {'Content-Type': 'application/x-amf'})

        gw.execute()
        self.assertTrue(dc.response.closed, True)
Esempio n. 21
0
    def test_get_response(self):
        gw = client.RemotingService('http://example.org/amf-gateway')
        dc = DummyConnection()
        gw.connection = dc

        response = DummyResponse(200, '\x00\x00\x00\x00\x00\x00',
                                 {'Content-Type': 'application/x-amf'})

        dc.response = response

        gw._getResponse()

        response = DummyResponse(404, '', {})
        dc.response = response

        self.assertRaises(remoting.RemotingError, gw._getResponse)

        # bad content type
        response = DummyResponse(200, '\x00\x00\x00\x00\x00\x00',
                                 {'Content-Type': 'text/html'})
        dc.response = response

        self.assertRaises(remoting.RemotingError, gw._getResponse)
Esempio n. 22
0
 def test_port(self):
     x = client.RemotingService('http://example.org:8080')
     self.assertEquals(x.connection.host, 'example.org')
     self.assertEquals(x.connection.port, 8080)
Esempio n. 23
0
    def test_port(self):
        x = client.RemotingService('http://example.org:8080')

        self.assertEqual(x.url, ('http', 'example.org:8080', '', '', '', ''))