Commit f5275f82 authored by Levin Zimmermann's avatar Levin Zimmermann Committed by Kirill Smelkov

lib/zodb/zurl_normalize_main += explicit filtering depending on scheme

In the old source code we already filtered NEO URI by dropping
credentials, but we applied this filter to any URI, not only the NEO
one. This patch adds a mechanism to apply various filter according to
the specific storage type. Starting with this new patch,
'zurl_normalize_main' also refuses to normalize an URI with an unknown

/reviewed-by @kirr
/reviewed-on nexedi/wendelin.core!17
parent 6032b274
......@@ -562,6 +562,14 @@ def test_zurl_normalize_main(zurl, zurl_norm_ok):
assert zurl_normalize_main(zurl_norm_ok) == zurl_norm_ok
# 'zurl_normalize_main' must explicitly raise an exception if an unsupported
# zodburi scheme is used.
def test_zurl_normalize_main_invalid_scheme():
for uri in "https://test postgres://a:b@c:5432/d".split(" "):
with pytest.raises(NotImplementedError):
# neo_ssl_dict returns the path of precomputed static ssl certificate
# files.
......@@ -455,12 +455,34 @@ def _is_ipv6(host):
# neos://ca=zzz@def:2,abc:1/cluster -> neos://abc:1,def:2/cluster
def zurl_normalize_main(zurl):
scheme, netloc, path, query, frag = urlsplit(zurl)
# Normalization depends on the storage backend (there is no standardized
# zodburi scheme among ZODB storages).
f = _zurl_normalize_registry[scheme.lower()]
except KeyError:
raise NotImplementedError("can't normalize zurl with scheme %s" % scheme)
return urlunsplit(f(scheme, netloc, path, query, frag))
# _znormalizer registers func f for zurl_normalize_main to use as scheme handler.
_zurl_normalize_registry = {} # scheme -> normalization func
def _znormalizer(scheme, f):
assert scheme not in _zurl_normalize_registry
_zurl_normalize_registry[scheme] = f
# Supported storages, but no normalization applied yet (TODO).
_znormalizer('file', lambda *args: args)
_znormalizer('zeo', lambda *args: args)
_znormalizer('demo', lambda *args: args)
def _znormalize_neo(scheme, netloc, path, query, frag):
# remove credentials from zurl.
# The same database can be accessed from different clients with different
# credentials, but we want to map them all to the same single WCFS
# instance.
scheme, netloc, path, query, frag = urlsplit(zurl)
if '@' in netloc:
netloc = netloc[netloc.index('@')+1:]
zurl = urlunsplit((scheme, netloc, path, query, frag))
return zurl
if "@" in netloc:
netloc = netloc[netloc.index("@") + 1 :]
return (scheme, netloc, path, query, frag)
_znormalizer('neo', _znormalize_neo)
_znormalizer('neos', _znormalize_neo)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment