summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2019-06-11 15:51:00 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2019-06-11 20:14:11 +0100
commit632089940cb2a9ebdc66b1f443ab8905daee074d (patch)
tree79b9d8fe9aa1719148fbf2183dc8eab709626e23
parent5d7db3e727d3f9b9ba42a5aaedf925fde6146c9d (diff)
downloaddeluge-632089940cb2a9ebdc66b1f443ab8905daee074d.tar.gz
deluge-632089940cb2a9ebdc66b1f443ab8905daee074d.tar.bz2
deluge-632089940cb2a9ebdc66b1f443ab8905daee074d.zip
[Web] Fix unable to change password
The hashlib update method requires bytes and raised a TypeError for salt passed as text. Added a test for auth change_password Fixes: #3262
-rw-r--r--CHANGELOG.md1
-rw-r--r--deluge/tests/test_web_auth.py36
-rw-r--r--deluge/ui/web/auth.py2
3 files changed, 38 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 12400dd90..d2ae328bb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
- Fix TypeError in Peers Tab setting country flag.
- Fix reverse proxy header TypeError (#3260).
- Fix request.base 'idna' codec error (#3261).
+- Fix unable to change password (#3262).
### Documentation
diff --git a/deluge/tests/test_web_auth.py b/deluge/tests/test_web_auth.py
new file mode 100644
index 000000000..a5185737c
--- /dev/null
+++ b/deluge/tests/test_web_auth.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
+# the additional special exception to link portions of this program with the OpenSSL library.
+# See LICENSE for more details.
+#
+from __future__ import unicode_literals
+
+from mock import patch
+from twisted.trial import unittest
+
+from deluge.ui.web import auth
+
+
+class MockConfig(object):
+ def __init__(self, config):
+ self.config = config
+
+ def __getitem__(self, key):
+ return self.config[key]
+
+ def __setitem__(self, key, value):
+ self.config[key] = value
+
+
+class WebAuthTestCase(unittest.TestCase):
+ @patch('deluge.ui.web.auth.JSONComponent.__init__', return_value=None)
+ def test_change_password(self, mock_json):
+ config = MockConfig(
+ {
+ 'pwd_sha1': '8d8ff487626141d2b91025901d3ab57211180b48',
+ 'pwd_salt': '7555d757710158655bd1646e207dee21a89e9226',
+ }
+ )
+ webauth = auth.Auth(config)
+ self.assertTrue(webauth.change_password('deluge', 'deluge_new'))
diff --git a/deluge/ui/web/auth.py b/deluge/ui/web/auth.py
index e344eaa99..fa9504954 100644
--- a/deluge/ui/web/auth.py
+++ b/deluge/ui/web/auth.py
@@ -198,7 +198,7 @@ class Auth(JSONComponent):
"""
log.debug('Changing password')
salt = hashlib.sha1(os.urandom(32)).hexdigest()
- s = hashlib.sha1(salt)
+ s = hashlib.sha1(salt.encode('utf-8'))
s.update(new_password.encode('utf8'))
self.config['pwd_salt'] = salt
self.config['pwd_sha1'] = s.hexdigest()