Skip to content

Commit

Permalink
Finish ckan tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Jan 2, 2020
1 parent c0e540f commit 671057a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions ckan/model/user.py
Expand Up @@ -109,12 +109,12 @@ def _get_password(self):
return self._password

def _verify_and_upgrade_from_sha1(self, password):
if isinstance(password, text_type):
password_8bit = password.encode('ascii', 'ignore')
else:
password_8bit = password
# if isinstance(password, text_type):
# password_8bit = password.encode('ascii', 'ignore')
# else:
# password_8bit = password

hashed_pass = sha1(password_8bit + self.password[:40])
hashed_pass = sha1(six.ensure_binary(password + self.password[:40]))
current_hash = passlib.utils.to_native_str(self.password[40:])

if passlib.utils.consteq(hashed_pass.hexdigest(), current_hash):
Expand Down
4 changes: 2 additions & 2 deletions ckan/tests/model/test_license.py
Expand Up @@ -56,7 +56,7 @@ def test_import_v2_style_register():
assert license.title == "Creative Commons Attribution 4.0"


@pytest.mark.usefixtures("reset")
@pytest.mark.usefixtures("reset", "with_request_context")
@pytest.mark.ckan_config(
"licenses_group_url", "file:///%s/licenses.v1" % this_dir
)
Expand All @@ -69,7 +69,7 @@ def test_import_v1_style_register_i18n(app):
assert "Altres (Oberta)" in resp.body


@pytest.mark.usefixtures("reset")
@pytest.mark.usefixtures("reset", "with_request_context")
@pytest.mark.ckan_config(
"licenses_group_url", "file:///%s/licenses.v2" % this_dir
)
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/model/test_package.py
Expand Up @@ -6,7 +6,7 @@
from ckan.tests import factories


@pytest.mark.usefixtures(u"clean_db")
@pytest.mark.usefixtures(u"clean_db", u"with_request_context")
class TestPackage(object):
def test_create(self):
# Demonstrate creating a package.
Expand Down
12 changes: 6 additions & 6 deletions ckan/tests/model/test_user.py
Expand Up @@ -18,21 +18,21 @@ def _set_password(password):
This is needed to create old password hashes in the tests
"""
if isinstance(password, text_type):
password_8bit = password.encode("ascii", "ignore")
else:
password_8bit = password
# if isinstance(password, text_type):
# password_8bit = password.encode("ascii", "ignore")
# else:
# password_8bit = password

salt = hashlib.sha1(os.urandom(60))
hash = hashlib.sha1(password_8bit + salt.hexdigest())
hash = hashlib.sha1(six.ensure_binary(password + salt.hexdigest()))
hashed_password = salt.hexdigest() + hash.hexdigest()

if not isinstance(hashed_password, text_type):
hashed_password = six.ensure_text(hashed_password)
return hashed_password


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("clean_db", u"with_request_context")
class TestUser:
def test_upgrade_from_sha(self):
user = factories.User()
Expand Down

0 comments on commit 671057a

Please sign in to comment.