Code Repositories xandikos / 8799b96
Allow script name to be unset. Fixes #37 Jelmer Vernooń≥ 1 year, 11 months ago
3 changed file(s) with 9 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
4949 class WebTests(WebTestCase):
5050
5151 def _method(self, app, method, path):
52 environ = {'PATH_INFO': path, 'REQUEST_METHOD': method,
53 'SCRIPT_NAME': ''}
52 environ = {'PATH_INFO': path, 'REQUEST_METHOD': method}
5453 setup_testing_defaults(environ)
5554 _code = []
5655 _headers = []
6564 return self._method(app, 'LOCK', path)
6665
6766 def mkcol(self, app, path):
68 environ = {'PATH_INFO': path, 'REQUEST_METHOD': 'MKCOL',
69 'SCRIPT_NAME': ''}
67 environ = {'PATH_INFO': path, 'REQUEST_METHOD': 'MKCOL'}
7068 setup_testing_defaults(environ)
7169 _code = []
7270 _headers = []
7876 return _code[0], _headers, contents
7977
8078 def delete(self, app, path):
81 environ = {'PATH_INFO': path, 'REQUEST_METHOD': 'DELETE',
82 'SCRIPT_NAME': ''}
79 environ = {'PATH_INFO': path, 'REQUEST_METHOD': 'DELETE'}
8380 setup_testing_defaults(environ)
8481 _code = []
8582 _headers = []
9188 return _code[0], _headers, contents
9289
9390 def get(self, app, path):
94 environ = {'PATH_INFO': path, 'REQUEST_METHOD': 'GET',
95 'SCRIPT_NAME': ''}
91 environ = {'PATH_INFO': path, 'REQUEST_METHOD': 'GET'}
9692 setup_testing_defaults(environ)
9793 _code = []
9894 _headers = []
108104 'PATH_INFO': path,
109105 'REQUEST_METHOD': 'PUT',
110106 'wsgi.input': BytesIO(contents),
111 'SCRIPT_NAME': ''
112107 }
113108 setup_testing_defaults(environ)
114109 _code = []
125120 'PATH_INFO': path,
126121 'REQUEST_METHOD': 'PROPFIND',
127122 'wsgi.input': BytesIO(body),
128 'SCRIPT_NAME': ''
129123 }
130124 setup_testing_defaults(environ)
131125 _code = []
853853 def __call__(self, environ, start_response):
854854 # See https://tools.ietf.org/html/rfc6764
855855 path = posixpath.normpath(
856 environ['SCRIPT_NAME'] + environ['PATH_INFO'])
856 environ.get('SCRIPT_NAME', '') + environ['PATH_INFO'])
857857 if path in WELLKNOWN_DAV_PATHS:
858858 start_response('302 Found', [
859859 ('Location', self._dav_root)])
508508 ET.SubElement(el, '{DAV:}unauthenticated')
509509 else:
510510 el.append(create_href(
511 self.current_user_principal, environ['SCRIPT_NAME']))
511 self.current_user_principal, environ.get('SCRIPT_NAME', '')))
512512
513513
514514 class PrincipalURLProperty(Property):
12061206 :param hrefs: List of hrefs to resolve
12071207 :return: iterator over (href, resource) tuples
12081208 """
1209 script_name = environ['SCRIPT_NAME']
1209 script_name = environ.get('SCRIPT_NAME', '')
12101210 # TODO(jelmer): Bulk query hrefs in a more efficient manner
12111211 for href in hrefs:
12121212 if not href.startswith(script_name):
13991399 error=ET.Element(e.precondition),
14001400 description=e.description)
14011401 href = (
1402 environ['SCRIPT_NAME'] +
1402 environ.get('SCRIPT_NAME', '') +
14031403 urllib.parse.urljoin(ensure_trailing_slash(path), name)
14041404 )
14051405 start_response('200 OK', [('Location', href)])
17071707
17081708 def _get_resource_from_environ(self, environ):
17091709 path = path_from_environ(environ, 'PATH_INFO')
1710 href = (environ['SCRIPT_NAME'] + path)
1710 href = (environ.get('SCRIPT_NAME', '') + path)
17111711 r = self.backend.get_resource(path)
17121712 return (href, path, r)
17131713