Esempio n. 1
0
    def testAdd(self):
        sample = os.path.join(self.tmp, "sample")
        os.mkdir(sample)
        self.populate_sample(sample)
        cli.init_stores()
        digest = "sha1new=7e3eb25a072988f164bae24d33af69c1814eb99a"
        try:
            cli.stores.lookup(digest)
            assert False
        except NotStored:
            pass

        logger.setLevel(logging.ERROR)
        try:
            cli.do_add([digest + "b", sample])
            assert False
        except BadDigest:
            pass
        logger.setLevel(logging.WARN)

        old_stdout = sys.stdout

        cli.do_add([digest, sample])
        sys.stdout = StringIO()
        try:
            cli.do_find([digest])
            assert False
        except SystemExit, ex:
            assert ex.code == 0
Esempio n. 2
0
	def testAdd(self):
		sample = os.path.join(self.tmp, 'sample')
		os.mkdir(sample)
		self.populate_sample(sample)
		cli.init_stores()
		digest = 'sha1new=7e3eb25a072988f164bae24d33af69c1814eb99a'
		try:
			cli.stores.lookup(digest)
			assert False
		except NotStored:
			pass

		logger.setLevel(logging.ERROR)
		try:
			cli.do_add([digest + "b", sample])
			assert False
		except BadDigest:
			pass
		logger.setLevel(logging.WARN)

		old_stdout = sys.stdout

		cli.do_add([digest, sample])
		sys.stdout = StringIO()
		try:
			cli.do_find([digest])
			assert False
		except SystemExit as ex:
			assert ex.code == 0
		cached = sys.stdout.getvalue().strip()
		assert cached == cli.stores.lookup(digest)

		for alg in [[], ['sha1new']]:
			sys.stdout = StringIO()
			try:
				cli.do_manifest([cached] + alg)
				assert False
			except SystemExit as ex:
				assert ex.code == 0
			result = sys.stdout.getvalue()
			assert 'MyFile' in result
			assert result.split('\n')[-2] == digest

		# Verify...
		sys.stdout = StringIO()
		cli.do_verify([cached, digest])
		cli.do_verify([cached])
		cli.do_verify([digest])

		# Full audit
		cli.do_audit([os.path.dirname(cached)])

		# Corrupt it...
		os.chmod(cached, 0o700)
		open(os.path.join(cached, 'hacked'), 'w').close()

		# Verify again...
		sys.stdout = StringIO()
		try:
			cli.do_verify([cached, digest])
			assert False
		except SystemExit as ex:
			assert ex.code == 1
			result = sys.stdout.getvalue()
			sys.stdout = old_stdout
			assert 'Cached item does NOT verify' in result

		# Full audit
		sys.stdout = StringIO()
		try:
			cli.do_audit([os.path.dirname(cached)])
		except SystemExit as ex:
			assert ex.code == 1
			result = sys.stdout.getvalue()
			sys.stdout = old_stdout
			assert 'Cached item does NOT verify' in result
Esempio n. 3
0
    def testAdd(self):
        sample = os.path.join(self.tmp, 'sample')
        os.mkdir(sample)
        self.populate_sample(sample)
        cli.init_stores()
        digest = 'sha1new=7e3eb25a072988f164bae24d33af69c1814eb99a'
        try:
            cli.stores.lookup(digest)
            assert False
        except NotStored:
            pass

        logger.setLevel(logging.ERROR)
        try:
            cli.do_add([digest + "b", sample])
            assert False
        except BadDigest:
            pass
        logger.setLevel(logging.WARN)

        old_stdout = sys.stdout

        cli.do_add([digest, sample])
        sys.stdout = StringIO()
        try:
            cli.do_find([digest])
            assert False
        except SystemExit as ex:
            assert ex.code == 0
        cached = sys.stdout.getvalue().strip()
        assert cached == cli.stores.lookup(digest)

        for alg in [[], ['sha1new']]:
            sys.stdout = StringIO()
            try:
                cli.do_manifest([cached] + alg)
                assert False
            except SystemExit as ex:
                assert ex.code == 0
            result = sys.stdout.getvalue()
            assert 'MyFile' in result
            assert result.split('\n')[-2] == digest

        # Verify...
        sys.stdout = StringIO()
        cli.do_verify([cached, digest])
        cli.do_verify([cached])
        cli.do_verify([digest])

        # Full audit
        cli.do_audit([os.path.dirname(cached)])

        # Corrupt it...
        os.chmod(cached, 0o700)
        open(os.path.join(cached, 'hacked'), 'w').close()

        # Verify again...
        sys.stdout = StringIO()
        try:
            cli.do_verify([cached, digest])
            assert False
        except SystemExit as ex:
            assert ex.code == 1
            result = sys.stdout.getvalue()
            sys.stdout = old_stdout
            assert 'Cached item does NOT verify' in result

        # Full audit
        sys.stdout = StringIO()
        try:
            cli.do_audit([os.path.dirname(cached)])
        except SystemExit as ex:
            assert ex.code == 1
            result = sys.stdout.getvalue()
            sys.stdout = old_stdout
            assert 'Cached item does NOT verify' in result