Change trusted scripts path from resources to plugin/scripts

CURA-7319
This commit is contained in:
Nino van Hooff 2020-03-25 16:51:21 +01:00
parent 6bf00d7ea1
commit 92f278acc8
2 changed files with 14 additions and 5 deletions

View file

@ -348,7 +348,9 @@ class PostProcessingPlugin(QObject, Extension):
# No signature needed # No signature needed
return True return True
if os.path.split(file_path) == os.path.join(Resources.getStoragePath(Resources.Resources), "scripts"): if os.path.split(file_path)[0] == os.path.join(
PluginRegistry.getInstance().getPluginPath("PostProcessingPlugin"),
"scripts"):
# Bundled scripts are trusted. # Bundled scripts are trusted.
return True return True

View file

@ -3,6 +3,7 @@ import os
import sys import sys
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock
from UM.PluginRegistry import PluginRegistry
from UM.Resources import Resources from UM.Resources import Resources
from UM.Trust import Trust from UM.Trust import Trust
from ..PostProcessingPlugin import PostProcessingPlugin from ..PostProcessingPlugin import PostProcessingPlugin
@ -12,6 +13,9 @@ sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
""" In this file, commnunity refers to regular Cura for makers.""" """ In this file, commnunity refers to regular Cura for makers."""
mock_plugin_registry = MagicMock()
mock_plugin_registry.getPluginPath = MagicMock(return_value = "mocked_plugin_path")
# noinspection PyProtectedMember # noinspection PyProtectedMember
@patch("cura.ApplicationMetadata.IsEnterpriseVersion", False) @patch("cura.ApplicationMetadata.IsEnterpriseVersion", False)
@ -27,19 +31,22 @@ def test_community_bundled_script_allowed():
# noinspection PyProtectedMember # noinspection PyProtectedMember
@patch("cura.ApplicationMetadata.IsEnterpriseVersion", True) @patch("cura.ApplicationMetadata.IsEnterpriseVersion", True)
def test_enterprise_unsigned_user_script_not_allowed(): @patch.object(PluginRegistry, "getInstance", return_value=mock_plugin_registry)
def test_enterprise_unsigned_user_script_not_allowed(plugin_registry):
assert not PostProcessingPlugin._isScriptAllowed("blaat.py") assert not PostProcessingPlugin._isScriptAllowed("blaat.py")
# noinspection PyProtectedMember # noinspection PyProtectedMember
@patch("cura.ApplicationMetadata.IsEnterpriseVersion", True) @patch("cura.ApplicationMetadata.IsEnterpriseVersion", True)
def test_enterprise_signed_user_script_allowed(): @patch.object(PluginRegistry, "getInstance", return_value=mock_plugin_registry)
def test_enterprise_signed_user_script_allowed(plugin_registry):
mocked_trust = MagicMock() mocked_trust = MagicMock()
mocked_trust.signedFileCheck = MagicMock(return_value=True) mocked_trust.signedFileCheck = MagicMock(return_value=True)
plugin_registry.getPluginPath = MagicMock(return_value="mocked_plugin_path")
with patch.object(Trust, "signatureFileExistsFor", return_value = True): with patch.object(Trust, "signatureFileExistsFor", return_value = True):
with patch("UM.Trust.Trust.getInstanceOrNone", return_value=mocked_trust): with patch("UM.Trust.Trust.getInstanceOrNone", return_value=mocked_trust):
assert PostProcessingPlugin._isScriptAllowed("blaat.py") assert PostProcessingPlugin._isScriptAllowed("mocked_plugin_path/scripts/blaat.py")
# noinspection PyProtectedMember # noinspection PyProtectedMember