Skip to content

Commit

Permalink
Make LICENSE file as required in plugin package (#309)
Browse files Browse the repository at this point in the history
* Make LICENSE file as required in plugin package

* Update qgis-app/plugins/validator.py

---------

Co-authored-by: Dimas Ciputra <[email protected]>
  • Loading branch information
Xpirix and dimasciput authored Nov 20, 2023
1 parent 3ea515d commit 91b9576
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 91b9576

Please sign in to comment.