diff options
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) | ||