diff options
| author | Trevor Gamblin <tgamblin@baylibre.com> | 2023-09-13 13:00:46 -0400 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-09-14 15:20:08 +0100 |
| commit | 4a6f38c5327b40a45c340af49fee9a0d5cc890bd (patch) | |
| tree | 669ae555ecc031990579baa207d40f38ab7e1335 /meta/lib/patchtest/tests/test_patch_cve.py | |
| parent | e12e6d94ecbea6e0dafc080f2f196e12228730eb (diff) | |
| download | poky-4a6f38c5327b40a45c340af49fee9a0d5cc890bd.tar.gz | |
patchtest: Add tests from patchtest oe repo
Copy the core components of the patchtest-oe repo into
meta/lib/patchtest in oe-core.
(From OE-Core rev: 257f64f4e4414b78981104aec132b067beb5a92a)
Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/patchtest/tests/test_patch_cve.py')
| -rw-r--r-- | meta/lib/patchtest/tests/test_patch_cve.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/meta/lib/patchtest/tests/test_patch_cve.py b/meta/lib/patchtest/tests/test_patch_cve.py new file mode 100644 index 0000000000..46ed9ef791 --- /dev/null +++ b/meta/lib/patchtest/tests/test_patch_cve.py | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | # Checks related to the patch's CVE lines | ||
| 2 | # | ||
| 3 | # Copyright (C) 2016 Intel Corporation | ||
| 4 | # | ||
| 5 | # This program is free software; you can redistribute it and/or modify | ||
| 6 | # it under the terms of the GNU General Public License version 2 as | ||
| 7 | # published by the Free Software Foundation. | ||
| 8 | # | ||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 17 | |||
| 18 | # SPDX-License-Identifier: GPL-2.0-or-later | ||
| 19 | |||
| 20 | import base | ||
| 21 | import os | ||
| 22 | import re | ||
| 23 | |||
| 24 | class CVE(base.Base): | ||
| 25 | |||
| 26 | re_cve_pattern = re.compile("CVE\-\d{4}\-\d+", re.IGNORECASE) | ||
| 27 | re_cve_payload_tag = re.compile("\+CVE:(\s+CVE\-\d{4}\-\d+)+") | ||
| 28 | |||
| 29 | def setUp(self): | ||
| 30 | if self.unidiff_parse_error: | ||
| 31 | self.skip('Parse error %s' % self.unidiff_parse_error) | ||
| 32 | |||
| 33 | # we are just interested in series that introduce CVE patches, thus discard other | ||
| 34 | # possibilities: modification to current CVEs, patch directly introduced into the | ||
| 35 | # recipe, upgrades already including the CVE, etc. | ||
| 36 | new_cves = [p for p in self.patchset if p.path.endswith('.patch') and p.is_added_file] | ||
| 37 | if not new_cves: | ||
| 38 | self.skip('No new CVE patches introduced') | ||
| 39 | |||
| 40 | def test_cve_tag_format(self): | ||
| 41 | for commit in CVE.commits: | ||
| 42 | if self.re_cve_pattern.search(commit.shortlog) or self.re_cve_pattern.search(commit.commit_message): | ||
| 43 | tag_found = False | ||
| 44 | for line in commit.payload.splitlines(): | ||
| 45 | if self.re_cve_payload_tag.match(line): | ||
| 46 | tag_found = True | ||
| 47 | break | ||
| 48 | if not tag_found: | ||
| 49 | self.fail('Missing or incorrectly formatted CVE tag in included patch file', | ||
| 50 | 'Correct or include the CVE tag on cve patch with format: "CVE: CVE-YYYY-XXXX"', | ||
| 51 | commit) | ||
