diff --git a/qgis-app/plugins/tests/test_validator.py b/qgis-app/plugins/tests/test_validator.py index 54fe0b2c..13d5af3a 100644 --- a/qgis-app/plugins/tests/test_validator.py +++ b/qgis-app/plugins/tests/test_validator.py @@ -193,3 +193,28 @@ def test_zipfile_with_gitignore(self, mock_namelist): exception.message, "For security reasons, zip file cannot contain '.git' directory", ) + + +class TestLicenseValidator(TestCase): + """Test if zipfile contains LICENSE file """ + + def setUp(self) -> None: + plugin_without_license = os.path.join(TESTFILE_DIR, "plugin_without_license.zip_") + self.invalid_plugin = open(plugin_without_license, "rb") + + def tearDown(self): + self.invalid_plugin.close() + + def test_zipfile_without_license(self): + self.assertRaises( + ValidationError, + validator, + InMemoryUploadedFile( + self.invalid_plugin, + field_name="tempfile", + name="testfile.zip", + content_type="application/zip", + size=39889, + charset="utf8", + ), + ) \ No newline at end of file diff --git a/qgis-app/plugins/tests/testfiles/plugin_without_license.zip_ b/qgis-app/plugins/tests/testfiles/plugin_without_license.zip_ new file mode 100644 index 00000000..1f93a041 Binary files /dev/null and b/qgis-app/plugins/tests/testfiles/plugin_without_license.zip_ differ diff --git a/qgis-app/plugins/tests/testfiles/valid_metadata_link.zip b/qgis-app/plugins/tests/testfiles/valid_metadata_link.zip index d16c9453..94ca6c67 100644 Binary files a/qgis-app/plugins/tests/testfiles/valid_metadata_link.zip and b/qgis-app/plugins/tests/testfiles/valid_metadata_link.zip differ diff --git a/qgis-app/plugins/tests/testfiles/valid_plugin.zip_ b/qgis-app/plugins/tests/testfiles/valid_plugin.zip_ index 1f93a041..82210e33 100644 Binary files a/qgis-app/plugins/tests/testfiles/valid_plugin.zip_ and b/qgis-app/plugins/tests/testfiles/valid_plugin.zip_ differ diff --git a/qgis-app/plugins/validator.py b/qgis-app/plugins/validator.py index 6dbfd9a9..925e0b0c 100644 --- a/qgis-app/plugins/validator.py +++ b/qgis-app/plugins/validator.py @@ -237,6 +237,11 @@ def validator(package): if initname not in namelist: raise ValidationError(_("Cannot find __init__.py in plugin package.")) + # Checks for LICENCE file precense + licensename = package_name+"/LICENSE" + if licensename not in namelist: + raise ValidationError(_("Cannot find LICENSE in plugin package.")) + # Checks metadata metadata = [] # First parse metadata.txt