Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make LICENSE file as required in plugin package #309

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading