Skip to content
Draft
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
13 changes: 3 additions & 10 deletions rpmlint/checks/TagsCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,16 @@ def _check_forbidden_controlchar(self, pkg):
Output info to STDOUT
"""

# Check if a package contains forbidden-controlchar in Requires: tag.
for tagname, items in (
('Provides', pkg.provides),
('Conflicts', pkg.conflicts),
('Obsoletes', pkg.obsoletes),
('Supplements', pkg.supplements),
('Suggests', pkg.suggests),
('Enhances', pkg.enhances),
('Recommends', pkg.recommends)):
('Recommends', pkg.recommends),
('Requires', pkg.requires)):
for item in items:
dep = Pkg.has_forbidden_controlchars(item)
if dep:
Expand All @@ -726,15 +728,6 @@ def _check_forbidden_controlchar(self, pkg):
value = Pkg.formatRequire(*item)
self._unexpanded_macros(pkg, f'{tagname} {value}', value)

# Check if a package contains forbidden-controlchar in Requires: tag.
for pkg_token in (pkg.requires):
dep = Pkg.has_forbidden_controlchars(pkg_token)
if dep:
self.output.add_info('E',
pkg,
'forbidden-controlchar-found',
f'Requires: {dep}')

def _check_self_obsoletion(self, pkg):
"""Trigger check self-obsoletion

Expand Down
10 changes: 10 additions & 0 deletions rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@ def __init__(self, name, is_source=False):
self.header[getattr(rpm, f'RPMTAG_{tagname}FLAGS')] = []
self.header[getattr(rpm, f'RPMTAG_{tagname}VERSION')] = []
self.header[rpm.RPMTAG_FILENAMES] = []
self.header[rpm.RPMTAG_CHANGELOGNAME] = []
self.header[rpm.RPMTAG_CHANGELOGTEXT] = []
self.header[rpm.RPMTAG_CHANGELOGTIME] = []

def add_file(self, path, name):
pkgfile = PkgFile(name)
Expand Down Expand Up @@ -968,6 +971,13 @@ def add_header(self, header):
self.header[getattr(rpm, f'RPMTAG_{tagname}VERSION')].append(version)
continue

if k == 'changelog':
for name, text, time_ in v:
self.header[rpm.RPMTAG_CHANGELOGNAME].append(name)
self.header[rpm.RPMTAG_CHANGELOGTEXT].append(text)
self.header[rpm.RPMTAG_CHANGELOGTIME].append(time_)
continue

key = getattr(rpm, f'RPMTAG_{k}'.upper())
self.header[key] = v

Expand Down
Binary file removed test/binary/SpecCheck4-0.0.1-0.x86_64.rpm
Binary file not shown.
Binary file not shown.
Binary file not shown.
56 changes: 56 additions & 0 deletions test/mockdata/mock_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,59 @@
'license': 'GPL-2.0+ WITH 389-exception',
},
)


ForbiddenControlCharPackage = get_tested_mock_package(
lazyload=True,
name='xtables-addons-kmp-default',
files=[],
header={
'requires': [
'ksym(default:',
'ksym(default:\b)',
'ksym(default:HX_memmem) = 55bffe85',
'ksym(default:PDE_DATA) = e515007f',
'ksym(default:__alloc_skb) = a57f3289'
],
'provides': [],
'arch': 'x86_64',
'name': 'xtables-addons-kmp-default',
'version': '0',
'release': '0',
},
)


ForbiddenControlCharChangelogPackage = get_tested_mock_package(
lazyload=True,
name='ruby2.6-rubygem-fast_gettext',
files=[],
header={
'requires': [],
'provides': [],
'arch': 'x86_64',
'name': 'ruby2.6-rubygem-fast_gettext',
'version': '0',
'release': '0',
'changelog': [
['daniel.garcia@suse.com', 'Text', 1557057600],
['daniel.garcia@suse.com', 'Forbiddeen character \x04 in changelog', 1557057600],
],
},
)


ForbiddenControlCharAllPackage = ForbiddenControlCharPackage.clone(
extend=True,
name='SpecCheck4',
files=[],
header={
'requires': ['/bin/sh', 'require\x06', 'rpmlib(CompressedFileNames) <= 3.0.4-1'],
'provides': ['SpecCheck4 = 0.0.1-0', 'SpecCheck4(x86-64) = 0.0.1-0', 'provide\x06'],
'obsoletes': ['obsoletes\x06'],
'conflicts': ['conflicts\x06'],
'changelog': [
['daniel.garcia@suse.com', 'changelog entry .... \x06', 1557057600],
],
},
)
2 changes: 1 addition & 1 deletion test/test_spellchecking.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_spellchecking():
result = spell.spell_check(text, 'Description({}):')
assert len(result) == 2
assert result['tihs'].startswith('Description(en_US): tihs -> ')
assert get_suggestions(result['tihs']) == ['hits', 'this', 'ties']
assert 'this' in get_suggestions(result['tihs'])

# different language, one typo
text = 'Příčerně žluťoučký kůň'
Expand Down
21 changes: 12 additions & 9 deletions test/test_tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from mockdata.mock_tags import (
FooDevelPackage,
ForbiddenControlCharAllPackage,
ForbiddenControlCharChangelogPackage,
ForbiddenControlCharPackage,
FuseCommonPackage,
InvalidExceptionPackage,
MissingProvidesPackage,
Expand Down Expand Up @@ -125,26 +128,26 @@ def test_valid_license_exception_begin_grouping(tmp_path, package, tagscheck):
assert 'W: invalid-license-exception' not in out


@pytest.mark.parametrize('package', ['binary/xtables-addons-kmp-default'])
def test_forbidden_controlchar_found_requires(tmp_path, package, tagscheck):
@pytest.mark.parametrize('package', [ForbiddenControlCharPackage])
def test_forbidden_controlchar_found_requires(package, tagscheck):
output, test = tagscheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'E: forbidden-controlchar-found Requires:' in out


@pytest.mark.parametrize('package', ['binary/ruby2.6-rubygem-fast_gettext'])
def test_forbidden_controlchar_found_changelog(tmp_path, package, tagscheck):
@pytest.mark.parametrize('package', [ForbiddenControlCharChangelogPackage])
def test_forbidden_controlchar_found_changelog(package, tagscheck):
output, test = tagscheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'E: forbidden-controlchar-found %changelog' in out


@pytest.mark.parametrize('package', ['binary/SpecCheck4'])
def test_forbidden_controlchar_found(tmp_path, package, tagscheck):
@pytest.mark.parametrize('package', [ForbiddenControlCharAllPackage])
def test_forbidden_controlchar_found(package, tagscheck):
output, test = tagscheck
test.check(get_tested_package(package, tmp_path))
test.check(package)
out = output.print_results(output.results)
assert 'E: forbidden-controlchar-found Requires:' in out
assert 'E: forbidden-controlchar-found Provides:' in out
Expand Down