1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
from pkgcheck.checks import header
from snakeoil.cli import arghparse
from .. import misc
class TestEbuildHeaderCheck(misc.ReportTestCase):
check_kls = header.EbuildHeaderCheck
def mk_check(self):
options = arghparse.Namespace(gentoo_repo=True)
return self.check_kls(options)
def mk_pkg(self, **kwargs):
return misc.FakePkg("dev-util/diffball-0.5", **kwargs)
def test_empty_file(self):
fake_pkg = self.mk_pkg(lines=())
self.assertNoReport(self.mk_check(), fake_pkg)
def test_good_copyright(self):
good_copyrights = [
"# Copyright 1999-2019 Gentoo Authors\n",
"# Copyright 2019 Gentoo Authors\n",
"# Copyright 2010-2017 Gentoo Authors\n",
]
for line in good_copyrights:
fake_src = [line, self.check_kls.license_header]
fake_pkg = self.mk_pkg(lines=fake_src)
self.assertNoReport(self.mk_check(), fake_pkg)
def test_invalid_copyright(self):
bad_copyrights = [
"# Copyright (c) 1999-2019 Gentoo Authors\n",
"# Copyright Gentoo Authors\n",
"# Gentoo Authors\n",
"# Here is entirely random text\n",
"\n",
]
for line in bad_copyrights:
fake_src = [line, self.check_kls.license_header]
fake_pkg = self.mk_pkg(lines=fake_src)
r = self.assertReport(self.mk_check(), fake_pkg)
assert isinstance(r, header.EbuildInvalidCopyright)
assert line.strip() in str(r)
def test_new_foundation_copyright(self):
"""Foundation copyright on new ebuilds triggers the report."""
bad_copyrights = [
"# Copyright 1999-2019 Gentoo Foundation\n",
"# Copyright 2019 Gentoo Foundation\n",
"# Copyright 3125 Gentoo Foundation\n",
"# Copyright 2010-2021 Gentoo Foundation\n",
]
for line in bad_copyrights:
fake_src = [line, self.check_kls.license_header]
fake_pkg = self.mk_pkg(lines=fake_src)
r = self.assertReport(self.mk_check(), fake_pkg)
assert isinstance(r, header.EbuildOldGentooCopyright)
assert line.strip() in str(r)
def test_old_foundation_copyright(self):
"""Foundation copyright on old ebuilds does not trigger false positives."""
good_copyrights = [
"# Copyright 1999-2018 Gentoo Foundation\n",
"# Copyright 2016 Gentoo Foundation\n",
"# Copyright 2010-2017 Gentoo Foundation\n",
]
for line in good_copyrights:
fake_src = [line, self.check_kls.license_header]
fake_pkg = self.mk_pkg(lines=fake_src)
self.assertNoReport(self.mk_check(), fake_pkg)
def test_non_gentoo_authors_copyright_in_gentoo(self):
"""Ebuilds in the gentoo repo must use 'Gentoo Authors'."""
bad_copyrights = [
"# Copyright 1999-2019 D. E. Veloper\n",
"# Copyright 2019 辣鸡汤\n",
]
for line in bad_copyrights:
fake_src = [line, self.check_kls.license_header]
fake_pkg = self.mk_pkg(lines=fake_src)
r = self.assertReport(self.mk_check(), fake_pkg)
assert isinstance(r, header.EbuildNonGentooAuthorsCopyright)
assert line.strip() in str(r)
def test_license_headers(self):
copyright = "# Copyright 1999-2019 Gentoo Authors\n"
fake_src = [copyright, self.check_kls.license_header]
fake_pkg = self.mk_pkg(lines=fake_src)
self.assertNoReport(self.mk_check(), fake_pkg)
bad_license_headers = [
[],
[""],
["\n"],
[f"{self.check_kls.license_header} "],
[f" {self.check_kls.license_header}"],
["# Distributed under the terms of the GNU General Public License v3"],
]
for content in bad_license_headers:
fake_src = [copyright] + content
fake_pkg = self.mk_pkg(lines=fake_src)
r = self.assertReport(self.mk_check(), fake_pkg)
assert isinstance(r, header.EbuildInvalidLicenseHeader)
expected = content[0].strip() if content else "missing license header"
assert expected in str(r)
|