diff --git a/README.md b/README.md index f0f413e..0b06a7a 100644 --- a/README.md +++ b/README.md @@ -38,16 +38,18 @@ graph TD This checks: +- [x] Is `package.xml` conform to it's schema? + [- SchemaCheck](src/ros_license_toolkit/license_checks/schema_check.py#L27) - [x] Is any license defined in `package.xml`? - [- LicenseTagExistsCheck](src/ros_license_toolkit/checks.py#L90) + [- LicenseTagExistsCheck](src/ros_license_toolkit/license_checks/license_tag_exists_check.py#L24) - [x] Has at most one license tag without a source-files declaration? - [- LicenseTagExistsCheck](src/ros_license_toolkit/checks.py#L90) + [- LicenseTagExistsCheck](src/ros_license_toolkit/license_checks/license_tag_exists_check.py#L24) - [x] Do all licenses tags follow the SPDX standard? - [- LicenseTagIsInSpdxListCheck](src/ros_license_toolkit/checks.py#L104) + [- LicenseTagIsInSpdxListCheck](src/ros_license_toolkit/license_checks/license_tag_is_spdx.py#L24) - [x] Are license texts available and correctly referenced for all declared licenses? - [- LicenseTextExistsCheck](src/ros_license_toolkit/checks.py#L123) + [- LicenseTextExistsCheck](src/ros_license_toolkit/license_checks/license_text_exists_check.py#L30) - [x] Does the code contain licenses not declared in any license tags source-file attribute (source-files="src/something/**")? - [- LicensesInCodeCheck](src/ros_license_toolkit/checks.py#L182) + [- LicensesInCodeCheck](src/ros_license_toolkit/license_checks/license_in_code_check.py#L28) ## Usage @@ -71,7 +73,7 @@ ros_license_toolkit my_ros_package ```bash $ ros_license_toolkit -h -usage: ros_license_toolkit [-h] [-c] [-v] [-q] path +usage: ros_license_toolkit [-h] [-c] [-v] [-q] [-e] [-w] path Checks ROS packages for correct license declaration. @@ -84,6 +86,11 @@ options: generate a copyright file -v, --verbose enable verbose output -q, --quiet disable most output + -e, --continue_on_error + treats all errors as warnings, i.e. will give + returncode 0 even on errors + -w, --warnings_as_error + treats all warnings as errors ``` Additionally, there is an option to ignore single files, folders and types of files. @@ -140,9 +147,9 @@ In particular, the following things will have to be done: - [x] Each LicenseTag should have SPDX id. - [x] Single license tag without file attribute and single license text should match automatically. - [x] Turn into github action. -- [ ] Evaluate runtime. If scancode-toolkit takes too long on too many cases, we will have to look for an alternative. +- [x] Evaluate runtime. If scancode-toolkit takes too long on too many cases, we will have to look for an alternative. +- [x] Error of `LicenseTagIsInSpdxListCheck` must be a warning - [ ] Idea: Create pull requests for package maintainers automatically. -- [ ] Error of `LicenseTagIsInSpdxListCheck` must be a warning ## License diff --git a/schemas/package_common.xsd b/schemas/package_common.xsd deleted file mode 100644 index afda493..0000000 --- a/schemas/package_common.xsd +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - The version number must have the form "X.Y.Z" where X, Y, and Z - are non-negative integers, and must not contain leading zeroes. - - - - - - - - - - - The description allows any content but should be limited to XHTML. - - - - - - - - - - - A valid email address must follow several complex rules - (see https://en.wikipedia.org/wiki/Email_address). - For ROS packages only a few are enforced, and not the full character set - is supported. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The version limit must have the form "X.Y.Z", "X.Y", or "X". - See documentation for VersionType for further details. - - - - - - - - - - - - - diff --git a/schemas/package_format1.xsd b/schemas/package_format1.xsd deleted file mode 100644 index b07616a..0000000 --- a/schemas/package_format1.xsd +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - Specified in REP 127 (see http://www.ros.org/reps/rep-0127.html). - - - - - - - - The package name should be unique within the ROS community. - It may differ from the folder name into which it is checked out, - but that is not recommended. - It must start with a lower-case letter and consist of only - lower-case letters, numbers and underscores. - It must not have two consecutive underscores. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/schemas/package_format2.xsd b/schemas/package_format2.xsd deleted file mode 100644 index 73cd9c1..0000000 --- a/schemas/package_format2.xsd +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - Specified in REP 140 (see http://www.ros.org/reps/rep-0140.html). - - - - - - - - The package name should be unique within the ROS community. - It may differ from the folder name into which it is checked out, - but that is not recommended. - It must start with a lower-case letter and consist of only - lower-case letters, numbers and underscores. - It must not have two consecutive underscores. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/schemas/package_format3.xsd b/schemas/package_format3.xsd deleted file mode 100644 index c09cd8e..0000000 --- a/schemas/package_format3.xsd +++ /dev/null @@ -1,113 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Specified in REP 149 (see http://www.ros.org/reps/rep-0149.html). - - - - - - - - The package name should be unique within the ROS community. - It may differ from the folder name into which it is checked out, - but that is not recommended. - It must start with a lower-case letter and consist of only - lower-case letters, numbers and underscores. - It must not have two consecutive underscores. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/ros_license_toolkit/license_checks/schema_check.py b/src/ros_license_toolkit/license_checks/schema_check.py index b4277a2..7e24b6d 100644 --- a/src/ros_license_toolkit/license_checks/schema_check.py +++ b/src/ros_license_toolkit/license_checks/schema_check.py @@ -16,7 +16,7 @@ """This Module contains SchemaCheck, which implements Check.""" -from typing import Dict, Tuple +from typing import Optional, Tuple from lxml import etree @@ -28,46 +28,59 @@ class SchemaCheck(Check): """This checks the xml scheme and returns the version number.""" def __init__(self): super().__init__() - self.xml_schemas: Dict[int, etree] = {} - for i in range(1, 4): - xml_schema_parsed = etree.parse(f'./schemas/package_format{i}.xsd') - self.xml_schemas[i] = etree.XMLSchema(xml_schema_parsed) + self.accepted_versions = [1, 2, 3] + self.validation_schema: Optional[etree.XMLSchema] = None def _check(self, package: Package): - """Checks via schema validation if the package.xml has the correct - format, dependant on the version it is in.""" - status, message = self.validate(package) + """Checks via scheme validation via self._validate. + Also considers version of pacakge.xml for validation.""" version: int = package.package_xml_format_ver - if status: - self._success(f"Detected package.xml version {version}, " - "validation of scheme successful.") + if version in self.accepted_versions: + status, message = self._validate(package) + if status: + self._success(f"Detected package.xml version {version}, " + "validation of scheme successful.") + else: + reason = f"package.xml contains errors: {message}" + self._failed(reason) else: # Temporary workaround for not implemented version 4 if version == 4: reason = "couldn't check package.xml scheme. Version 4 is " +\ "not available right now" self._warning(reason) - return - - if message != '': - reason = f"package.xml contains errors: {message}" else: reason = "package.xml does not contain correct package " +\ "format number. Please use a real version. " +\ "(e.g. )" - self._failed(reason) + self._failed(reason) - def validate(self, package: Package) -> Tuple[bool, str]: - """This is validating package.xml file from given path. - Automatically detects version number and validates - it with corresponding scheme, e.g. format 3. - If everything is correct, returns format number, else -1.""" + def _validate(self, package: Package) -> Tuple[bool, str]: + """This is validating the package.xml schema from given package. + This can only validate for format version 1, 2 or 3. Every other + version WILL FAIL. If everything is correct, returns format number, + else -1.""" version = package.package_xml_format_ver message = '' - if version in self.xml_schemas: - schema = self.xml_schemas[version] + schema = self._get_validation_schema(version) + if schema: result = schema.validate(package.parsed_package_xml) if not result: message = schema.error_log.last_error return result, message - return False, message + return False, 'Couldn\'t get schema, no validation possible.' + + def _get_validation_schema(self, version: int): + """Return validation schema for version 1, 2 or 3. If called for other + version numbers, this WILL FAIL. Version is not checked again. + Only call with version 1, 2 or 3.""" + if self.validation_schema is None: + address = 'http://download.ros.org/schema/' +\ + f'package_format{version}.xsd' + try: + schema = etree.parse(address) + self.validation_schema = etree.XMLSchema(schema) + except (AttributeError, etree.XMLSyntaxError) as error: + print(error) + print("An error encountered while getting " + address) + return self.validation_schema diff --git a/src/ros_license_toolkit/main.py b/src/ros_license_toolkit/main.py index 9bac322..11f9ab3 100644 --- a/src/ros_license_toolkit/main.py +++ b/src/ros_license_toolkit/main.py @@ -67,6 +67,13 @@ def main(args: Optional[Sequence[str]] = None) -> int: parser.add_argument( '-q', '--quiet', dest='quiet', action='store_true', default=False, help='disable most output') + parser.add_argument( + '-e', '--continue_on_error', action='store_true', + default=False, help='treats all errors as warnings, i.e. will give ' + + 'returncode 0 even on errors') + parser.add_argument( + '-w', '--warnings_as_error', action='store_true', + default=False, help='treats all warnings as errors') parsed_args = parser.parse_args(args) # Determine the verbosity level @@ -118,14 +125,7 @@ def main(args: Optional[Sequence[str]] = None) -> int: rll_print(f'Execution time: {stop - start:.2f} seconds', Verbosity.QUIET) # Print the overall results - if max(results_per_package.values()) == Status.SUCCESS: - rll_print(f"All packages:\n {SUCCESS_STR}", Verbosity.QUIET) - return os.EX_OK - if max(results_per_package.values()) == Status.WARNING: - rll_print(f"All packages:\n {WARNING_STR}", Verbosity.QUIET) - return os.EX_OK - rll_print(f"All packages:\n {FAILURE_STR}", Verbosity.QUIET) - return os.EX_DATAERR + return print_results(results_per_package, rll_print, parsed_args) def generate_copyright_file(packages, rll_print): @@ -144,6 +144,28 @@ def generate_copyright_file(packages, rll_print): Verbosity.QUIET) +def print_results(result, rll_print, args): + """Printing the result of package""" + if max(result.values()) == Status.SUCCESS: + rll_print(f"All packages:\n {SUCCESS_STR}", Verbosity.QUIET) + return os.EX_OK + + if max(result.values()) == Status.WARNING: + if args.warnings_as_error: + rll_print(f"All packages:\n {FAILURE_STR} " + + "(Treating warnings as failure)", Verbosity.QUIET) + return os.EX_DATAERR + rll_print(f"All packages:\n {WARNING_STR}", Verbosity.QUIET) + return os.EX_OK + + if args.continue_on_error: # Error is Warning, still displayed red + rll_print(f"All packages:\n {WARNING_STR} " + + "(Treating errors as warnings)", Verbosity.QUIET) + return os.EX_OK + rll_print(f"All packages:\n {FAILURE_STR}", Verbosity.QUIET) + return os.EX_DATAERR + + def process_one_pkg(rll_print, package): """Perform checks on one package, print results and return them.""" results_per_package = {} diff --git a/test/_test_data/test_pkg_both_tags_not_spdx_one_file_own/package.xml b/test/_test_data/test_pkg_both_tags_not_spdx_one_file_own/package.xml index 1bdc20b..ce42499 100644 --- a/test/_test_data/test_pkg_both_tags_not_spdx_one_file_own/package.xml +++ b/test/_test_data/test_pkg_both_tags_not_spdx_one_file_own/package.xml @@ -1,6 +1,6 @@ - - + + test_pkg_both_tags_not_spdx_one_file_own 3.2.1 very suggestive description diff --git a/test/_test_data/test_pkg_has_code_of_different_license_and_wrong_tag/package.xml b/test/_test_data/test_pkg_has_code_of_different_license_and_wrong_tag/package.xml index 8b48738..683c8bf 100644 --- a/test/_test_data/test_pkg_has_code_of_different_license_and_wrong_tag/package.xml +++ b/test/_test_data/test_pkg_has_code_of_different_license_and_wrong_tag/package.xml @@ -1,6 +1,6 @@ - - + + test_pkg_has_code_of_different_license_and_wrong_tag 3.2.1 very suggestive description diff --git a/test/_test_data/test_pkg_one_correct_one_license_file_missing/package.xml b/test/_test_data/test_pkg_one_correct_one_license_file_missing/package.xml index 1d7200c..ff0a4f2 100644 --- a/test/_test_data/test_pkg_one_correct_one_license_file_missing/package.xml +++ b/test/_test_data/test_pkg_one_correct_one_license_file_missing/package.xml @@ -1,6 +1,6 @@ - - + + test_pkg_one_correct_one_license_file_missing 8.4.2 even more suggestive description diff --git a/test/_test_data/test_pkg_scheme1_conform/LICENSE b/test/_test_data/test_pkg_scheme1_conform/LICENSE new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/test/_test_data/test_pkg_scheme1_conform/LICENSE @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/test/_test_data/test_pkg_scheme1_conform/package.xml b/test/_test_data/test_pkg_scheme1_conform/package.xml new file mode 100644 index 0000000..7daf9c0 --- /dev/null +++ b/test/_test_data/test_pkg_scheme1_conform/package.xml @@ -0,0 +1,9 @@ + + + + my_very_own_package1 + 19.5.12 + very descriptive text + + Apache-2.0 + \ No newline at end of file diff --git a/test/_test_data/test_pkg_scheme1_violation/LICENSE b/test/_test_data/test_pkg_scheme1_violation/LICENSE new file mode 100644 index 0000000..6101579 --- /dev/null +++ b/test/_test_data/test_pkg_scheme1_violation/LICENSE @@ -0,0 +1,63 @@ +The licenses for most data are designed to take away your freedom to share and change it. By contrast, this License is intended to guarantee your freedom to share and change free data--to make sure the data are free for all their users. + +This License, the Lesser General Public License for Linguistic Resources, applies to some specially designated linguistic resources -- typically lexicons and grammars. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any Linguistic Resource which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License for Linguistic Resources (also called "this License"). Each licensee is addressed as "you". +A "linguistic resource" means a collection of data about language prepared so as to be used with application programs. + +The "Linguistic Resource", below, refers to any such work which has been distributed under these terms. A "work based on the Linguistic Resource" means either the Linguistic Resource or any derivative work under copyright law: that is to say, a work containing the Linguistic Resource or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) + +"Legible form" for a linguistic resource means the preferred form of the resource for making modifications to it. + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Linguistic Resource is not restricted, and output from such a program is covered only if its contents constitute a work based on the Linguistic Resource (independent of the use of the Linguistic Resource in a tool for writing it). Whether that is true depends on what the program that uses the Linguistic Resource does. + +1. You may copy and distribute verbatim copies of the Linguistic Resource as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Linguistic Resource. +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Linguistic Resource or any portion of it, thus forming a work based on the Linguistic Resource, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: +a) The modified work must itself be a linguistic resource. +b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. +c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Linguistic Resource, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Linguistic Resource, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Linguistic Resource. + +In addition, mere aggregation of another work not based on the Linguistic Resource with the Linguistic Resource (or with a work based on the Linguistic Resource) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. A program that contains no derivative of any portion of the Linguistic Resource, but is designed to work with the Linguistic Resource (or an encrypted form of the Linguistic Resource) by reading it or being compiled or linked with it, is called a "work that uses the Linguistic Resource". Such a work, in isolation, is not a derivative work of the Linguistic Resource, and therefore falls outside the scope of this License. +However, combining a "work that uses the Linguistic Resource" with the Linguistic Resource (or an encrypted form of the Linguistic Resource) creates a package that is a derivative of the Linguistic Resource (because it contains portions of the Linguistic Resource), rather than a "work that uses the Linguistic Resource". If the package is a derivative of the Linguistic Resource, you may distribute the package under the terms of Section 4. Any works containing that package also fall under Section 4. + +4. As an exception to the Sections above, you may also combine a "work that uses the Linguistic Resource" with the Linguistic Resource (or an encrypted form of the Linguistic Resource) to produce a package containing portions of the Linguistic Resource, and distribute that package under terms of your choice, provided that the terms permit modification of the package for the customer's own use and reverse engineering for debugging such modifications. +You must give prominent notice with each copy of the package that the Linguistic Resource is used in it and that the Linguistic Resource and its use are covered by this License. You must supply a copy of this License. If the package during execution displays copyright notices, you must include the copyright notice for the Linguistic Resource among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: + +a) Accompany the package with the complete corresponding machine-readable legible form of the Linguistic Resource including whatever changes were used in the package (which must be distributed under Sections 1 and 2 above); and, if the package contains an encrypted form of the Linguistic Resource, with the complete machine-readable "work that uses the Linguistic Resource", as object code and/or source code, so that the user can modify the Linguistic Resource and then encrypt it to produce a modified package containing the modified Linguistic Resource. +b) Use a suitable mechanism for combining with the Linguistic Resource. A suitable mechanism is one that will operate properly with a modified version of the Linguistic Resource, if the user installs one, as long as the modified version is interface-compatible with the version that the package was made with. +c) Accompany the package with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 4a, above, for a charge no more than the cost of performing this distribution. +d) If distribution of the package is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. +e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. +If the package includes an encrypted form of the Linguistic Resource, the required form of the "work that uses the Linguistic Resource" must include any data and utility programs needed for reproducing the package from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +It may happen that this requirement contradicts the license restrictions of proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Linguistic Resource together in a package that you distribute. + +5. You may not copy, modify, sublicense, link with, or distribute the Linguistic Resource except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Linguistic Resource is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. +6. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Linguistic Resource or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Linguistic Resource (or any work based on the Linguistic Resource), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Linguistic Resource or works based on it. +7. Each time you redistribute the Linguistic Resource (or any work based on the Linguistic Resource), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Linguistic Resource subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. +8. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Linguistic Resource at all. For example, if a patent license would not permit royalty-free redistribution of the Linguistic Resource by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Linguistic Resource. +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free resource distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of data distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute resources through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +9. If the distribution and/or use of the Linguistic Resource is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Linguistic Resource under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. +10. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License for Linguistic Resources from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. +Each version is given a distinguishing version number. If the Linguistic Resource specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Linguistic Resource does not specify a license version number, you may choose any version ever published by the Free Software Foundation. + +11. If you wish to incorporate parts of the Linguistic Resource into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. +NO WARRANTY + +12. BECAUSE THE LINGUISTIC RESOURCE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LINGUISTIC RESOURCE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LINGUISTIC RESOURCE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LINGUISTIC RESOURCE IS WITH YOU. SHOULD THE LINGUISTIC RESOURCE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. +13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LINGUISTIC RESOURCE AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LINGUISTIC RESOURCE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LINGUISTIC RESOURCE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/test/_test_data/test_pkg_scheme1_violation/package.xml b/test/_test_data/test_pkg_scheme1_violation/package.xml new file mode 100644 index 0000000..b4cdb62 --- /dev/null +++ b/test/_test_data/test_pkg_scheme1_violation/package.xml @@ -0,0 +1,8 @@ + + + + my_very_own_package2 + 19.5.12 + very descriptive text + LGPLLR + \ No newline at end of file diff --git a/test/_test_data/test_pkg_scheme2_conform/LICENSE b/test/_test_data/test_pkg_scheme2_conform/LICENSE new file mode 100644 index 0000000..d97fba8 --- /dev/null +++ b/test/_test_data/test_pkg_scheme2_conform/LICENSE @@ -0,0 +1,11 @@ +Copyright 1995 Foo Bar + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/test/_test_data/test_pkg_scheme2_conform/package.xml b/test/_test_data/test_pkg_scheme2_conform/package.xml new file mode 100644 index 0000000..0c95ed9 --- /dev/null +++ b/test/_test_data/test_pkg_scheme2_conform/package.xml @@ -0,0 +1,10 @@ + + + + some_name + 1.6.3 + Some text to describe package + + BSD-3-Clause + dependence + \ No newline at end of file diff --git a/test/_test_data/test_pkg_scheme2_violation/LICENSE b/test/_test_data/test_pkg_scheme2_violation/LICENSE new file mode 100644 index 0000000..c407ef9 --- /dev/null +++ b/test/_test_data/test_pkg_scheme2_violation/LICENSE @@ -0,0 +1,14 @@ +Redistribution and use of this software and associated documentation ("Software"), with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions in source form must retain copyright statements and notices, +2. Redistributions in binary form must reproduce applicable copyright statements and notices, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution, and +3. Redistributions must contain a verbatim copy of this document. +The OpenLDAP Foundation may revise this license from time to time. Each revision is distinguished by a version number. You may use this Software under terms of this license revision or under the terms of any subsequent revision of the license. + +THIS SOFTWARE IS PROVIDED BY THE OPENLDAP FOUNDATION AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENLDAP FOUNDATION, ITS CONTRIBUTORS, OR THE AUTHOR(S) OR OWNER(S) OF THE SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The names of the authors and copyright holders must not be used in advertising or otherwise to promote the sale, use or other dealing in this Software without specific, written prior permission. Title to copyright in this Software shall at all times remain with copyright holders. + +OpenLDAP is a registered trademark of the OpenLDAP Foundation. + +Copyright 1999-2003 The OpenLDAP Foundation, Redwood City, California, USA. All Rights Reserved. Permission to copy and distribute verbatim copies of this document is granted. \ No newline at end of file diff --git a/test/_test_data/test_pkg_scheme2_violation/package.xml b/test/_test_data/test_pkg_scheme2_violation/package.xml new file mode 100644 index 0000000..9aab9e2 --- /dev/null +++ b/test/_test_data/test_pkg_scheme2_violation/package.xml @@ -0,0 +1,9 @@ + + + + fancy_faulty_package + 6.3 + Some text to describe package + + OLDAP-2.8 + \ No newline at end of file diff --git a/test/_test_data/test_pkg_scheme3_conform/package.xml b/test/_test_data/test_pkg_scheme3_conform/package.xml index 86f0f3d..8f87d66 100644 --- a/test/_test_data/test_pkg_scheme3_conform/package.xml +++ b/test/_test_data/test_pkg_scheme3_conform/package.xml @@ -7,4 +7,5 @@ AFL-2.0 + group diff --git a/test/_test_data/test_pkg_scheme3_violation/LICENSE b/test/_test_data/test_pkg_scheme3_violation/LICENSE new file mode 100644 index 0000000..dc6d227 --- /dev/null +++ b/test/_test_data/test_pkg_scheme3_violation/LICENSE @@ -0,0 +1,14 @@ +This software is Copyright (c) NAUMEN (tm) and Contributors. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions in source code must retain the above copyright notice, this list of conditions, and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution. +3. The name NAUMEN (tm) must not be used to endorse or promote products derived from this software without prior written permission from NAUMEN. +4. The right to distribute this software or to use it for any purpose does not give you the right to use Servicemarks (sm) or Trademarks (tm) of NAUMEN. +5. If any files originating from NAUMEN or Contributors are modified, you must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. +Disclaimer: + +THIS SOFTWARE IS PROVIDED BY NAUMEN "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NAUMEN OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +This software consists of contributions made by NAUMEN and Contributors. Specific attributions are listed in the accompanying credits file. \ No newline at end of file diff --git a/test/_test_data/test_pkg_scheme3_violation/package.xml b/test/_test_data/test_pkg_scheme3_violation/package.xml new file mode 100644 index 0000000..2132cf7 --- /dev/null +++ b/test/_test_data/test_pkg_scheme3_violation/package.xml @@ -0,0 +1,9 @@ + + + + faulty_format_3_test wrong + 6.12.24 + description + + Naumen + diff --git a/test/systemtest/test_all_packages.py b/test/systemtest/test_all_packages.py index 97824e4..66b231d 100644 --- a/test/systemtest/test_all_packages.py +++ b/test/systemtest/test_all_packages.py @@ -56,7 +56,12 @@ def test_all(self): self.assertIn(b"test_pkg_no_license", stdout) self.assertIn(b"test_pkg_no_license_file", stdout) self.assertIn(b"test_pkg_one_correct_one_license_file_missing", stdout) + self.assertIn(b"test_pkg_scheme1_conform", stdout) + self.assertIn(b"test_pkg_scheme1_violation", stdout) + self.assertIn(b"test_pkg_scheme2_conform", stdout) + self.assertIn(b"test_pkg_scheme2_violation", stdout) self.assertIn(b"test_pkg_scheme3_conform", stdout) + self.assertIn(b"test_pkg_scheme3_violation", stdout) self.assertIn(b"test_pkg_spdx_tag", stdout) self.assertIn(b"test_pkg_too_many_license_files", stdout) self.assertIn(b"test_pkg_tag_not_spdx", stdout) diff --git a/test/systemtest/test_separate_pkgs.py b/test/systemtest/test_separate_pkgs.py index 7d8fa9f..7e12592 100644 --- a/test/systemtest/test_separate_pkgs.py +++ b/test/systemtest/test_separate_pkgs.py @@ -62,7 +62,7 @@ def test_pkg_both_tags_not_spdx(self): process, stdout = open_subprocess("test_pkg_both_tags_not_spdx") self.assertEqual(os.EX_OK, process.returncode) self.assertTrue(check_output_status( - stdout, SUCCESS, WARNING, WARNING, WARNING, WARNING)) + stdout, WARNING, SUCCESS, WARNING, WARNING, WARNING, WARNING)) def test_pkg_both_tags_not_spdx_one_file_own(self): """Test on a package that has two licenses. One is self-defined, other @@ -71,7 +71,7 @@ def test_pkg_both_tags_not_spdx_one_file_own(self): "test_pkg_both_tags_not_spdx_one_file_own") self.assertEqual(os.EX_DATAERR, process.returncode) self.assertTrue(check_output_status( - stdout, SUCCESS, WARNING, FAILURE, WARNING, WARNING)) + stdout, WARNING, SUCCESS, WARNING, FAILURE, WARNING, WARNING)) def test_pkg_code_has_no_license(self): """Test on a package that has a correct package.xml with a license @@ -86,7 +86,8 @@ def test_pkg_has_code_disjoint(self): a license different from the package main license.""" process, stdout = open_subprocess("test_pkg_has_code_disjoint") self.assertEqual(os.EX_OK, process.returncode) - self.assertTrue(check_output_status(stdout)) + self.assertTrue(check_output_status(stdout, + exp_schema_validated=WARNING)) def test_pkg_has_code_of_different_license(self): """Test on a package with source files under a license different @@ -104,7 +105,8 @@ def test_pkg_has_code_of_different_license_and_tag(self): process, stdout = open_subprocess( "test_pkg_has_code_of_different_license_and_tag") self.assertEqual(os.EX_OK, process.returncode) - self.assertTrue(check_output_status(stdout)) + self.assertTrue(check_output_status(stdout, + exp_schema_validated=WARNING)) def test_pkg_has_code_of_different_license_and_wrong_tag(self): """Test on a package with source files under a license different @@ -114,14 +116,16 @@ def test_pkg_has_code_of_different_license_and_wrong_tag(self): "test_pkg_has_code_of_different_license_and_wrong_tag") self.assertEqual(os.EX_DATAERR, process.returncode) self.assertTrue(check_output_status( - stdout, exp_lic_text_exits=FAILURE, exp_lic_in_code=FAILURE)) + stdout, exp_schema_validated=WARNING, exp_lic_text_exits=FAILURE, + exp_lic_in_code=FAILURE)) def test_pkg_ignore_readme_contents(self): """Test on a package with readme files. READMEs mention licenses that are not in package and shall therefore be ignored.""" process, stdout = open_subprocess("test_pkg_ignore_readme_contents") self.assertEqual(os.EX_OK, process.returncode) - self.assertTrue(check_output_status(stdout)) + self.assertTrue(check_output_status(stdout, + exp_schema_validated=WARNING)) def test_pkg_name_not_in_spdx(self): """Test on a package that has valid License file with BSD-3-Clause @@ -129,7 +133,7 @@ def test_pkg_name_not_in_spdx(self): process, stdout = open_subprocess("test_pkg_name_not_in_spdx") self.assertEqual(os.EX_OK, process.returncode) self.assertTrue(check_output_status( - stdout, SUCCESS, WARNING, WARNING, SUCCESS, WARNING)) + stdout, SUCCESS, SUCCESS, WARNING, WARNING, SUCCESS, WARNING)) def test_pkg_no_file_attribute(self): """Test on a package with License file that is not referenced in @@ -143,7 +147,7 @@ def test_pkg_no_license(self): process, stdout = open_subprocess("test_pkg_no_license") self.assertEqual(os.EX_DATAERR, process.returncode) self.assertTrue(check_output_status( - stdout, FAILURE, SUCCESS, FAILURE, FAILURE, SUCCESS)) + stdout, FAILURE, FAILURE, SUCCESS, FAILURE, FAILURE, SUCCESS)) def test_pkg_no_license_file(self): """Test on a package with no license text file.""" @@ -159,7 +163,37 @@ def test_pkg_one_correct_one_license_file_missing(self): "test_pkg_one_correct_one_license_file_missing") self.assertEqual(os.EX_DATAERR, process.returncode) self.assertTrue(check_output_status( - stdout, SUCCESS, WARNING, FAILURE, FAILURE, SUCCESS)) + stdout, WARNING, SUCCESS, WARNING, FAILURE, FAILURE, SUCCESS)) + + def test_pkg_scheme1_conform(self): + """Test on a package that has all attributes for being conform to + the official scheme v1""" + process, stdout = open_subprocess("test_pkg_scheme1_conform") + self.assertEqual(os.EX_OK, process.returncode) + self.assertTrue(check_output_status(stdout)) + + def test_pkg_scheme1_violation(self): + """Test on a package that has all attributes except for maintainer, + and therefor not conform to the official scheme v1.""" + process, stdout = open_subprocess("test_pkg_scheme1_violation") + self.assertEqual(os.EX_DATAERR, process.returncode) + self.assertTrue(check_output_status(stdout, + exp_schema_validated=FAILURE)) + + def test_pkg_scheme2_conform(self): + """Test on a package that has all attributes for being conform to + the official scheme v2""" + process, stdout = open_subprocess("test_pkg_scheme2_conform") + self.assertEqual(os.EX_OK, process.returncode) + self.assertTrue(check_output_status(stdout)) + + def test_pkg_scheme2_violation(self): + """Test on a package that has all attributes except the wrong version + format being conform to the official scheme v2""" + process, stdout = open_subprocess("test_pkg_scheme2_violation") + self.assertEqual(os.EX_DATAERR, process.returncode) + self.assertTrue(check_output_status(stdout, + exp_schema_validated=FAILURE)) def test_pkg_scheme3_conform(self): """Test on a package that has all attributes for being conform to @@ -168,6 +202,14 @@ def test_pkg_scheme3_conform(self): self.assertEqual(os.EX_OK, process.returncode) self.assertTrue(check_output_status(stdout)) + def test_pkg_scheme3_violation(self): + """Test on a package that has all attributes except faulty name format + for being conform to the official scheme v3.""" + process, stdout = open_subprocess("test_pkg_scheme3_violation") + self.assertEqual(os.EX_DATAERR, process.returncode) + self.assertTrue(check_output_status(stdout, + exp_schema_validated=FAILURE)) + def test_pkg_spdx_tag(self): """Test on a package with a license declared in the package.xml with the SPDX tag.""" @@ -192,7 +234,7 @@ def test_pkg_tag_not_spdx(self): process, stdout = open_subprocess("test_pkg_tag_not_spdx") self.assertEqual(os.EX_OK, process.returncode) self.assertTrue(check_output_status( - stdout, SUCCESS, WARNING, WARNING, WARNING, WARNING)) + stdout, SUCCESS, SUCCESS, WARNING, WARNING, WARNING, WARNING)) def test_pkg_unknown_license(self): """Test on a package with an unknown license declared in the @@ -236,7 +278,7 @@ def test_pkg_with_multiple_licenses_one_referenced_incorrect(self): self.assertEqual(os.EX_OK, process.returncode) self.assertIn(b"WARNING Licenses ['BSD'] are not in SPDX list", stdout) self.assertTrue(check_output_status( - stdout, SUCCESS, WARNING, WARNING, WARNING, WARNING)) + stdout, WARNING, SUCCESS, WARNING, WARNING, WARNING, WARNING)) def test_pkg_wrong_license_file(self): """Test on a package with a license text file that does not match @@ -261,6 +303,7 @@ def open_subprocess(test_data_name: str): def check_output_status(output: str, + exp_schema_validated: Status = Status.SUCCESS, exp_lic_tag_exists: Status = Status.SUCCESS, exp_lic_tag_spdx: Status = Status.SUCCESS, exp_lic_text_exits: Status = Status.SUCCESS, @@ -272,6 +315,7 @@ def check_output_status(output: str, certain check. The default is always SUCCESS.""" # pylint: disable=too-many-arguments + real_lic_validated = get_test_result(output, "SchemaCheck") real_lic_tag_exists = get_test_result(output, "LicenseTagExistsCheck") real_lic_tag_spdx = get_test_result(output, "LicenseTagIsInSpdxListCheck") real_lic_text_exits = get_test_result(output, "LicenseTextExistsCheck") @@ -279,7 +323,8 @@ def check_output_status(output: str, real_lic_files_referenced = get_test_result( output, "LicenseFilesReferencedCheck") - return exp_lic_tag_exists == real_lic_tag_exists \ + return exp_schema_validated == real_lic_validated \ + and exp_lic_tag_exists == real_lic_tag_exists \ and exp_lic_tag_spdx == real_lic_tag_spdx \ and exp_lic_text_exits == real_lic_text_exits \ and exp_lic_in_code == real_lic_in_code \