From 7cc56af2bb69583b4d2b5ea0febc991d1142e6e2 Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Fri, 17 Jun 2016 19:02:53 -0700 Subject: [PATCH] bugfix 1593883 pjlink authenticatino test --- openlp/core/common/__init__.py | 3 +- .../openlp_core_lib/test_projector_pjlink1.py | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index 5da4d6dc4..488fbc63b 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -226,7 +226,8 @@ def qmd5_hash(salt, data=None): log.debug('qmd5_hash(salt="{text}"'.format(text=salt)) hash_obj = QHash(QHash.Md5) hash_obj.addData(salt.encode('ascii')) - hash_obj.addData(data.encode('ascii')) + if data: + hash_obj.addData(data.encode('ascii')) hash_value = hash_obj.result().toHex() log.debug('qmd5_hash() returning "{hash}"'.format(hash=hash_value)) return hash_value diff --git a/tests/functional/openlp_core_lib/test_projector_pjlink1.py b/tests/functional/openlp_core_lib/test_projector_pjlink1.py index cb9b7751f..1c56e5bec 100644 --- a/tests/functional/openlp_core_lib/test_projector_pjlink1.py +++ b/tests/functional/openlp_core_lib/test_projector_pjlink1.py @@ -30,7 +30,7 @@ from openlp.core.lib.projector.constants import E_PARAMETER, ERROR_STRING, S_OFF S_COOLDOWN, PJLINK_POWR_STATUS from tests.functional import patch -from tests.resources.projector.data import TEST_PIN, TEST_SALT, TEST_CONNECT_AUTHENTICATE +from tests.resources.projector.data import TEST_PIN, TEST_SALT, TEST_CONNECT_AUTHENTICATE, TEST_HASH pjlink_test = PJLink1(name='test', ip='127.0.0.1', pin=TEST_PIN, no_poll=True) @@ -355,4 +355,30 @@ class TestPJLink(TestCase): pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE) # THEN: No Authentication signal should have been sent - mock_authentication.called_with(pjlink.name, 'projectorAuthentication should have been called') + mock_authentication.assert_called_with(pjlink.name, 'projectorAuthentication should have been called') + + @patch.object(pjlink_test, 'waitForReadyRead') + @patch.object(pjlink_test, 'state') + @patch.object(pjlink_test, '_send_command') + @patch.object(pjlink_test, 'timer') + @patch.object(pjlink_test, 'socket_timer') + def test_bug_1593883_pjlink_authentication(self, mock_socket_timer, + mock_timer, + mock_send_command, + mock_state, + mock_waitForReadyRead): + """ + Test bugfix 1593883 pjlink authentication + """ + # GIVEN: Test object and data + pjlink = pjlink_test + pjlink_pin = TEST_PIN + mock_state.return_value = pjlink.ConnectedState + mock_waitForReadyRead.return_value = True + + # WHEN: Athenticated connection is called + pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE) + + # THEN: send_command should have the proper authentication + self.assertEquals("{test}".format(test=mock_send_command.call_args_list[0]), + "call(data='{hash}%1CLSS ?\\r')".format(hash=TEST_HASH))