Skip to content

Commit

Permalink
Make LICENSE file as required in plugin package
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix committed Nov 16, 2023
1 parent 2057611 commit 8d06194
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions qgis-app/plugins/tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
)
Binary file not shown.
Binary file modified qgis-app/plugins/tests/testfiles/valid_metadata_link.zip
Binary file not shown.
Binary file modified qgis-app/plugins/tests/testfiles/valid_plugin.zip_
Binary file not shown.
5 changes: 5 additions & 0 deletions qgis-app/plugins/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d06194

Please sign in to comment.