def test_parse_service_name(self): assert 'emu' == parse_service_name("/ows/proxy/emu") assert 'emu' == parse_service_name("/ows/proxy/emu/foo/bar") assert 'emu' == parse_service_name("/ows/proxy/emu/") with pytest.raises(ValueError) as e_info: assert 'emu' == parse_service_name("/ows/proxy/") with pytest.raises(ValueError) as e_info: assert 'emu' == parse_service_name("/ows/nowhere/emu")
def check_request(self, request): if request.path.startswith(protected_path): # TODO: fix this code try: service_name = parse_service_name(request.path) except ValueError: service_name = None if service_name and self.service_registry.is_public(service_name): logger.info('public access for service %s', service_name) else: ows_request = OWSRequest(request) if not ows_request.service_allowed(): raise OWSInvalidParameterValue( "service %s not supported" % ows_request.service, value="service") if not ows_request.public_access(): try: token = self.get_token_param(request) access_token = self.tokenstore.fetch_by_token(token) if not access_token: raise AccessTokenNotFound() elif access_token.is_expired(): raise OWSAccessForbidden("Access token is expired.") # update request with user environ from access token request.environ.update(access_token.user_environ) except AccessTokenNotFound: raise OWSAccessForbidden("Access token is required to access this service.")