Commit d365ee80 authored by Carlos Ramos Carreño's avatar Carlos Ramos Carreño

Fix `_mntpt_4zurl` to accept strings.

Strings cannot be directly hashed without encoding them first, or
an error will be raised:

```python
______________________________________________________________________ test_zsync_resync _______________________________________________________________________

    @func
    def test_zsync_resync():
        zstor = testdb.getZODBStorage()
        defer(zstor.close)

>       db, zconn, wconn = _zsync_setup(zstor)

wcfs/client/_wczsync_test.py:112:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../venvs/wendelin.core/lib/python3.9/site-packages/decorator.py:232: in fun
    return caller(func, *(extras + args), **kw)
../pygolang/golang/__init__.py:125: in _
    return f(*argv, **kw)
wcfs/client/_wczsync_test.py:53: in _zsync_setup
    wc = wcfs.join(zurl)
wcfs/__init__.py:201: in join
    mntpt = _mntpt_4zurl(zurl)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

zurl = 'file:///srv/slapgrid/slappart66/tmp/testdb_fs.xstpbg49/1.fs'

    def _mntpt_4zurl(zurl):
        # normalize zurl so that even if we have e.g. two neos:// urls coming
        # with different paths to ssl keys, or with different order in the list of
        # masters, we still have them associated with the same wcfs mountpoint.
        zurl = zurl_normalize_main(zurl)

        m = hashlib.sha1()
>       m.update(zurl)
E       TypeError: Strings must be encoded before hashing
```

We fix this error by encoding the string as UTF8 before hashing it.
parent 6f5456b5
......@@ -67,6 +67,7 @@ The following environment variables can be used to control wcfs.py client:
from __future__ import print_function, absolute_import
import os, sys, hashlib, subprocess, stat
import six
import logging; log = logging.getLogger('wcfs')
from os.path import dirname
from stat import S_ISDIR
......@@ -504,6 +505,9 @@ def _mntpt_4zurl(zurl):
# masters, we still have them associated with the same wcfs mountpoint.
zurl = zurl_normalize_main(zurl)
if isinstance(zurl, six.text_type):
zurl = zurl.encode("utf-8")
m = hashlib.sha1()
m.update(zurl)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment