def test_filters_regexp(): """ Load some filters and make sure we generate nice regexp """ cfg = Config(TEST_CONFIG_FILTERS) result = Filter(cfg) assert len(cfg.configuration['Filters']) == 9 assert cfg.configuration['Filters'][0] == '.*invalid-buildhost.*' assert isinstance(result.filters_re, Pattern)
def test_data_storing(tmpdir): """ Load some filters and make sure we generate nice regexp """ cfg = Config(TEST_CONFIG_FILTERS) cfg.load_rpmlintrc(TEST_RPMLINTRC) result = Filter(cfg) pkg = get_tested_package(TEST_PACKAGE, tmpdir) # this should be filtered result.add_info('E', pkg, 'invalid-vendor', '') assert len(result.results) == 0 # this should be upgraded to error result.add_info('I', pkg, 'suse-other-error', '') assert len(result.results) == 1 assert result.printed_messages['I'] == 0 assert result.printed_messages['E'] == 1 # this should be downgraded result.add_info('E', pkg, 'suse-dbus-unauthorized-service', '') assert len(result.results) == 2 assert result.printed_messages['W'] == 1 assert result.printed_messages['E'] == 1
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_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 zipcheck(): CONFIG.info = True output = Filter(CONFIG) test = ZipCheck(CONFIG, output) return output, test
def sclcheck(): CONFIG.info = True output = Filter(CONFIG) test = SCLCheck(CONFIG, output) return output, test
def menuxdgcheck(): CONFIG.info = True output = Filter(CONFIG) test = MenuXDGCheck(CONFIG, output) return output, test
def distributioncheck(): CONFIG.info = True output = Filter(CONFIG) test = DistributionCheck(CONFIG, output) return output, test
def tagscheck(): CONFIG.info = True output = Filter(CONFIG) test = TagsCheck(CONFIG, output) return output, test
def speccheck(): CONFIG.info = True output = Filter(CONFIG) test = SpecCheck(CONFIG, output) return output, test
def rpmfilescheck(): CONFIG.info = True output = Filter(CONFIG) test = RpmFileCheck(CONFIG, output) return output, test
def pamcheck(): CONFIG.info = True output = Filter(CONFIG) test = PamCheck(CONFIG, output) return output, test
def main(): locale.setlocale(locale.LC_COLLATE, '') output = Filter(cfg) # Load all checks for c in cfg.configuration['Checks']: loadCheck(c, cfg, output) packages_checked = 0 specfiles_checked = 0 try: # Loop over all file names given in arguments dirs = [] for arg in args: pkgs = [] isfile = False try: if arg == '-': arg = '(standard input)' # Short-circuit stdin spec file check stdin = sys.stdin.readlines() if not stdin: continue with Pkg.FakePkg(arg) as pkg: runSpecChecks(pkg, None, spec_lines=stdin) specfiles_checked += 1 continue try: st = os.stat(arg) isfile = True if stat.S_ISREG(st[stat.ST_MODE]): if arg.endswith('.spec'): # Short-circuit spec file checks with Pkg.FakePkg(arg) as pkg: runSpecChecks(pkg, arg) specfiles_checked += 1 elif '/' in arg or arg.endswith('.rpm') or \ arg.endswith('.spm'): pkgs.append(Pkg.Pkg(arg, extract_dir)) else: raise OSError elif stat.S_ISDIR(st[stat.ST_MODE]): dirs.append(arg) continue else: raise OSError except OSError: ipkgs = Pkg.getInstalledPkgs(arg) if not ipkgs: print_warning( '(none): E: no installed packages by name %s' % arg) else: ipkgs.sort(key=lambda x: locale.strxfrm( x.header.sprintf('%{NAME}.%{ARCH}'))) pkgs.extend(ipkgs) except KeyboardInterrupt: if isfile: arg = os.path.abspath(arg) print_warning( '(none): E: interrupted, exiting while reading %s' % arg) sys.exit(2) except Exception as e: if isfile: arg = os.path.abspath(arg) print_warning('(none): E: error while reading %s: %s' % (arg, e)) pkgs = [] continue for pkg in pkgs: with pkg: runChecks(pkg) packages_checked += 1 for dname in dirs: try: for path, _, files in os.walk(dname): for fname in files: fname = os.path.abspath(os.path.join(path, fname)) try: if fname.endswith('.rpm') or \ fname.endswith('.spm'): with Pkg.Pkg(fname, extract_dir) as pkg: runChecks(pkg) packages_checked += 1 elif fname.endswith('.spec'): with Pkg.FakePkg(fname) as pkg: runSpecChecks(pkg, fname) specfiles_checked += 1 except KeyboardInterrupt: print_warning( '(none): E: interrupted while reading %s' % fname) sys.exit(2) except Exception as e: print_warning('(none): E: while reading %s: %s' % (fname, e)) continue except Exception as e: print_warning('(none): E: error while reading dir %s: %s' % (dname, e)) continue print(output.print_results(output.results)) if output.badness_threshold > 0 and output.score > output.badness_threshold: print_warning( '(none): E: badness %d exceeds threshold %d, aborting.' % (output.score, output.badness_threshold)) sys.exit(66) finally: print('%d packages and %d specfiles checked; %d errors, %d warnings.' % (packages_checked, specfiles_checked, output.printed_messages['E'], output.printed_messages['W'])) if output.printed_messages['E'] > 0: sys.exit(64) sys.exit(0)
kv = o[1].split(None, 1) if len(kv) == 1: config_overrides[kv[0]] = None else: config_overrides[kv[0]] = eval(kv[1]) # apply config overrides for key, value in config_overrides.items(): cfg.configuration[key] = value if not extract_dir: extract_dir = tempfile.gettempdir() if info_error: cfg.info = True output = Filter(cfg) for c in checks: cfg.add_check(c) for c in cfg.configuration['Checks']: loadCheck(c, cfg, output) for e in sorted(info_error): print('{}:'.format(e)) print(output.get_description(e)) sys.exit(0) # if no argument print usage if not args: usage(argv0) sys.exit(1) if __name__ == '__main__':
def sourcescheck(): CONFIG.info = True output = Filter(CONFIG) test = SourceCheck(CONFIG, output) return output, test