~raoul-snyman/openlp/bug-1608194

« back to all changes in this revision

Viewing changes to tests/functional/openlp_core_lib/test_projector_pjlink1.py

Bugfix 1593882 and 1593883 - projector authorization

- Fix exception when authenticated connection requested and pin is None
- Fix pjlink authentication (use python hash instead of qt hash)
- Fix md5_hash functions
- Fix qmd5hash functions
- Added tests for bugfixes
Tested with test server and Eiki XL200 projector

--------------------------------
lp:~alisonken1/openlp/bug-1593883-projector-authentication (revision 2684)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/1629/
[SUCCESS] https...

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    S_COOLDOWN, PJLINK_POWR_STATUS
31
31
 
32
32
from tests.functional import patch
33
 
from tests.resources.projector.data import TEST_PIN, TEST_SALT, TEST_CONNECT_AUTHENTICATE
 
33
from tests.resources.projector.data import TEST_PIN, TEST_SALT, TEST_CONNECT_AUTHENTICATE, TEST_HASH
34
34
 
35
35
pjlink_test = PJLink1(name='test', ip='127.0.0.1', pin=TEST_PIN, no_poll=True)
36
36
 
332
332
        self.assertFalse(pjlink.send_busy, 'Projector send_busy should be False')
333
333
        self.assertTrue(mock_timer.called, 'Projector timer.stop()  should have been called')
334
334
        self.assertTrue(mock_socket_timer.called, 'Projector socket_timer.stop() should have been called')
 
335
 
 
336
    @patch.object(pjlink_test, 'send_command')
 
337
    @patch.object(pjlink_test, 'waitForReadyRead')
 
338
    @patch.object(pjlink_test, 'projectorAuthentication')
 
339
    @patch.object(pjlink_test, 'timer')
 
340
    @patch.object(pjlink_test, 'socket_timer')
 
341
    def test_bug_1593882_no_pin_authenticated_connection(self, mock_socket_timer,
 
342
                                                         mock_timer,
 
343
                                                         mock_authentication,
 
344
                                                         mock_ready_read,
 
345
                                                         mock_send_command):
 
346
        """
 
347
        Test bug 1593882 no pin and authenticated request exception
 
348
        """
 
349
        # GIVEN: Test object and mocks
 
350
        pjlink = pjlink_test
 
351
        pjlink.pin = None
 
352
        mock_ready_read.return_value = True
 
353
 
 
354
        # WHEN: call with authentication request and pin not set
 
355
        pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
 
356
 
 
357
        # THEN: No Authentication signal should have been sent
 
358
        mock_authentication.emit.assert_called_with(pjlink.name)
 
359
 
 
360
    @patch.object(pjlink_test, 'waitForReadyRead')
 
361
    @patch.object(pjlink_test, 'state')
 
362
    @patch.object(pjlink_test, '_send_command')
 
363
    @patch.object(pjlink_test, 'timer')
 
364
    @patch.object(pjlink_test, 'socket_timer')
 
365
    def test_bug_1593883_pjlink_authentication(self, mock_socket_timer,
 
366
                                               mock_timer,
 
367
                                               mock_send_command,
 
368
                                               mock_state,
 
369
                                               mock_waitForReadyRead):
 
370
        """
 
371
        Test bugfix 1593883 pjlink authentication
 
372
        """
 
373
        # GIVEN: Test object and data
 
374
        pjlink = pjlink_test
 
375
        pjlink.pin = TEST_PIN
 
376
        mock_state.return_value = pjlink.ConnectedState
 
377
        mock_waitForReadyRead.return_value = True
 
378
 
 
379
        # WHEN: Athenticated connection is called
 
380
        pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
 
381
 
 
382
        # THEN: send_command should have the proper authentication
 
383
        self.assertEquals("{test}".format(test=mock_send_command.call_args),
 
384
                          "call(data='{hash}%1CLSS ?\\r')".format(hash=TEST_HASH))