Esempio n. 1
0
    def test_endpoint_for_no_wss(self):
        from twisted.internet import reactor
        factory = ClientEndpointFactory(reactor)

        url_bytes = b'wss://tweets.socket.io/engine.io/?EIO=3&transport=polling'
        url = BaseUrl.fromBytes(url_bytes)
        self.assertRaises(t_error.SchemeNotSupported, factory.endpointForURI, url)
Esempio n. 2
0
    def test_endpoint_for_ws(self):
        from twisted.internet import reactor
        factory = ClientEndpointFactory(reactor)

        url_bytes = b'ws://tweets.socket.io/engine.io/?EIO=3&transport=polling'
        url = BaseUrl.fromBytes(url_bytes)
        endpoint = factory.endpointForURI(url)
        self.assertIsInstance(endpoint, t_endpoints.HostnameEndpoint)
        self.assertEqual(endpoint._host, b'tweets.socket.io') # pylint: disable=protected-access
        self.assertEqual(endpoint._port, 80) # pylint: disable=protected-access

        url_bytes = b'ws://tweets.socket.io:12345/engine.io/?EIO=3&transport=polling'
        url = BaseUrl.fromBytes(url_bytes)
        endpoint = factory.endpointForURI(url)
        self.assertIsInstance(endpoint, t_endpoints.HostnameEndpoint)
        self.assertEqual(endpoint._host, b'tweets.socket.io') # pylint: disable=protected-access
        self.assertEqual(endpoint._port, 12345) # pylint: disable=protected-access
Esempio n. 3
0
    def test_scheme(self):
        base = BaseUrl.fromBytes(b'http://localhost/~xyz')
        self.assertEqual(base.scheme, b'http')

        sub = base.asscheme(b'https')
        self.assertIs(type(sub), BaseUrl)
        self.assertEqual(sub.scheme, b'https')
        self.assertEqual(sub.__str__(), b'https://localhost/~xyz')
Esempio n. 4
0
    def test_endpoint_for_unix(self):
        from twisted.internet import reactor
        factory = ClientEndpointFactory(reactor)

        url_bytes = b'unix://.%2Ftests%2Fnode%2Fhttp.sock/engine.io/?EIO=3&transport=polling'
        url = BaseUrl.fromBytes(url_bytes)
        endpoint = factory.endpointForURI(url)
        self.assertIsInstance(endpoint, t_endpoints.UNIXClientEndpoint)
        self.assertEqual(endpoint._path.encode('utf_8'), b'./tests/node/http.sock') # pylint: disable=protected-access
Esempio n. 5
0
    def setUp(self):
        super().setUp()
        self.url = BaseUrl.fromString(b'unix://<sockpath>/<path>')
        sockpath = './integrations/node/http.sock'
        self.url.netloc = url_parse.quote(sockpath.encode('utf_8'), safe=b'').encode('ascii')
        self.close_d = t_defer.Deferred()

        def _close_handler(event):
            _LOGGER.debug('_close_handler() called with %r', event)

            return reactor.callLater(0, self.close_d.callback, None)

        self.close_handler = _close_handler
Esempio n. 6
0
    def test_child(self):
        base = BaseUrl.fromBytes(b'http://localhost/~xyz?foo=bar')
        sub = base.child(b'')
        self.assertIs(type(sub), BaseUrl)

        if twisted.version < _TWISTED_15_5:
            self.assertEqual(sub.path, b'~xyz/')
        else:
            self.assertEqual(sub.path, b'%7Exyz/')

        sub = base.child(b'/')
        self.assertEqual(sub.path, b'/')

        sub = base.child(b'/abc')
        self.assertEqual(sub.path, b'/abc')
Esempio n. 7
0
    def test_join(self):
        base = BaseUrl.fromBytes(b'http://localhost/~xyz?foo=bar')

        if twisted.version < _TWISTED_15_5:
            self.assertEqual(base.path, b'/~xyz')
        else:
            self.assertEqual(base.path, b'/%7Exyz')

        self.assertEqual(base.query, b'foo=bar')

        p = ( b'', )
        sub = base.join(*p)
        self.assertIs(type(sub), BaseUrl)

        if twisted.version < _TWISTED_15_5:
            self.assertEqual(sub.path, b'/~xyz/')
        else:
            self.assertEqual(sub.path, b'/%7Exyz/')

        self.assertEqual(sub.query, b'')

        subquery = base.joinquery(*p)
        self.assertIs(type(subquery), BaseUrl)
        self.assertEqual(subquery.path, sub.path)
        self.assertEqual(subquery.query, base.query)

        p = ( b'', b'', b'' )
        sub = base.join(*p)

        if twisted.version < _TWISTED_15_5:
            self.assertEqual(sub.path, b'/~xyz/')
        else:
            self.assertEqual(sub.path, b'/%7Exyz/')

        subquery = base.joinquery(*p)
        self.assertEqual(subquery.path, sub.path)
        self.assertEqual(subquery.query, base.query)

        p = ( b'abc', )
        sub = base.join(*p)

        if twisted.version < _TWISTED_15_5:
            self.assertEqual(sub.path, b'/~xyz/abc')
        else:
            self.assertEqual(sub.path, b'/%7Exyz/abc')

        subquery = base.joinquery(*p)
        self.assertEqual(subquery.path, sub.path)
        self.assertEqual(subquery.query, base.query)

        p = ( b'abc', b'' )
        sub = base.join(*p)

        if twisted.version < _TWISTED_15_5:
            self.assertEqual(sub.path, b'/~xyz/abc/')
        else:
            self.assertEqual(sub.path, b'/%7Exyz/abc/')

        subquery = base.joinquery(*p)
        self.assertEqual(subquery.path, sub.path)
        self.assertEqual(subquery.query, base.query)

        p = ( b'abc', b'', b'', b'' )
        sub = base.join(*p)

        if twisted.version < _TWISTED_15_5:
            self.assertEqual(sub.path, b'/~xyz/abc/')
        else:
            self.assertEqual(sub.path, b'/%7Exyz/abc/')

        subquery = base.joinquery(*p)
        self.assertEqual(subquery.path, sub.path)
        self.assertEqual(subquery.query, base.query)

        p = ( b'abc', b'', b'', b'', b'def' )
        sub = base.join(*p)

        if twisted.version < _TWISTED_15_5:
            self.assertEqual(sub.path, b'/~xyz/abc/def')
        else:
            self.assertEqual(sub.path, b'/%7Exyz/abc/def')

        subquery = base.joinquery(*p)
        self.assertEqual(subquery.path, sub.path)
        self.assertEqual(subquery.query, base.query)

        p = ( b'/abc', )
        sub = base.join(*p)
        self.assertEqual(sub.path, b'/abc')

        subquery = base.joinquery(*p)
        self.assertEqual(subquery.path, sub.path)
        self.assertEqual(subquery.query, base.query)
Esempio n. 8
0
 def test_uri(self):
     url_bytes = b'http://localhost/cgi-bin/test?key=val#name'
     uri = t_client.URI.fromBytes(url_bytes)
     base_url = BaseUrl.fromURI(uri)
     self.assertEqual(base_url.unsplit(), url_bytes)
     self.assertEqual(base_url.toURI().toBytes(), uri.toBytes())