Ejemplo n.º 1
0
	def testCopy(self):
		sha1 = manifest.get_algorithm('sha1')
		sha1new = manifest.get_algorithm('sha1new')
		source = os.path.join(self.tmp, 'badname')
		os.mkdir(source)

		self.populate_sample(source)

		lines = list(sha1new.generate_manifest(source))
		self.assertEqual(['F f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 2 5 MyFile',
				   'S 570b0ce957ab43e774c82fca0ea3873fc452278b 19 a symlink',
				   'D /My Dir',
				   'F 0236ef92e1e37c57f0eb161e7e2f8b6a8face705 2 10 !a file!',
				   'X b4ab02f2c791596a980fd35f51f5d92ee0b4705c 2 10 !a file!.exe'],
				lines)
		digest = sha1.getID(manifest.add_manifest_file(source, sha1))

		copy = tempfile.mktemp()
		os.mkdir(copy)
		try:
			# Source must be in the form alg=value
			try:
				cli.do_copy([source, copy])
				assert 0
			except BadDigest as ex:
				assert 'badname' in str(ex)
			source, badname = os.path.join(self.tmp, digest), source
			os.chmod(badname, 0o755)		# can't rename RO directories on MacOS X
			os.rename(badname, source)
			os.chmod(source, 0o555)

			# Can't copy sha1 implementations (unsafe)
			try:
				cli.do_copy([source, copy])
			except SafeException as ex:
				assert 'sha1' in str(ex)

			# Already have a .manifest
			try:
				manifest.add_manifest_file(source, sha1new)
				assert 0
			except SafeException as ex:
				assert '.manifest' in str(ex)

			os.chmod(source, 0o700)
			os.unlink(os.path.join(source, '.manifest'))

			# Switch to sha1new
			digest = sha1new.getID(manifest.add_manifest_file(source, sha1new))
			source, badname = os.path.join(self.tmp, digest), source
			os.chmod(badname, 0o755)
			os.rename(badname, source)
			os.chmod(source, 0o555)

			cli.do_copy([source, copy])

			with open(os.path.join(copy, digest, 'MyFile'), 'rt') as stream:
				self.assertEqual('Hello', stream.read())
		finally:
			support.ro_rmtree(copy)
Ejemplo n.º 2
0
    def testCopy(self):
        sha1 = manifest.get_algorithm('sha1')
        sha1new = manifest.get_algorithm('sha1new')
        source = os.path.join(self.tmp, 'badname')
        os.mkdir(source)

        self.populate_sample(source)

        lines = list(sha1new.generate_manifest(source))
        self.assertEquals([
            'F f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 2 5 MyFile',
            'S 570b0ce957ab43e774c82fca0ea3873fc452278b 19 a symlink',
            'D /My Dir',
            'F 0236ef92e1e37c57f0eb161e7e2f8b6a8face705 2 10 !a file!',
            'X b4ab02f2c791596a980fd35f51f5d92ee0b4705c 2 10 !a file!.exe'
        ], lines)
        digest = sha1.getID(manifest.add_manifest_file(source, sha1))

        copy = tempfile.mktemp()
        os.mkdir(copy)
        try:
            # Source must be in the form alg=value
            try:
                cli.do_copy([source, copy])
                assert 0
            except BadDigest as ex:
                assert 'badname' in str(ex)
            source, badname = os.path.join(self.tmp, digest), source
            os.rename(badname, source)

            # Can't copy sha1 implementations (unsafe)
            try:
                cli.do_copy([source, copy])
            except SafeException as ex:
                assert 'sha1' in str(ex)

            # Already have a .manifest
            try:
                manifest.add_manifest_file(source, sha1new)
                assert 0
            except SafeException as ex:
                assert '.manifest' in str(ex)

            os.chmod(source, 0o700)
            os.unlink(os.path.join(source, '.manifest'))

            # Switch to sha1new
            digest = sha1new.getID(manifest.add_manifest_file(source, sha1new))
            source, badname = os.path.join(self.tmp, digest), source
            os.rename(badname, source)

            cli.do_copy([source, copy])

            self.assertEquals(
                'Hello',
                file(os.path.join(copy, digest, 'MyFile')).read())
        finally:
            support.ro_rmtree(copy)
Ejemplo n.º 3
0
	def assert_manifest(self, required):
		alg_name = required.split('=', 1)[0]
		manifest.fixup_permissions(self.tmpdir)
		sha1 = alg_name + '=' + manifest.add_manifest_file(self.tmpdir, manifest.get_algorithm(alg_name)).hexdigest()
		self.assertEqual(sha1, required)

		# Check permissions are sensible
		for root, dirs, files in os.walk(self.tmpdir):
			for f in files + dirs:
				full = os.path.join(root, f)
				if os.path.islink(full): continue
				full_mode = os.stat(full).st_mode
				self.assertEqual(0o444, full_mode & 0o666)	# Must be r-?r-?r-?
Ejemplo n.º 4
0
    def assert_manifest(self, required):
        alg_name = required.split('=', 1)[0]
        manifest.fixup_permissions(self.tmpdir)
        sha1 = alg_name + '=' + manifest.add_manifest_file(
            self.tmpdir, manifest.get_algorithm(alg_name)).hexdigest()
        self.assertEqual(sha1, required)

        # Check permissions are sensible
        for root, dirs, files in os.walk(self.tmpdir):
            for f in files + dirs:
                full = os.path.join(root, f)
                if os.path.islink(full): continue
                full_mode = os.stat(full).st_mode
                self.assertEqual(0o444, full_mode & 0o666)  # Must be r-?r-?r-?
Ejemplo n.º 5
0
 def testVerify(self):
     path = os.path.join(self.tmp, "MyLink")
     os.symlink("Hello", path)
     mfile = os.path.join(self.tmp, ".manifest")
     for alg_name in ["sha1", "sha256", "sha1new"]:
         try:
             alg = manifest.get_algorithm(alg_name)
             added_digest = alg.getID(manifest.add_manifest_file(self.tmp, alg))
             digest = alg.new_digest()
             digest.update("Hello")
             self.assertEquals("S %s 5 MyLink\n" % digest.hexdigest(), file(mfile, "rb").read())
             manifest.verify(self.tmp, added_digest)
             os.chmod(self.tmp, 0700)
             os.unlink(mfile)
         except BadDigest, ex:
             raise Exception("%s: %s\n%s" % (alg_name, ex, ex.detail))
Ejemplo n.º 6
0
	def testVerify(self):
		path = os.path.join(self.tmp, 'MyLink')
		os.symlink('Hello', path)
		mfile = os.path.join(self.tmp, '.manifest')
		for alg_name in ['sha1', 'sha256', 'sha1new']:
			try:
				alg = manifest.get_algorithm(alg_name)
				added_digest = alg.getID(manifest.add_manifest_file(self.tmp, alg))
				digest = alg.new_digest()
				digest.update('Hello')
				self.assertEquals("S %s 5 MyLink\n" % digest.hexdigest(),
						file(mfile, 'rb').read())
				manifest.verify(self.tmp, added_digest)
				os.chmod(self.tmp, 0o700)
				os.unlink(mfile)
			except BadDigest as ex:
				raise Exception("%s: %s\n%s" % (alg_name, ex, ex.detail))
Ejemplo n.º 7
0
 def testVerify(self):
     path = os.path.join(self.tmp, 'MyLink')
     os.symlink('Hello', path)
     mfile = os.path.join(self.tmp, '.manifest')
     for alg_name in ['sha1', 'sha256', 'sha1new']:
         try:
             alg = manifest.get_algorithm(alg_name)
             added_digest = alg.getID(
                 manifest.add_manifest_file(self.tmp, alg))
             digest = alg.new_digest()
             digest.update('Hello')
             self.assertEquals("S %s 5 MyLink\n" % digest.hexdigest(),
                               file(mfile, 'rb').read())
             manifest.verify(self.tmp, added_digest)
             os.chmod(self.tmp, 0o700)
             os.unlink(mfile)
         except BadDigest as ex:
             raise Exception("%s: %s\n%s" % (alg_name, ex, ex.detail))
Ejemplo n.º 8
0
def export_impls(export_dir, impls):
	implementations = os.path.join(export_dir, 'implementations')
	for digest, impl in impls.iteritems():
		print "Exporting implementation %s (%s %s)" % (impl, impl.feed.get_name(), impl.get_version())
		# Store implementation
		src = get_implementation_path(impl)
		dst = os.path.join(implementations, digest)
		shutil.copytree(src, dst, symlinks = True)

		# Regenerate the manifest, because it might be for a different algorithm
		os.chmod(dst, 0755)
		os.unlink(os.path.join(dst, '.manifest'))
		alg_name, required_value = digest.split('=', 1)
		alg = manifest.algorithms[alg_name]
		actual = manifest.add_manifest_file(dst, alg).hexdigest()
		assert actual == required_value, "Expected digest '%s', but found '%s'" % (required_value, actual)

		for root, dirs, files in os.walk(dst):
			os.chmod(root, 0755)
		os.unlink(os.path.join(dst, '.manifest'))
		info("Exported implementation %s", impl)
Ejemplo n.º 9
0
    def testCopy(self):
        sha1 = manifest.get_algorithm("sha1")
        sha1new = manifest.get_algorithm("sha1new")
        source = os.path.join(self.tmp, "badname")
        os.mkdir(source)

        self.populate_sample(source)

        lines = list(sha1new.generate_manifest(source))
        self.assertEquals(
            [
                "F f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 2 5 MyFile",
                "S 570b0ce957ab43e774c82fca0ea3873fc452278b 19 a symlink",
                "D /My Dir",
                "F 0236ef92e1e37c57f0eb161e7e2f8b6a8face705 2 10 !a file!",
                "X b4ab02f2c791596a980fd35f51f5d92ee0b4705c 2 10 !a file!.exe",
            ],
            lines,
        )
        digest = sha1.getID(manifest.add_manifest_file(source, sha1))

        copy = tempfile.mktemp()
        os.mkdir(copy)
        try:
            # Source must be in the form alg=value
            try:
                cli.do_copy([source, copy])
                assert 0
            except BadDigest, ex:
                assert "badname" in str(ex)
            source, badname = os.path.join(self.tmp, digest), source
            os.rename(badname, source)

            # Can't copy sha1 implementations (unsafe)
            try:
                cli.do_copy([source, copy])
            except SafeException, ex:
                assert "sha1" in str(ex)
Ejemplo n.º 10
0
                cli.do_copy([source, copy])
                assert 0
            except BadDigest, ex:
                assert "badname" in str(ex)
            source, badname = os.path.join(self.tmp, digest), source
            os.rename(badname, source)

            # Can't copy sha1 implementations (unsafe)
            try:
                cli.do_copy([source, copy])
            except SafeException, ex:
                assert "sha1" in str(ex)

                # Already have a .manifest
            try:
                manifest.add_manifest_file(source, sha1new)
                assert 0
            except SafeException, ex:
                assert ".manifest" in str(ex)

            os.chmod(source, 0700)
            os.unlink(os.path.join(source, ".manifest"))

            # Switch to sha1new
            digest = sha1new.getID(manifest.add_manifest_file(source, sha1new))
            source, badname = os.path.join(self.tmp, digest), source
            os.rename(badname, source)

            cli.do_copy([source, copy])

            self.assertEquals("Hello", file(os.path.join(copy, digest, "MyFile")).read())