Ejemplo n.º 1
0
    def test_endpoints_and_forwarding_url_supplied(self):
        config = {'route': self.forwarding_pattern,
                  'forwarding_url': self.endpoint_1,
                  'endpoints': self.endpoints}

        with ExpectedException(ConfigError):
            route_factory.parse_dict(config)
Ejemplo n.º 2
0
    def test_endpoints_wildcard_missing(self):
        config = {
            'route': self.forwarding_pattern,
            'endpoints': self.endpoints
        }

        with ExpectedException(ConfigError):
            route_factory.parse_dict(config)
Ejemplo n.º 3
0
    def test_endpoints_ignore_errors_range_entry_missing_start_number(self):
        ignore_errors = ["-404"]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'ignore_errors': ignore_errors}

        with ExpectedException(ConfigError):
            route_factory.parse_dict(route_dict)
Ejemplo n.º 4
0
    def test_endpoints_ignore_errors_range_entry_invalid_stop_number(self):
        ignore_errors = ["401-404A"]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'ignore_errors': ignore_errors}

        with ExpectedException(ConfigError):
            route_factory.parse_dict(route_dict)
Ejemplo n.º 5
0
    def test_endpoints_ignore_errors_single_entry_invalid_range_max(self):
        ignore_errors = ["600"]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'ignore_errors': ignore_errors}

        with ExpectedException(ConfigError):
            route_factory.parse_dict(route_dict)
Ejemplo n.º 6
0
    def test_endpoints_and_forwarding_url_supplied(self):
        config = {
            'route': self.forwarding_pattern,
            'forwarding_url': self.endpoint_1,
            'endpoints': self.endpoints
        }

        with ExpectedException(ConfigError):
            route_factory.parse_dict(config)
Ejemplo n.º 7
0
    def test_match_first_route(self):
        route_config_1 = {'route': 'https://www.example.com',
                          'forwarding_url': 'https://1.new.example.com'}
        route_1 = route_factory.parse_dict(route_config_1)
        route_config_2 = {'route': 'https://www.example.com/path',
                          'forwarding_url': 'https://2.new.example.com'}
        route_2 = route_factory.parse_dict(route_config_2)

        self.curry._routes += [route_1, route_2]

        matched_route = self.curry._match_route('https://www.example.com/p')

        self.assertEqual(route_1, matched_route)
Ejemplo n.º 8
0
    def test_matched_route(self):
        # Setup route
        self.route_config = {
            'route': 'https://www.example.com',
            'forwarding_url': 'https://new.example.com'
        }
        self.route = route_factory.parse_dict(self.route_config)
        self.curry._routes.append(self.route)

        # Mocked response
        mock_response = Response()
        mock_response.status = 200
        mock_response.body = 'Response Body'

        # Create request
        environ = {
            'wsgi.url_scheme': 'https',
            'HTTP_HOST': 'www.example.com',
            'PATH_INFO': '/path',
            'QUERY_STRING': 'query=string'
        }
        start_response = StartResponseMock()

        # Issue request
        with patch.object(ForwardingRoute,
                          '__call__',
                          return_value=mock_response):
            response = self.curry.__call__(environ, start_response)

            # Assert
            self.assertEqual(mock_response.status, start_response.status)
            self.assertEqual(mock_response.headerlist, start_response.headers)
            self.assertEqual(mock_response.body, response)
Ejemplo n.º 9
0
    def test_matched_route(self):
        # Setup route
        self.route_config = {'route': 'https://www.example.com',
                             'forwarding_url': 'https://new.example.com'}
        self.route = route_factory.parse_dict(self.route_config)
        self.curry._routes.append(self.route)

        # Mocked response
        mock_response = Response()
        mock_response.status = 200
        mock_response.body = 'Response Body'

        # Create request
        environ = {'wsgi.url_scheme': 'https',
                   'HTTP_HOST': 'www.example.com',
                   'PATH_INFO': '/path',
                   'QUERY_STRING': 'query=string'}
        start_response = StartResponseMock()

        # Issue request
        with patch.object(ForwardingRoute,
                          '__call__',
                          return_value=mock_response):
            response = self.curry.__call__(environ, start_response)

            # Assert
            self.assertEqual(mock_response.status, start_response.status)
            self.assertEqual(mock_response.headerlist, start_response.headers)
            self.assertEqual(mock_response.body, response)
Ejemplo n.º 10
0
    def test_endpoints_ignore_errors_single_entry_valid_range_min(self):
        ignore_errors = ["0"]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'ignore_errors': ignore_errors}

        route = route_factory.parse_dict(route_dict)
        self.assertEqual([0], route._ignore_errors)
Ejemplo n.º 11
0
    def test_endpoints_priority_errors(self):
        priority_errors = [401, 404]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'priority_errors': priority_errors}

        route = route_factory.parse_dict(route_dict)

        self.assertEqual(priority_errors, route._priority_errors)
Ejemplo n.º 12
0
    def test_endpoints(self):
        route = route_factory.parse_dict(self.endpoints_config)

        self.assertTrue(self.endpoint_1['id'] in route._endpoints)
        self.assertEqual(self.endpoint_1['url'],
                         route._endpoints[self.endpoint_1['id']])
        self.assertTrue(self.endpoint_2['id'] in route._endpoints)
        self.assertEqual(self.endpoint_2['url'],
                         route._endpoints[self.endpoint_2['id']])
Ejemplo n.º 13
0
    def test_endpoint(self):
        config = {'route': self.endpoints_pattern,
                  'endpoints': [self.endpoint_1]}

        route = route_factory.parse_dict(config)

        self.assertTrue(self.endpoint_1['id'] in route._endpoints)
        self.assertEqual(self.endpoint_1['url'],
                         route._endpoints[self.endpoint_1['id']])
Ejemplo n.º 14
0
    def test_endpoints(self):
        route = route_factory.parse_dict(self.endpoints_config)

        self.assertTrue(self.endpoint_1['id'] in route._endpoints)
        self.assertEqual(self.endpoint_1['url'],
                         route._endpoints[self.endpoint_1['id']])
        self.assertTrue(self.endpoint_2['id'] in route._endpoints)
        self.assertEqual(self.endpoint_2['url'],
                         route._endpoints[self.endpoint_2['id']])
Ejemplo n.º 15
0
    def test_unmatched_no_matching_routes(self):
        route_config = {'route': 'https://www.example.com',
                        'forwarding_url': 'https://new.example.com'}
        route = route_factory.parse_dict(route_config)

        self.curry._routes.append(route)

        with ExpectedException(RequestError):
            self.curry._match_route('https://1.www.example.com/path')
Ejemplo n.º 16
0
    def test_endpoints_ignore_errors_range_entry_valid(self):
        ignore_errors = ["401-404"]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'ignore_errors': ignore_errors}

        route = route_factory.parse_dict(route_dict)

        self.assertEqual(range(401, 405), route._ignore_errors)
Ejemplo n.º 17
0
    def test_match(self):
        route_config = {'route': 'https://www.example.com',
                        'forwarding_url': 'https://new.example.com'}
        route = route_factory.parse_dict(route_config)

        self.curry._routes.append(route)

        matched_route = self.curry._match_route('https://www.example.com/path')

        self.assertEqual(route, matched_route)
Ejemplo n.º 18
0
    def test_endpoint(self):
        config = {
            'route': self.endpoints_pattern,
            'endpoints': [self.endpoint_1]
        }

        route = route_factory.parse_dict(config)

        self.assertTrue(self.endpoint_1['id'] in route._endpoints)
        self.assertEqual(self.endpoint_1['url'],
                         route._endpoints[self.endpoint_1['id']])
Ejemplo n.º 19
0
    def test_endpoints_priority_errors(self):
        priority_errors = [401, 404]
        route_dict = {
            'route': self.endpoints_pattern,
            'endpoints': self.endpoints,
            'priority_errors': priority_errors
        }

        route = route_factory.parse_dict(route_dict)

        self.assertEqual(priority_errors, route._priority_errors)
Ejemplo n.º 20
0
    def _process_routes(self, routes_file):
        """Read a configuration file and setup an instance of CurryProxy.

        Args:
            routes_file: Path to CurryProxy's main configuration file which
                details the routes to be served and the backend endpoints each
                route points to.

        """
        try:
            route_configs = json.load(open(routes_file))
        except ValueError:
            raise ConfigError('Configuration file contains invalid JSON.')

        for route_config in route_configs:
            self._routes.append(route_factory.parse_dict(route_config))
Ejemplo n.º 21
0
    def test_endpoints_wildcard_missing(self):
        config = {'route': self.forwarding_pattern,
                  'endpoints': self.endpoints}

        with ExpectedException(ConfigError):
            route_factory.parse_dict(config)
Ejemplo n.º 22
0
    def test_forwarding_url(self):
        route = route_factory.parse_dict(self.forwarding_config)

        self.assertEqual(self.endpoint_1, route._forwarding_url)
Ejemplo n.º 23
0
    def test_endpoints_ignore_errors_missing(self):
        route = route_factory.parse_dict(self.endpoints_config)

        self.assertEqual([], route._ignore_errors)
Ejemplo n.º 24
0
    def test_forwarding_url(self):
        route = route_factory.parse_dict(self.forwarding_config)

        self.assertEqual(self.endpoint_1, route._forwarding_url)
Ejemplo n.º 25
0
    def test_route(self):
        route = route_factory.parse_dict(self.endpoints_config)

        self.assertEqual([self.endpoints_pattern], route._url_patterns)
Ejemplo n.º 26
0
 def test_route_missing(self):
     with ExpectedException(ConfigError):
         route_factory.parse_dict({'endpoints': self.endpoints})
Ejemplo n.º 27
0
 def test_endpoints_and_forwarding_url_missing(self):
     with ExpectedException(ConfigError):
         route_factory.parse_dict({'route': self.forwarding_pattern})
Ejemplo n.º 28
0
    def test_status(self):
        route_dict = {'status': ['http://curryproxy.example.com/status']}

        route = route_factory.parse_dict(route_dict)

        self.assertEqual(route_dict['status'], route._url_patterns)
Ejemplo n.º 29
0
 def test_endpoints_and_forwarding_url_missing(self):
     with ExpectedException(ConfigError):
         route_factory.parse_dict({'route': self.forwarding_pattern})
Ejemplo n.º 30
0
    def test_route(self):
        route = route_factory.parse_dict(self.endpoints_config)

        self.assertEqual([self.endpoints_pattern], route._url_patterns)
Ejemplo n.º 31
0
 def test_route_missing(self):
     with ExpectedException(ConfigError):
         route_factory.parse_dict({'endpoints': self.endpoints})
Ejemplo n.º 32
0
    def test_status(self):
        route_dict = {'status': ['http://curryproxy.example.com/status']}

        route = route_factory.parse_dict(route_dict)

        self.assertEqual(route_dict['status'], route._url_patterns)