Esempio 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)
Esempio 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, 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)
Esempio n. 3
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)
Esempio n. 4
0
            # 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())
        finally:
            support.ro_rmtree(copy)


if __name__ == "__main__":
    unittest.main()