def conanfile_capture_verify_manifest_folder_test(self):
        files = {"conanfile.txt": "[requires]\nHello/0.1@lasote/stable"}
        self.client.save(files, clean_first=True)
        folder = "mymanifests"
        self._capture_verify_manifest(".", folder=folder)

        conanfile = """from conans import ConanFile
class ConanFileTest(ConanFile):
    name = "Hello2"
    version = "0.1"
"""
        client = TestClient(base_folder=self.client.base_folder)
        client.save({CONANFILE: conanfile})
        client.run("export lasote/stable")

        files = {
            "conanfile.txt":
            "[requires]\nHello2/0.1@lasote/stable\nHello/0.1@lasote/stable"
        }
        self.client.save(files)

        self.client.run("install . --build missing --manifests %s" % folder)

        remote = "local cache"
        package_reference = PackageReference.loads(
            "Hello/0.1@lasote/stable:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK",
                      self.client.user_io.out)
        self.assertIn("Manifest for '%s': OK" % str(package_reference),
                      self.client.user_io.out)
        self.assertIn(
            "Installed manifest for 'Hello2/0.1@lasote/stable' from %s" %
            remote, self.client.user_io.out)
        self.assertIn(
            "Installed manifest for 'Hello2/0.1@lasote/stable:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
            self.client.user_io.out)

        output_folder = os.path.join(self.client.current_folder, folder)
        paths = SimplePaths(output_folder)
        self.assertTrue(
            os.path.exists(paths.digestfile_conanfile(self.reference)))
        self.assertTrue(
            os.path.exists(paths.digestfile_package(package_reference)))
        package_reference = PackageReference.loads(
            "Hello2/0.1@lasote/stable:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(
            os.path.exists(paths.digestfile_package(package_reference)))
Exemple #2
0
    def _capture_verify_manifest(self, reference, remote="local cache", folder=""):
        self.client.run("install %s --build missing --manifests %s" % (str(reference), folder))
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote,
                      self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable:"
                      "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
                      self.client.user_io.out)

        real_folder = folder or ".conan_manifests"
        output_folder = os.path.join(self.client.current_folder, real_folder)
        paths = SimplePaths(output_folder)
        self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference)))
        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))

        # again should do nothing
        self.client.run("install %s --build missing --manifests %s"
                        % (str(self.reference), folder))
        self.assertNotIn("Installed manifest", self.client.user_io.out)

        # now verify
        self.client.run("install %s --build missing --verify %s" % (str(self.reference), folder))
        self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out)
        self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
    def _capture_verify_manifest(self, reference, remote="local cache", folder=""):
        self.client.run("install %s --build missing --manifests %s" % (str(reference), folder))
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote,
                      self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable:"
                      "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
                      self.client.user_io.out)

        real_folder = folder or ".conan_manifests"
        output_folder = os.path.join(self.client.current_folder, real_folder)
        paths = SimplePaths(output_folder)
        self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference)))
        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))

        # again should do nothing
        self.client.run("install %s --build missing --manifests %s"
                        % (str(self.reference), folder))
        self.assertNotIn("manifest", self.client.user_io.out)

        # now verify
        self.client.run("install %s --build missing --verify %s" % (str(self.reference), folder))
        self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out)
        self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
Exemple #4
0
    def test_package_test(self, use_abs_folder):
        self.client.run("install Hello/0.1@lasote/stable --build missing")
        conanfile = """from conans import ConanFile

class ConsumerFileTest(ConanFile):
    name = "Chat"
    version = "0.1"
    requires = "Hello/0.1@lasote/stable"
"""
        test_conanfile = """from conans import ConanFile

class ConsumerFileTest(ConanFile):
    requires = "Chat/0.1@lasote/stable"
    def test(self):
        self.output.info("TEST OK")
"""
        if use_abs_folder:
            output_folder = temp_folder()
            dest = '="%s"' % output_folder
        else:
            dest = ""
            output_folder = os.path.join(self.client.current_folder,
                                         ".conan_manifests")

        self.client.save(
            {
                "conanfile.py": conanfile,
                "test_package/conanfile.py": test_conanfile
            },
            clean_first=True)

        self.client.run("create . lasote/stable --manifests%s" % dest)
        self.assertIn("Chat/0.1@lasote/stable (test package): TEST OK",
                      self.client.user_io.out)
        self.assertIn(
            "Installed manifest for 'Chat/0.1@lasote/stable' from local cache",
            self.client.user_io.out)
        self.assertIn(
            "Installed manifest for 'Hello/0.1@lasote/stable' from local cache",
            self.client.user_io.out)

        paths = SimplePaths(output_folder)
        self.assertTrue(
            os.path.exists(paths.digestfile_conanfile(self.reference)))
        package_reference = PackageReference.loads(
            "Hello/0.1@lasote/stable:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(
            os.path.exists(paths.digestfile_package(package_reference)))
        # now verify
        self.client.run("create . lasote/stable --verify%s" % dest)
        self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK",
                      self.client.user_io.out)
        self.assertIn("Manifest for '%s': OK" % str(package_reference),
                      self.client.user_io.out)
    def _failed_package_verify(self, reference, remote="local cache"):
        self.client.run("install %s --build missing --manifests" %
                        str(reference))
        self.assertIn(
            "Installed manifest for 'Hello/0.1@lasote/stable' from %s" %
            remote, self.client.user_io.out)
        self.assertIn(
            "Installed manifest for 'Hello/0.1@lasote/stable:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
            self.client.user_io.out)

        output_folder = os.path.join(self.client.current_folder,
                                     ".conan_manifests")
        paths = SimplePaths(output_folder)
        self.assertTrue(
            os.path.exists(paths.digestfile_conanfile(self.reference)))

        package_reference = PackageReference.loads(
            "Hello/0.1@lasote/stable:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(
            os.path.exists(paths.digestfile_package(package_reference)))

        client = TestClient(servers=self.servers,
                            users={"default": [("lasote", "mypass")]})

        client.save(self.files)
        client.run("export lasote/stable")
        client.run("install Hello/0.1@lasote/stable --build=missing")
        info = os.path.join(client.paths.package(package_reference),
                            "conaninfo.txt")
        info_content = load(info)
        info_content += "# Dummy string"
        save(info, info_content)
        manifest = client.paths.load_package_manifest(package_reference)
        manifest.file_sums["conaninfo.txt"] = md5(info_content)
        save(client.paths.digestfile_package(package_reference), str(manifest))

        manifest = client.paths.load_package_manifest(package_reference)
        client.run("upload %s --all" % str(self.reference))

        # now verify, with update
        self.client.run("remove Hello/0.1@lasote/stable -f")
        self.client.run("install %s --build missing --verify" %
                        str(self.reference),
                        ignore_error=True)
        self.assertNotIn("Manifest for 'Hello/0.1@lasote/stable': OK",
                         self.client.user_io.out)
        self.assertNotIn("Manifest for '%s': OK" % str(package_reference),
                         self.client.user_io.out)
        self.assertIn(
            "Modified or new manifest '%s' detected" % str(package_reference),
            self.client.user_io.out)
    def conanfile_capture_verify_manifest_folder_test(self):
        files = {"conanfile.txt": "[requires]\nHello/0.1@lasote/stable"}
        self.client.save(files, clean_first=True)
        folder = "mymanifests"
        self._capture_verify_manifest(".", folder=folder)

        conanfile = """from conans import ConanFile
class ConanFileTest(ConanFile):
    name = "Hello2"
    version = "0.1"
"""
        client = TestClient(base_folder=self.client.base_folder)
        client.save({CONANFILE: conanfile})
        client.run("export lasote/stable")

        files = {"conanfile.txt": "[requires]\nHello2/0.1@lasote/stable\nHello/0.1@lasote/stable"}
        self.client.save(files)

        self.client.run("install . --build missing --manifests %s" % folder)

        remote = "local cache"
        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out)
        self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello2/0.1@lasote/stable' from %s" % remote,
                      self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello2/0.1@lasote/stable:"
                      "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
                      self.client.user_io.out)

        output_folder = os.path.join(self.client.current_folder, folder)
        paths = SimplePaths(output_folder)
        self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference)))
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))
        package_reference = PackageReference.loads("Hello2/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))
    def _failed_verify(self, reference, remote="local cache"):
        self.client.run("install %s --build missing --manifests" %
                        str(reference))
        self.assertIn(
            "Installed manifest for 'Hello/0.1@lasote/stable' from %s" %
            remote, self.client.user_io.out)
        self.assertIn(
            "Installed manifest for 'Hello/0.1@lasote/stable:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
            self.client.user_io.out)

        output_folder = os.path.join(self.client.current_folder,
                                     ".conan_manifests")
        paths = SimplePaths(output_folder)
        self.assertTrue(
            os.path.exists(paths.digestfile_conanfile(self.reference)))

        package_reference = PackageReference.loads(
            "Hello/0.1@lasote/stable:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(
            os.path.exists(paths.digestfile_package(package_reference)))

        client = TestClient(servers=self.servers,
                            users={"default": [("lasote", "mypass")]})
        conanfile = """from conans import ConanFile
class ConanFileTest(ConanFile):
    name = "Hello"
    version = "0.1"
    exports = "*"
"""
        files = {CONANFILE: conanfile, "data.txt": "MyDataHacked"}
        # Export and upload the conanfile
        client.save(files)
        client.run("export lasote/stable")
        client.run("upload %s --all" % str(self.reference))

        # now verify, with update
        self.client.run("remove Hello/0.1@lasote/stable -f")
        self.client.run("install %s --build missing --verify" %
                        str(self.reference),
                        ignore_error=True)
        self.assertNotIn("Manifest for 'Hello/0.1@lasote/stable': OK",
                         self.client.user_io.out)
        self.assertNotIn("Manifest for '%s': OK" % str(package_reference),
                         self.client.user_io.out)
        self.assertIn(
            "Modified or new manifest 'Hello/0.1@lasote/stable' detected",
            self.client.user_io.out)
    def test_package_test(self, use_abs_folder):
        self.client.run("install Hello/0.1@lasote/stable --build missing")
        conanfile = """from conans import ConanFile

class ConsumerFileTest(ConanFile):
    name = "Chat"
    version = "0.1"
    requires = "Hello/0.1@lasote/stable"
"""
        test_conanfile = """from conans import ConanFile

class ConsumerFileTest(ConanFile):
    requires = "Chat/0.1@lasote/stable"
    def test(self):
        self.output.info("TEST OK")
"""
        if use_abs_folder:
            output_folder = temp_folder()
            dest = '="%s"' % output_folder
        else:
            dest = ""
            output_folder = os.path.join(self.client.current_folder, ".conan_manifests")

        self.client.save({"conanfile.py": conanfile,
                          "test_package/conanfile.py": test_conanfile}, clean_first=True)

        self.client.run("create . lasote/stable --manifests%s" % dest)
        self.assertIn("Chat/0.1@lasote/stable (test package): TEST OK", self.client.user_io.out)
        self.assertIn("Installed manifest for 'Chat/0.1@lasote/stable' from local cache",
                      self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from local cache",
                      self.client.user_io.out)

        paths = SimplePaths(output_folder)
        self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference)))
        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))
        # now verify
        self.client.run("create . lasote/stable --verify%s" % dest)
        self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out)
        self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
    def _failed_package_verify(self, reference, remote="local cache"):
        self.client.run("install %s --build missing --manifests" % str(reference))
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote,
                      self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable:"
                      "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
                      self.client.user_io.out)

        output_folder = os.path.join(self.client.current_folder, ".conan_manifests")
        paths = SimplePaths(output_folder)
        self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference)))

        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))

        client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]})

        client.save(self.files)
        client.run("export lasote/stable")
        client.run("install Hello/0.1@lasote/stable --build=missing")
        info = os.path.join(client.paths.package(package_reference), "conaninfo.txt")
        info_content = load(info)
        info_content += "# Dummy string"
        save(info, info_content)
        manifest = client.paths.load_package_manifest(package_reference)
        manifest.file_sums["conaninfo.txt"] = md5(info_content)
        save(client.paths.digestfile_package(package_reference), str(manifest))

        manifest = client.paths.load_package_manifest(package_reference)
        client.run("upload %s --all" % str(self.reference))

        # now verify, with update
        self.client.run("remove Hello/0.1@lasote/stable -f")
        self.client.run("install %s --build missing --verify"
                        % str(self.reference),
                        ignore_error=True)
        self.assertNotIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out)
        self.assertNotIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
        self.assertIn("Modified or new manifest '%s' detected" % str(package_reference),
                      self.client.user_io.out)
    def _failed_verify(self, reference, remote="local cache"):
        self.client.run("install %s --build missing --manifests" % str(reference))
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote,
                      self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable:"
                      "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
                      self.client.user_io.out)

        output_folder = os.path.join(self.client.current_folder, ".conan_manifests")
        paths = SimplePaths(output_folder)
        self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference)))

        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))

        client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]})
        conanfile = """from conans import ConanFile
class ConanFileTest(ConanFile):
    name = "Hello"
    version = "0.1"
    exports = "*"
"""
        files = {CONANFILE: conanfile, "data.txt": "MyDataHacked"}
        # Export and upload the conanfile
        client.save(files)
        client.run("export lasote/stable")
        client.run("upload %s --all" % str(self.reference))

        # now verify, with update
        self.client.run("remove Hello/0.1@lasote/stable -f")
        self.client.run("install %s --build missing --verify"
                        % str(self.reference),
                        ignore_error=True)
        self.assertNotIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out)
        self.assertNotIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
        self.assertIn("Modified or new manifest 'Hello/0.1@lasote/stable' detected",
                      self.client.user_io.out)
Exemple #11
0
class ManifestManager(object):
    def __init__(self,
                 folder,
                 user_io,
                 client_cache,
                 verify=False,
                 interactive=False):
        if verify and not os.path.exists(folder):
            raise ConanException("Manifest folder does not exist: %s" % folder)
        self._paths = SimplePaths(folder)
        self._user_io = user_io
        self._client_cache = client_cache
        self._verify = verify
        self._interactive = interactive
        self._log = []

    def print_log(self):
        self._user_io.out.success("\nManifests : %s" % (self._paths.store))
        for log_entry in self._log:
            self._user_io.out.info(log_entry)

    def _handle_add(self, reference, remote, manifest, path):
        # query the user for approval
        if self._interactive:
            ok = self._user_io.request_boolean(
                "Installing %s from %s\n"
                "Do you trust it?" % (str(reference), remote), True)
        else:
            ok = True

        if ok:
            save(path, str(manifest))
            self._log.append("Installed manifest for '%s' from %s" %
                             (str(reference), remote))
        else:
            raise ConanException("Installation of '%s' rejected!" %
                                 str(reference))

    def _check(self, reference, manifest, remote, path):
        if os.path.exists(path):
            existing_manifest = FileTreeManifest.loads(load(path))
            if existing_manifest == manifest:
                self._log.append("Manifest for '%s': OK" % str(reference))
                return

        if self._verify:
            diff = existing_manifest.difference(manifest)
            error_msg = os.linesep.join(
                "Mismatched checksum '%s' (manifest: %s, file: %s)" %
                (fname, h1, h2) for fname, (h1, h2) in diff.items())
            raise ConanException(
                "Modified or new manifest '%s' detected.\n"
                "Remote: %s\nProject manifest doesn't match installed one\n%s"
                % (str(reference), remote, error_msg))

        self._handle_add(reference, remote, manifest, path)

    def _match_manifests(self, read_manifest, expected_manifest, reference):
        if read_manifest is None or read_manifest != expected_manifest:
            raise ConanException("%s local cache package is corrupted: "
                                 "some file hash doesn't match manifest" %
                                 (str(reference)))

    def check_recipe(self, conan_reference, remote):
        manifests = self._client_cache.conan_manifests(conan_reference)
        read_manifest, expected_manifest = manifests
        remote = "local cache" if not remote else "%s:%s" % (remote.name,
                                                             remote.url)
        self._match_manifests(read_manifest, expected_manifest,
                              conan_reference)

        path = self._paths.digestfile_conanfile(conan_reference)
        self._check(conan_reference, read_manifest, remote, path)

    def check_package(self, package_reference, remote):
        manifests = self._client_cache.package_manifests(package_reference)
        read_manifest, expected_manifest = manifests
        remote = "local cache" if not remote else "%s:%s" % (remote.name,
                                                             remote.url)
        self._match_manifests(read_manifest, expected_manifest,
                              package_reference)

        path = self._paths.digestfile_package(package_reference,
                                              short_paths=None)
        self._check(package_reference, read_manifest, remote, path)
Exemple #12
0
class ManifestManager(object):

    def __init__(self, folder, user_io, client_cache, verify=False, interactive=False):
        if verify and not os.path.exists(folder):
            raise ConanException("Manifest folder does not exist: %s" % folder)
        self._paths = SimplePaths(folder)
        self._user_io = user_io
        self._client_cache = client_cache
        self._verify = verify
        self._interactive = interactive
        self._log = []

    def print_log(self):
        self._user_io.out.success("\nManifests")
        for log_entry in self._log:
            self._user_io.out.info(log_entry)

    def _handle_add(self, reference, remote, manifest, path):
        # query the user for approval
        if self._interactive:
            ok = self._user_io.request_boolean("Installing %s from %s\n"
                                               "Do you trust it?" % (str(reference), remote),
                                               True)
        else:
            ok = True

        if ok:
            save(path, str(manifest))
            self._log.append("Installed manifest for '%s' from %s" % (str(reference), remote))
        else:
            raise ConanException("Installation of '%s' rejected!" % str(reference))

    def _check(self, reference, manifest, remote, path):
        if os.path.exists(path):
            existing_manifest = FileTreeManifest.loads(load(path))
            if existing_manifest.file_sums == manifest.file_sums:
                self._log.append("Manifest for '%s': OK" % str(reference))
                return

        if self._verify:
            raise ConanException("Modified or new manifest '%s' detected.\n"
                                 "Remote: %s\nProject manifest doesn't match installed one"
                                 % (str(reference), remote))

        self._handle_add(reference, remote, manifest, path)

    def _match_manifests(self, read_manifest, expected_manifest, reference):
        if read_manifest is None or read_manifest.file_sums != expected_manifest.file_sums:
            raise ConanException("%s local cache package is corrupted: "
                                 "some file hash doesn't match manifest"
                                 % (str(reference)))

    def check_recipe(self, conan_reference, remote):
        manifests = self._client_cache.conan_manifests(conan_reference)
        read_manifest, expected_manifest = manifests
        remote = "local cache" if not remote else "%s:%s" % (remote.name, remote.url)
        self._match_manifests(read_manifest, expected_manifest, conan_reference)

        path = self._paths.digestfile_conanfile(conan_reference)
        self._check(conan_reference, read_manifest, remote, path)

    def check_package(self, package_reference, remote):
        manifests = self._client_cache.package_manifests(package_reference)
        read_manifest, expected_manifest = manifests
        remote = "local cache" if not remote else "%s:%s" % (remote.name, remote.url)
        self._match_manifests(read_manifest, expected_manifest, package_reference)

        path = self._paths.digestfile_package(package_reference, short_paths=None)
        self._check(package_reference, read_manifest, remote, path)