diff options
author | Michał Górny <mgorny@gentoo.org> | 2017-11-08 10:15:06 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2017-11-08 10:15:06 +0100 |
commit | 3c2d1de39b26609dc9807305a1b144ac5a970aa3 (patch) | |
tree | 534ebf69b6bad346b89060514c406571be821886 | |
parent | 11396e898c0b72375e79579c532354a2dc02c187 (diff) | |
download | gemato-3c2d1de39b26609dc9807305a1b144ac5a970aa3.tar.gz |
Remove non-strict verification mode
-rw-r--r-- | gemato/cli.py | 10 | ||||
-rw-r--r-- | gemato/recursiveloader.py | 38 | ||||
-rw-r--r-- | tests/test_recursiveloader.py | 46 |
3 files changed, 16 insertions, 78 deletions
diff --git a/gemato/cli.py b/gemato/cli.py index 7440862..b3b36d9 100644 --- a/gemato/cli.py +++ b/gemato/cli.py @@ -17,11 +17,6 @@ import gemato.profile import gemato.recursiveloader -def verify_warning(e): - logging.warning(str(e)) - return True - - def verify_failure(e): logging.error(str(e)) return False @@ -40,8 +35,6 @@ def do_verify(args, argp): kwargs = {} if args.keep_going: kwargs['fail_handler'] = verify_failure - if not args.strict: - kwargs['warn_handler'] = verify_warning if not args.openpgp_verify: init_kwargs['verify_openpgp'] = False with gemato.openpgp.OpenPGPEnvironment() as env: @@ -255,9 +248,6 @@ def main(argv): help='Disable OpenPGP verification of signed Manifests') verify.add_argument('-s', '--require-signed-manifest', action='store_true', help='Require that the top-level Manifest is OpenPGP signed') - verify.add_argument('-S', '--no-strict', action='store_false', - dest='strict', - help='Do not fail on non-strict Manifest issues (MISC entries)') verify.set_defaults(func=do_verify) update = subp.add_parser('update', diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py index a58159c..daaa298 100644 --- a/gemato/recursiveloader.py +++ b/gemato/recursiveloader.py @@ -381,18 +381,14 @@ class ManifestRecursiveLoader(object): return out def _verify_one_file(self, path, relpath, e, fail_handler, - warn_handler, last_mtime): + last_mtime): ret, diff = gemato.verify.verify_path(path, e, expected_dev=self.manifest_device, last_mtime=last_mtime) if not ret: - if e is not None and e.tag == 'MISC': - h = warn_handler - else: - h = fail_handler err = gemato.exceptions.ManifestMismatch(relpath, e, diff) - ret = h(err) + ret = fail_handler(err) if ret is None: ret = True @@ -400,7 +396,7 @@ class ManifestRecursiveLoader(object): def assert_directory_verifies(self, path='', fail_handler=gemato.util.throw_exception, - warn_handler=None, last_mtime=None): + last_mtime=None): """ Verify the complete directory tree starting at @path (relative to top Manifest directory). Includes testing for stray files. @@ -408,18 +404,15 @@ class ManifestRecursiveLoader(object): verification. @fail_handler is the callback called whenever verification - fails for 'strong' entries (or stray files). @warn_handler - is called whenever verification fails for MISC entries. + fails (ether for mismatch, missing or stray file). The handler + is passed a ManifestMismatch exception object. The default fail + handler raises the exception. However, a custom handler can be + used to provide a non-strict mode, or continue the scan after + the first failure. - The handlers are passed a ManifestMismatch exception object. - The default fail handler raises the exception. Unless specified - explicitly, the warn handler defaults to fail handler. However, - custom handlers can be used to provide a non-strict mode, - or continue the scan after the first failure. - - If none of the handlers raise exceptions, the function returns - boolean. It returns False if at least one of the handler calls - returned explicit False; True otherwise. + If none of the handler calls raise an exception, the function + returns boolean. It returns False if at least one of the handler + calls returned explicit False; True otherwise. If @last_mtime is not None, then only files whose mtime is newer than that value (in st_mtime format) will be checked. Use this @@ -433,9 +426,6 @@ class ManifestRecursiveLoader(object): followlinks=True) ret = True - if warn_handler is None: - warn_handler = fail_handler - for dirpath, dirnames, filenames in it: relpath = os.path.relpath(dirpath, self.root_directory) # strip dot to avoid matching problems @@ -462,7 +452,7 @@ class ManifestRecursiveLoader(object): skip_dirs.append(d) else: ret &= self._verify_one_file(os.path.join(dirpath, d), - dpath, de, fail_handler, warn_handler, last_mtime) + dpath, de, fail_handler, last_mtime) # skip scanning ignored directories for d in skip_dirs: @@ -480,13 +470,13 @@ class ManifestRecursiveLoader(object): continue fe = entry_dict.pop(fpath, None) ret &= self._verify_one_file(os.path.join(dirpath, f), - fpath, fe, fail_handler, warn_handler, last_mtime) + fpath, fe, fail_handler, last_mtime) # check for missing files for relpath, e in entry_dict.items(): syspath = os.path.join(self.root_directory, relpath) ret &= self._verify_one_file(syspath, relpath, e, - fail_handler, warn_handler, last_mtime) + fail_handler, last_mtime) return ret diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py index 380ce34..61969a0 100644 --- a/tests/test_recursiveloader.py +++ b/tests/test_recursiveloader.py @@ -304,13 +304,6 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e self.assertRaises(gemato.exceptions.ManifestMismatch, m.assert_directory_verifies, 'sub') - def test_assert_directory_verifies_stray_file_nonstrict(self): - m = gemato.recursiveloader.ManifestRecursiveLoader( - os.path.join(self.dir, 'Manifest')) - self.assertRaises(gemato.exceptions.ManifestMismatch, - m.assert_directory_verifies, 'sub', - warn_handler=lambda x: True) - def test_assert_directory_verifies_stray_file_nofail(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) @@ -341,12 +334,6 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e os.path.join(self.dir, 'sub')]), 1) - def test_cli_verifies_stray_file_nonstrict(self): - self.assertEqual( - gemato.cli.main(['gemato', 'verify', '--no-strict', - os.path.join(self.dir, 'sub')]), - 1) - def test_cli_fails_without_signed_manifest(self): self.assertEqual( gemato.cli.main(['gemato', 'verify', @@ -1483,18 +1470,6 @@ MISC foo 0 MD5 d41d8cd98f00b204e9800998ecf8427e self.assertRaises(gemato.exceptions.ManifestMismatch, m.assert_directory_verifies, '') - def test_assert_directory_verifies_nonstrict(self): - m = gemato.recursiveloader.ManifestRecursiveLoader( - os.path.join(self.dir, 'Manifest')) - self.assertTrue(m.assert_directory_verifies('', - warn_handler=lambda x: True)) - - def test_assert_directory_verifies_nonstrict_false(self): - m = gemato.recursiveloader.ManifestRecursiveLoader( - os.path.join(self.dir, 'Manifest')) - self.assertFalse(m.assert_directory_verifies('', - warn_handler=lambda x: False)) - def test_assert_directory_verifies_nonstrict_via_fail_handler(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) @@ -1506,11 +1481,6 @@ MISC foo 0 MD5 d41d8cd98f00b204e9800998ecf8427e gemato.cli.main(['gemato', 'verify', self.dir]), 1) - def test_cli_verifies_nonstrict(self): - self.assertEqual( - gemato.cli.main(['gemato', 'verify', '--no-strict', self.dir]), - 0) - def test_update_entry_for_path(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) @@ -1561,19 +1531,13 @@ DATA sub/version 0 MD5 d41d8cd98f00b204e9800998ecf8427e os.path.join(self.dir, 'Manifest')) self.assertRaises(gemato.exceptions.ManifestCrossDevice, m.assert_directory_verifies, '', - fail_handler=lambda x: True, - warn_handler=lambda x: True) + fail_handler=lambda x: True) def test_cli_verifies(self): self.assertEqual( gemato.cli.main(['gemato', 'verify', self.dir]), 1) - def test_cli_verifies_nonstrict(self): - self.assertEqual( - gemato.cli.main(['gemato', 'verify', '--no-strict', self.dir]), - 1) - def test_update_entries_for_directory(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest'), @@ -1613,19 +1577,13 @@ class CrossDeviceEmptyManifestTest(TempDirTestCase): os.path.join(self.dir, 'Manifest')) self.assertRaises(gemato.exceptions.ManifestCrossDevice, m.assert_directory_verifies, '', - fail_handler=lambda x: True, - warn_handler=lambda x: True) + fail_handler=lambda x: True) def test_cli_verifies(self): self.assertEqual( gemato.cli.main(['gemato', 'verify', self.dir]), 1) - def test_cli_verifies_nonstrict(self): - self.assertEqual( - gemato.cli.main(['gemato', 'verify', '--no-strict', self.dir]), - 1) - def test_update_entries_for_directory(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest'), |