def test_output(tmpdir): """ Test the actual output of rpmlint on one file """ expected_output = """ngircd.x86_64: I: suse-other-error /usr/bin/1 ngircd.x86_64: I: suse-other-error /usr/bin/2 dovecot.x86_64: E: suse-other-error /usr/bin/3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ngircd.x86_64: E: suse-dbus-unauthorized-service\n""" cfg = Config(TEST_CONFIG_FILTERS) result = Filter(cfg) pkg = get_tested_package(TEST_PACKAGE, tmpdir) pkg2 = get_tested_package(TEST_PACKAGE2, tmpdir) # here we check if empty detail will not add whitespace result.add_info('E', pkg, 'suse-dbus-unauthorized-service', '') # two options so we check the description is added only once result.add_info('I', pkg, 'suse-other-error', '/usr/bin/1') result.add_info('I', pkg, 'suse-other-error', '/usr/bin/2') result.add_info('E', pkg2, 'suse-other-error', '/usr/bin/3') result.error_details.update({'suse-other-error': 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'}) assert len(result.print_results(result.results).splitlines()) == 4 result.info = True assert len(result.print_results(result.results).splitlines()) == 11 assert result.print_results(result.results) == expected_output
def test_overshadowing_of_initscript(tmpdir, package, sysvcheck): output, test = sysvcheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: systemd-shadowed-initscript bar' in out assert 'E: missing-rc-link bar' in out assert 'E: missing-rc-link foo' in out
def test_inconsistent_file_extension(tmpdir, package, sourcescheck): output, test = sourcescheck test.check(get_tested_package(package, tmpdir)) assert len(output.results) == 3 out = output.print_results(output.results) assert 'inconsistent-file-extension' in out assert 'a file should have' in out
def test_position_independent_executable(tmpdir, package, binariescheck): CONFIG.configuration['PieExecutables'] = ['.*'] output = Filter(CONFIG) test = BinariesCheck(CONFIG, output) test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: non-position-independent-executable /usr/bin/bcc-lua' in out
def test_appdata_fail(tmpdir, package, appdatacheck): output, test = appdatacheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) # there are two borked packages assert len(output.results) == 2 assert 'invalid-appdata-file' in out
def test_invalid_la_file(tmpdir, package, binariescheck): output, test = binariescheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: invalid-la-file' in out # no /usr/share dir there assert 'E: arch-dependent-file-in-usr-share' not in out
def test_shared_library1(tmpdir, package, binariescheck): output, test = binariescheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: invalid-soname' in out # there is an invalid soname here, so no "no-soname" error assert 'W: no-soname' not in out
def test_build_date_time_correct(tmpdir, package, builddatecheck): output, test = builddatecheck test.istoday = re.compile('Jan 1 2019') test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: file-contains-date-and-time' not in out assert 'E: file-contains-current-date' not in out
def test_mixed_ownership(tmpdir, package, mixedownershipcheck): output, test = mixedownershipcheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'noproblem' not in out assert 'file-parent-ownership-mismatch Path "/var/lib/badfolder/broken1" owned by "root" is stored in directory owned by "nobody"' in out assert 'file-parent-ownership-mismatch Path "/var/lib/badfolder/correctperms" owned by "root" is stored in directory owned by "nobody"' in out
def test_doccheck(tmpdir, package, doccheck): output, test = doccheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: executable-docs /usr/share/doc/packages/mydoc/doc.html' in out assert 'E: executable-docs /usr/share/doc/packages/mydoc/README' in out assert 'W: package-with-huge-docs 100%' in out
def test_zero_length_ignore(tmpdir, package, filescheck, filename, show): output, test = filescheck pkg = get_tested_package(package, tmpdir) test.check(pkg) out = output.print_results(output.results) assert filename in pkg.files assert (f'zero-length {filename}' in out) == show
def test_invalid_signature(tmpdir, package, signaturecheck): output, test = signaturecheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: invalid-signature' in out assert 'E: no-signature' not in out assert 'E: unknown-key' not in out
def test_pkg_config_correct(tmpdir, package, pkgconfigcheck): output, test = pkgconfigcheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: invalid-pkgconfig-file' not in out assert 'E: pkgconfig-invalid-libs-dir' not in out assert 'E: double-slash-in-pkgconfig-path' not in out
def test_pkg_config(tmpdir, package, pkgconfigcheck): output, test = pkgconfigcheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: invalid-pkgconfig-file /tmp/pkgconfig/xcb.pc' in out assert 'E: pkgconfig-invalid-libs-dir /tmp/pkgconfig/xcb.pc Libs: -L/usr/lib' in out assert 'E: double-slash-in-pkgconfig-path /tmp/pkgconfig/xcb.pc includedir=/usr/include//xyz' in out
def test_package_random_warnings(tmpdir, package, tagscheck): """Test if a package has check, - in out, obsolete-not-provided description-line-too-long, - not in out, invalid-dependency, unreasonable-epoch, no-description-tag, self-obsoletion.""" output, test = tagscheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) # Test if a package that was obsoleted is still provided # in newer package to avoid unnecessary dependency breakage assert 'W: obsolete-not-provided' in out # Test if a package has a description longer than 79 characters assert 'E: description-line-too-long This is ridiculously long description that has no meaning but is used to test the check description-line-too-long.' in out # Test if a package has a Requires tag value start with # string other than /usr/local/ assert 'E: invalid-dependency' not in out # Test if a package has a Epoch tag value less than or equal to 99 assert 'W: unreasonable-epoch' not in out # Test if a package has a non-empty description tag assert 'W: no-description-tag' not in out # Test if a package does not have itself in Obsoletes: tag value assert 'W: self-obsoletion' not in out
def test_makefile_junk(tmpdir, package, filescheck): output, test = filescheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: makefile-junk /usr/share/CMakeLists.txt' in out assert 'E: makefile-junk /usr/share/Makefile.am' in out assert 'E: makefile-junk /usr/share/selinux' not in out
def test_only_non_binary_in_usr_lib_exception(tmpdir, package, binariescheck): CONFIG.configuration['UsrLibBinaryException'] = '^/usr/lib(64)?/python' output = Filter(CONFIG) test = BinariesCheck(CONFIG, output) test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'W: only-non-binary-in-usr-lib' not in out
def test_check_summary_warning(tmpdir, package, tagscheck): """Test package for check - in out, summary-too-long, summary-has-leading-spaces, description-shorter-than-summary, - not in out invalid-version, unexpanded-macro. """ output, test = tagscheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) # Test if package has a summary longer than 80 characters assert 'E: summary-too-long' in out # Test if package has leading space at the beginning of the summary # where non-breaking space is used (U+00A0). assert b'E: summary-has-leading-spaces \xc2\xa0\xc2\xa0lorem'.decode() in out # Test if package has a shorter description than Summary assert 'W: description-shorter-than-summary' in out # Test if a package has a Version: tag # without any pre/alpha/beta suffixes in it's specfile. assert 'E: invalid-version' not in out # Test if a package does not have an unexpanded # macro in it's specfile. assert 'W: unexpanded-macro' not in out assert 'E: no-group-tag' in out
def test_binary_in_etc(tmpdir, package, binariescheck): output, test = binariescheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: binary-in-etc' in out # it's not a library package assert 'E: executable-in-library-package' not in out
def test_sysv_init_on_systemd_check(tmpdir, package, sysvcheck): output, test = sysvcheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: obsolete-insserv-requirement' in out assert 'E: deprecated-init-script weekly.script' in out assert 'E: deprecated-boot-script boot.script' in out
def test_multiple_errors(tmpdir, package, binariescheck): output, test = binariescheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'E: call-to-mktemp' in out assert 'E: missing-call-to-setgroups-before-setuid' in out assert 'W: binary-or-shlib-calls-gethostbyname' in out
def test_description_storing(tmpdir): """ Test if we can store extra destcriptions and formatting is up par """ lorem_formated = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\n""" cfg = Config(TEST_CONFIG_FILTERS) result = Filter(cfg) pkg = get_tested_package(TEST_PACKAGE, tmpdir) assert len(result.results) == 0 result.add_info('E', pkg, 'suse-dbus-unauthorized-service', '') # two options so we check the description is added only once result.add_info('I', pkg, 'suse-other-error', '/usr/bin/1') # nothing is populated assert not result.get_description('suse-other-error') # add descriptions result.error_details.update({ 'suse-other-error': 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' }) assert result.get_description('suse-other-error') == lorem_formated
def test_kmp_noreq(tmpdir, package, kmpcheck): output, test = kmpcheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'kmp-missing-supplements' in out assert 'kmp-missing-requires' in out assert 'kmp-missing-enhances' in out
def test_check_errors(tmpdir, package, tagscheck): """Test package for check invalid-version.""" output, test = tagscheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) # Test if a package has a Version: tag with pre/alpha/beta suffixes in it's specfile assert 'E: invalid-version 0pre' in out
def test_libalternative_ok(tmpdir, package, alternativescheck): output, test = alternativescheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'I: package supports libalternatives' in out assert 'E' not in out assert 'W' not in out
def test_file_not_utf8_for_compression_algorithms(tmpdir, package, filescheck): output, test = filescheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'file-not-utf8 /usr/share/doc/packages/testdocumentation/README1.gz' in out assert 'file-not-utf8 /usr/share/doc/packages/testdocumentation/README2.bz2' in out assert 'file-not-utf8 /usr/share/doc/packages/testdocumentation/README3.xz' in out
def test_check_include(tmpdir, speccheck): output, test = speccheck test.check_source(get_tested_package('source/CheckInclude', tmpdir)) out = output.print_results(output.results) assert '/tmp/' not in out assert 'no-buildroot-tag' in out assert 'E: specfile-error error: query of specfile' not in out
def test_shlib2_devel(tmpdir, package, filescheck): output, test = filescheck test.check(get_tested_package(package, tmpdir)) out = output.print_results(output.results) assert 'library-without-ldconfig-postin' in out assert 'library-without-ldconfig-postun' in out assert 'non-devel-file-in-devel-package' in out
def test_devel_files(tmpdir, package): output, test = filescheck() test.check(get_tested_package(package, tmpdir)) assert len(output.results) == 5 out = output.print_results(output.results) assert 'devel-file-in-non-devel-package' not in out assert 'incorrect-fsf-address' in out assert 'no-documentation' in out
def test_pam_check(tmpdir, package, pamcheck): output, test = pamcheck test.check(get_tested_package(package, tmpdir)) assert len(output.results) == 1 out = output.print_results(output.results) assert 'PamCheck.i586: E: use-old-pam-stack' in out assert '/etc/pam.d/PamCheck (line 1)' in out assert 'Update pam file' in out