From cef0e67bd217838475e57af994b5562eba3af8ec Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 30 Oct 2019 17:33:07 +0000 Subject: [PATCH] Allow x11 override --- openlp/core/display/window.py | 6 +- .../openlp_core/api/http/test_init.py | 17 +++++ .../openlp_core/display/test_window.py | 72 +++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/functional/openlp_core/display/test_window.py diff --git a/openlp/core/display/window.py b/openlp/core/display/window.py index 08ac190b1..52c1a8fc3 100644 --- a/openlp/core/display/window.py +++ b/openlp/core/display/window.py @@ -109,13 +109,17 @@ class DisplayWindow(QtWidgets.QWidget): Create the display window """ super(DisplayWindow, self).__init__(parent) + # Gather all flags for the display window + flags = QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool | QtCore.Qt.WindowStaysOnTopHint + if Settings().value('advanced/x11 bypass wm'): + flags |= QtCore.Qt.X11BypassWindowManagerHint # Need to import this inline to get around a QtWebEngine issue from openlp.core.display.webengine import WebEngineView self._is_initialised = False self._can_show_startup_screen = can_show_startup_screen self._fbo = None self.setWindowTitle(translate('OpenLP.DisplayWindow', 'Display Window')) - self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool | QtCore.Qt.WindowStaysOnTopHint) + self.setWindowFlags(flags) self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setAutoFillBackground(True) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) diff --git a/tests/functional/openlp_core/api/http/test_init.py b/tests/functional/openlp_core/api/http/test_init.py index 770599a30..166ec6ef4 100644 --- a/tests/functional/openlp_core/api/http/test_init.py +++ b/tests/functional/openlp_core/api/http/test_init.py @@ -144,6 +144,23 @@ class TestInit(TestCase, TestMixin): # THEN: the result will be as expected - try again assert str(value) == 'called' + def test_requires_auth_missing_credentials(self): + """ + Test the requires_auth wrapper with enabled security and authorization taken place and and error + :return: + """ + # GIVEN: An enabled security and a known user + Settings().setValue('api/authentication enabled', True) + Settings().setValue('api/user id', 'superfly') + Settings().setValue('api/password', 'lamas') + + # WHEN: I call the function with no password + wrapped_function = requires_auth(func) + value = wrapped_function(0) + + # THEN: the result will be as expected (unauthorized) + assert str(value) == str(authenticate()) + def func(field=None): return 'called' diff --git a/tests/functional/openlp_core/display/test_window.py b/tests/functional/openlp_core/display/test_window.py new file mode 100644 index 000000000..c2c1990d0 --- /dev/null +++ b/tests/functional/openlp_core/display/test_window.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- + +########################################################################## +# OpenLP - Open Source Lyrics Projection # +# ---------------------------------------------------------------------- # +# Copyright (c) 2008-2019 OpenLP Developers # +# ---------------------------------------------------------------------- # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +########################################################################## +""" +Package to test the openlp.core.display.window package. +""" +import sys + +from unittest import TestCase +from unittest.mock import MagicMock, patch + +from PyQt5 import QtCore + +# Mock QtWebEngineWidgets +sys.modules['PyQt5.QtWebEngineWidgets'] = MagicMock() + +from openlp.core.display.window import DisplayWindow +from tests.helpers.testmixin import TestMixin +from openlp.core.common.settings import Settings + + +@patch('PyQt5.QtWidgets.QVBoxLayout') +@patch('openlp.core.display.webengine.WebEngineView') +class TestDisplayWindow(TestCase, TestMixin): + """ + A test suite to test the functions in DisplayWindow + """ + + def test_x11_override_on(self, mocked_webengine, mocked_addWidget): + """ + Test that the x11 override option bit is set + """ + # GIVEN: x11 bypass is on + Settings().setValue('advanced/x11 bypass wm', True) + + # WHEN: A DisplayWindow is generated + display_window = DisplayWindow() + + # THEN: The x11 override flag should be set + x11_bit = display_window.windowFlags() & QtCore.Qt.X11BypassWindowManagerHint + assert x11_bit == QtCore.Qt.X11BypassWindowManagerHint + + def test_x11_override_off(self, mocked_webengine, mocked_addWidget): + """ + Test that the x11 override option bit is not set when setting if off + """ + # GIVEN: x11 bypass is off + Settings().setValue('advanced/x11 bypass wm', False) + + # WHEN: A DisplayWindow is generated + display_window = DisplayWindow() + + # THEN: The x11 override flag should not be set + x11_bit = display_window.windowFlags() & QtCore.Qt.X11BypassWindowManagerHint + assert x11_bit != QtCore.Qt.X11BypassWindowManagerHint