openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #25994
[Merge] lp:~alisonken1/openlp/hash_fix into lp:openlp
Ken Roberts has proposed merging lp:~alisonken1/openlp/hash_fix into lp:openlp.
Requested reviews:
Tim Bentley (trb143)
Related bugs:
Bug #1417809 in OpenLP: "non-ascii characters in file path of images and presentation causes traceback"
https://bugs.launchpad.net/openlp/+bug/1417809
For more details, see:
https://code.launchpad.net/~alisonken1/openlp/hash_fix/+merge/248583
Remove default ascii encoding so md5hash can be used to hash other data
(i.e., filepaths)
Removed new functions
Fixed tests
lp:~alisonken1/openlp/hash_fix (revision 2498)
[SUCCESS] http://ci.openlp.org/job/Branch-01-Pull/931/
[SUCCESS] http://ci.openlp.org/job/Branch-02-Functional-Tests/857/
[FAILURE] http://ci.openlp.org/job/Branch-03-Interface-Tests/802/
Stopping after failure
NOTE: Crosswalk changed webpage interface - failed test is crosswalk import.
--
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/common/__init__.py'
--- openlp/core/common/__init__.py 2015-01-18 13:39:21 +0000
+++ openlp/core/common/__init__.py 2015-02-04 17:00:09 +0000
@@ -190,31 +190,32 @@
return True if verify_ipv4(addr) else verify_ipv6(addr)
-def md5_hash(salt, data):
+def md5_hash(salt, data=None):
"""
Returns the hashed output of md5sum on salt,data
using Python3 hashlib
:param salt: Initial salt
- :param data: Data to hash
+ :param data: OPTIONAL Data to hash
:returns: str
"""
log.debug('md5_hash(salt="%s")' % salt)
hash_obj = hashlib.new('md5')
- hash_obj.update(salt.encode('ascii'))
- hash_obj.update(data.encode('ascii'))
+ hash_obj.update(salt)
+ if data:
+ hash_obj.update(data)
hash_value = hash_obj.hexdigest()
log.debug('md5_hash() returning "%s"' % hash_value)
return hash_value
-def qmd5_hash(salt, data):
+def qmd5_hash(salt, data=None):
"""
Returns the hashed output of MD5Sum on salt, data
using PyQt4.QCryptographicHash.
:param salt: Initial salt
- :param data: Data to hash
+ :param data: OPTIONAL Data to hash
:returns: str
"""
log.debug('qmd5_hash(salt="%s"' % salt)
@@ -223,7 +224,7 @@
hash_obj.addData(data)
hash_value = hash_obj.result().toHex()
log.debug('qmd5_hash() returning "%s"' % hash_value)
- return decode(hash_value.data(), 'ascii')
+ return hash_value.data()
def clean_button_text(button_text):
=== modified file 'openlp/core/lib/projector/pjlink1.py'
--- openlp/core/lib/projector/pjlink1.py 2015-01-22 17:42:29 +0000
+++ openlp/core/lib/projector/pjlink1.py 2015-02-04 17:00:09 +0000
@@ -343,7 +343,7 @@
# Authenticated login with salt
log.debug('(%s) Setting hash with salt="%s"' % (self.ip, data_check[2]))
log.debug('(%s) pin="%s"' % (self.ip, self.pin))
- salt = qmd5_hash(salt=data_check[2], data=self.pin)
+ salt = qmd5_hash(salt=data_check[2].endcode('ascii'), data=self.pin.encode('ascii'))
else:
salt = None
# We're connected at this point, so go ahead and do regular I/O
=== modified file 'tests/functional/openlp_core_common/test_projector_utilities.py'
--- tests/functional/openlp_core_common/test_projector_utilities.py 2015-01-18 13:39:21 +0000
+++ tests/functional/openlp_core_common/test_projector_utilities.py 2015-02-04 17:00:09 +0000
@@ -23,6 +23,8 @@
Package to test the openlp.core.ui.projector.networkutils package.
"""
+import os
+
from unittest import TestCase
from openlp.core.common import verify_ip_address, md5_hash, qmd5_hash
@@ -30,6 +32,8 @@
salt = '498e4a67'
pin = 'JBMIAProjectorLink'
test_hash = '5d8409bc1c3fa39749434aa3a5c38682'
+test_non_ascii_string = '이것은 한국어 시험 문자열'
+test_non_ascii_hash = 'fc00c7912976f6e9c19099b514ced201'
ip4_loopback = '127.0.0.1'
ip4_local = '192.168.1.1'
@@ -120,7 +124,7 @@
Test MD5 hash from salt+data pass (python)
"""
# WHEN: Given a known salt+data
- hash_ = md5_hash(salt=salt, data=pin)
+ hash_ = md5_hash(salt=salt.encode('ascii'), data=pin.encode('ascii'))
# THEN: Validate return has is same
self.assertEquals(hash_, test_hash, 'MD5 should have returned a good hash')
@@ -130,7 +134,7 @@
Test MD5 hash from salt+data fail (python)
"""
# WHEN: Given a different salt+hash
- hash_ = md5_hash(salt=pin, data=salt)
+ hash_ = md5_hash(salt=pin.encode('ascii'), data=salt.encode('ascii'))
# THEN: return data is different
self.assertNotEquals(hash_, test_hash, 'MD5 should have returned a bad hash')
@@ -140,17 +144,37 @@
Test MD5 hash from salt+data pass (Qt)
"""
# WHEN: Given a known salt+data
- hash_ = qmd5_hash(salt=salt, data=pin)
+ hash_ = qmd5_hash(salt=salt.encode('ascii'), data=pin.encode('ascii'))
# THEN: Validate return has is same
- self.assertEquals(hash_, test_hash, 'Qt-MD5 should have returned a good hash')
+ self.assertEquals(hash_.decode('ascii'), test_hash, 'Qt-MD5 should have returned a good hash')
def test_qmd5_hash_bad(self):
"""
Test MD5 hash from salt+hash fail (Qt)
"""
# WHEN: Given a different salt+hash
- hash_ = qmd5_hash(salt=pin, data=salt)
+ hash_ = qmd5_hash(salt=pin.encode('ascii'), data=salt.encode('ascii'))
# THEN: return data is different
- self.assertNotEquals(hash_, test_hash, 'Qt-MD5 should have returned a bad hash')
+ self.assertNotEquals(hash_.decode('ascii'), test_hash, 'Qt-MD5 should have returned a bad hash')
+
+ def test_md5_non_ascii_string(self):
+ """
+ Test MD5 hash with non-ascii string - bug 1417809
+ """
+ # WHEN: Non-ascii string is hashed
+ hash_ = md5_hash(salt=test_non_ascii_string.encode('utf-8'), data=None)
+
+ # THEN: Valid MD5 hash should be returned
+ self.assertEqual(hash_, test_non_ascii_hash, 'MD5 should have returned a valid hash')
+
+ def test_qmd5_non_ascii_string(self):
+ """
+ Test MD5 hash with non-ascii string - bug 1417809
+ """
+ # WHEN: Non-ascii string is hashed
+ hash_ = md5_hash(salt=test_non_ascii_string.encode('utf-8'), data=None)
+
+ # THEN: Valid MD5 hash should be returned
+ self.assertEqual(hash_, test_non_ascii_hash, 'Qt-MD5 should have returned a valid hash')
=== added file 'tests/resources/projector/Wheat.otz'
Binary files tests/resources/projector/Wheat.otz 1970-01-01 00:00:00 +0000 and tests/resources/projector/Wheat.otz 2015-02-04 17:00:09 +0000 differ