def test_encoded_filename(self, mock_apt_cache): """ Ensure that we can locate urlencoded filenames in apt cache """ package = Package(mock_apt_cache) package.by_filename( '/var/cache/apt/archive/encodedpackage_3%3a6.03+dfsg-14.1+deb9u1_amd64.deb' ) assert package.name == 'encodedpackage' assert package.version == '3:6.03+dfsg-14.1+deb9u1' assert package.arch == 'amd64'
def process_package(config, filename, cache): logging.debug("Package Filename: %s", filename) pkg = Package(cache) # Allow PackageNotFound to bubble up # dpkg should not continue if we are unable to verify the package pkg.by_filename(filename) logging.debug("Package name: %s", pkg) # Generate the filters from configuration file filters = Filters() for _, repo in config['repositories'].items(): filters.new(repo['filter'], repo['app']) # Pass the package through the filter list, get a list of matching filters # We now have a list of filters which tell us what to do package_filter = filters.is_match(pkg) # If there was no match found, ignore this package if not package_filter: logging.info("No filter found, skipping signature checks..") return logging.info("Matched filter: \"%s\"", package_filter) logging.info("Validating signatures for %s using '%s'", pkg, package_filter.app) command = "{} {}".format(package_filter.app, pkg.filename) logging.debug("Passing to command '%s'", command) try: output = subprocess.check_output(command.split(), stderr=subprocess.STDOUT) except subprocess.CalledProcessError as error: logging.error("ERROR: Signature verification check FAILED") logging.error(error.output) sys.exit(error.returncode) else: logging.info(output)
def test_invalid_package_by_filename(self, mock_apt_cache): package = Package(mock_apt_cache) with pytest.raises(PackageNotFound): package.by_filename("mypackage_1.2.1_amd64.deb")
def test_by_filename(self, mock_apt_cache): package = Package(mock_apt_cache) package.by_filename('/var/cache/apt/archive/mypackage_1.0.1_amd64.deb') self.assert_package(package)