Exemple #1
0
    def test_run_command_password(self):
        if sys.platform == 'win32':
            binary = ['plink.exe', '-ssh']
        else:
            binary = ['plink', '-ssh']
        expected = binary + ['-pw', '12345', 'host', 'git-clone-url']

        vendor = PLinkSSHVendor()

        warnings.simplefilter("always", UserWarning)
        self.addCleanup(warnings.resetwarnings)
        warnings_list, restore_warnings = setup_warning_catcher()
        self.addCleanup(restore_warnings)

        command = vendor.run_command('host', 'git-clone-url', password='******')

        expected_warning = UserWarning(
            'Invoking PLink with a password exposes the password in the '
            'process list.')

        for w in warnings_list:
            if (type(w) == type(expected_warning)
                    and w.args == expected_warning.args):
                break
        else:
            raise AssertionError('Expected warning %r not in %r' %
                                 (expected_warning, warnings_list))

        args = command.proc.args

        self.assertListEqual(expected, args[0])
Exemple #2
0
    def test_run_command_password(self):
        if sys.platform == 'win32':
            binary = ['putty.exe', '-ssh']
        else:
            binary = ['putty', '-ssh']
        expected = binary + ['-pw', '12345', 'host', 'git-clone-url']

        vendor = PuttySSHVendor()

        warnings.simplefilter("always", UserWarning)
        self.addCleanup(warnings.resetwarnings)
        warnings_list, restore_warnings = setup_warning_catcher()
        self.addCleanup(restore_warnings)

        command = vendor.run_command('host', 'git-clone-url', password='******')

        expected_warning = UserWarning(
            'Invoking Putty with a password exposes the password in the '
            'process list.')

        for w in warnings_list:
            if (type(w) == type(expected_warning) and
                    w.args == expected_warning.args):
                break
        else:
            raise AssertionError(
                'Expected warning %r not in %r' %
                (expected_warning, warnings_list))

        args = command.proc.args

        self.assertListEqual(expected, args[0])
Exemple #3
0
    def test_shell_hook_post_commit(self):
        if os.name != 'posix':
            self.skipTest('shell hook tests requires POSIX shell')

        repo_dir = os.path.join(tempfile.mkdtemp())
        r = Repo.init(repo_dir)
        self.addCleanup(shutil.rmtree, repo_dir)

        (fd, path) = tempfile.mkstemp(dir=repo_dir)
        post_commit_msg = b"""#!/bin/sh
rm """ + path.encode(sys.getfilesystemencoding()) + b"""
"""

        root_sha = r.do_commit(
            b'empty commit',
            committer=b'Test Committer <*****@*****.**>',
            author=b'Test Author <*****@*****.**>',
            commit_timestamp=12345, commit_timezone=0,
            author_timestamp=12345, author_timezone=0)
        self.assertEqual([], r[root_sha].parents)

        post_commit = os.path.join(r.controldir(), 'hooks', 'post-commit')

        with open(post_commit, 'wb') as f:
            f.write(post_commit_msg)
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        commit_sha = r.do_commit(
            b'empty commit',
            committer=b'Test Committer <*****@*****.**>',
            author=b'Test Author <*****@*****.**>',
            commit_timestamp=12345, commit_timezone=0,
            author_timestamp=12345, author_timezone=0)
        self.assertEqual([root_sha], r[commit_sha].parents)

        self.assertFalse(os.path.exists(path))

        post_commit_msg_fail = b"""#!/bin/sh
exit 1
"""
        with open(post_commit, 'wb') as f:
            f.write(post_commit_msg_fail)
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        warnings.simplefilter("always", UserWarning)
        self.addCleanup(warnings.resetwarnings)
        warnings_list, restore_warnings = setup_warning_catcher()
        self.addCleanup(restore_warnings)

        commit_sha2 = r.do_commit(
            b'empty commit',
            committer=b'Test Committer <*****@*****.**>',
            author=b'Test Author <*****@*****.**>',
            commit_timestamp=12345, commit_timezone=0,
            author_timestamp=12345, author_timezone=0)
        self.assertEqual(len(warnings_list), 1, warnings_list)
        self.assertIsInstance(warnings_list[-1], UserWarning)
        self.assertTrue("post-commit hook failed: " in str(warnings_list[-1]))
        self.assertEqual([commit_sha], r[commit_sha2].parents)
Exemple #4
0
    def test_iterblobs(self):
        warnings.simplefilter("always", UserWarning)
        self.addCleanup(warnings.resetwarnings)
        warnings_list, restore_warnings = setup_warning_catcher()
        self.addCleanup(restore_warnings)

        self.assertEqual(
            [(b'bla', b'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391', 33188)],
            list(self.get_simple_index("index").iterblobs()))

        expected_warning = PendingDeprecationWarning(
            'Use iterobjects() instead.')
        for w in warnings_list:
            if (type(w) == type(expected_warning)
                    and w.args == expected_warning.args):
                break
        else:
            raise AssertionError('Expected warning %r not in %r' %
                                 (expected_warning, warnings_list))
Exemple #5
0
    def test_iterblobs(self):
        warnings.simplefilter("always", UserWarning)
        self.addCleanup(warnings.resetwarnings)
        warnings_list, restore_warnings = setup_warning_catcher()
        self.addCleanup(restore_warnings)

        self.assertEqual(
                [(b'bla', b'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391', 33188)],
                list(self.get_simple_index("index").iterblobs()))

        expected_warning = PendingDeprecationWarning(
            'Use iterobjects() instead.')
        for w in warnings_list:
            if (type(w) == type(expected_warning) and
                    w.args == expected_warning.args):
                break
        else:
            raise AssertionError(
                'Expected warning %r not in %r' %
                (expected_warning, warnings_list))
    def test_shell_hook_post_commit(self):
        if os.name != 'posix':
            self.skipTest('shell hook tests requires POSIX shell')

        repo_dir = os.path.join(tempfile.mkdtemp())
        r = Repo.init(repo_dir)
        self.addCleanup(shutil.rmtree, repo_dir)

        (fd, path) = tempfile.mkstemp(dir=repo_dir)
        post_commit_msg = """#!/bin/sh
unlink %(file)s
""" % {'file': path}

        root_sha = r.do_commit('empty commit',
                               committer='Test Committer <*****@*****.**>',
                               author='Test Author <*****@*****.**>',
                               commit_timestamp=12345,
                               commit_timezone=0,
                               author_timestamp=12345,
                               author_timezone=0)
        self.assertEqual([], r[root_sha].parents)

        post_commit = os.path.join(r.controldir(), 'hooks', 'post-commit')

        f = open(post_commit, 'wb')
        try:
            f.write(post_commit_msg)
        finally:
            f.close()
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        commit_sha = r.do_commit(
            'empty commit',
            committer='Test Committer <*****@*****.**>',
            author='Test Author <*****@*****.**>',
            commit_timestamp=12345,
            commit_timezone=0,
            author_timestamp=12345,
            author_timezone=0)
        self.assertEqual([root_sha], r[commit_sha].parents)

        self.assertFalse(os.path.exists(path))

        post_commit_msg_fail = """#!/bin/sh
exit 1
"""
        f = open(post_commit, 'wb')
        try:
            f.write(post_commit_msg_fail)
        finally:
            f.close()
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        warnings.simplefilter("always", UserWarning)
        self.addCleanup(warnings.resetwarnings)
        warnings_list = setup_warning_catcher()

        commit_sha2 = r.do_commit(
            'empty commit',
            committer='Test Committer <*****@*****.**>',
            author='Test Author <*****@*****.**>',
            commit_timestamp=12345,
            commit_timezone=0,
            author_timestamp=12345,
            author_timezone=0)
        self.assertEqual(len(warnings_list), 1)
        self.assertIsInstance(warnings_list[-1], UserWarning)
        self.assertTrue("post-commit hook failed: " in str(warnings_list[-1]))
        self.assertEqual([commit_sha], r[commit_sha2].parents)
Exemple #7
0
    def test_shell_hook_post_commit(self):
        if os.name != 'posix':
            self.skipTest('shell hook tests requires POSIX shell')

        repo_dir = self.mkdtemp()
        self.addCleanup(shutil.rmtree, repo_dir)

        r = Repo.init(repo_dir)
        self.addCleanup(r.close)

        (fd, path) = tempfile.mkstemp(dir=repo_dir)
        os.close(fd)
        post_commit_msg = """#!/bin/sh
rm """ + path + """
"""

        root_sha = r.do_commit(
            b'empty commit',
            committer=b'Test Committer <*****@*****.**>',
            author=b'Test Author <*****@*****.**>',
            commit_timestamp=12345, commit_timezone=0,
            author_timestamp=12345, author_timezone=0)
        self.assertEqual([], r[root_sha].parents)

        post_commit = os.path.join(r.controldir(), 'hooks', 'post-commit')

        with open(post_commit, 'wb') as f:
            f.write(post_commit_msg.encode(locale.getpreferredencoding()))
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        commit_sha = r.do_commit(
            b'empty commit',
            committer=b'Test Committer <*****@*****.**>',
            author=b'Test Author <*****@*****.**>',
            commit_timestamp=12345, commit_timezone=0,
            author_timestamp=12345, author_timezone=0)
        self.assertEqual([root_sha], r[commit_sha].parents)

        self.assertFalse(os.path.exists(path))

        post_commit_msg_fail = """#!/bin/sh
exit 1
"""
        with open(post_commit, 'w') as f:
            f.write(post_commit_msg_fail)
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        warnings.simplefilter("always", UserWarning)
        self.addCleanup(warnings.resetwarnings)
        warnings_list, restore_warnings = setup_warning_catcher()
        self.addCleanup(restore_warnings)

        commit_sha2 = r.do_commit(
            b'empty commit',
            committer=b'Test Committer <*****@*****.**>',
            author=b'Test Author <*****@*****.**>',
            commit_timestamp=12345, commit_timezone=0,
            author_timestamp=12345, author_timezone=0)
        expected_warning = UserWarning(
            'post-commit hook failed: Hook post-commit exited with '
            'non-zero status 1',)
        for w in warnings_list:
            if (type(w) == type(expected_warning) and
                    w.args == expected_warning.args):
                break
        else:
            raise AssertionError(
                'Expected warning %r not in %r' %
                (expected_warning, warnings_list))
        self.assertEqual([commit_sha], r[commit_sha2].parents)
Exemple #8
0
    def test_shell_hook_post_commit(self):
        if os.name != 'posix':
            self.skipTest('shell hook tests requires POSIX shell')

        repo_dir = self.mkdtemp()
        if isinstance(repo_dir, bytes):
            repo_dir_str = repo_dir.decode(sys.getfilesystemencoding())
        else:
            repo_dir_str = repo_dir

        r = Repo.init(repo_dir)
        self.addCleanup(shutil.rmtree, repo_dir)

        (fd, path) = tempfile.mkstemp(dir=repo_dir_str)
        os.close(fd)
        post_commit_msg = """#!/bin/sh
rm """ + path + """
"""

        root_sha = r.do_commit(b'empty commit',
                               committer=b'Test Committer <*****@*****.**>',
                               author=b'Test Author <*****@*****.**>',
                               commit_timestamp=12345,
                               commit_timezone=0,
                               author_timestamp=12345,
                               author_timezone=0)
        self.assertEqual([], r[root_sha].parents)

        post_commit = os.path.join(r.controldir(), b'hooks', b'post-commit')

        with open(post_commit, 'w') as f:
            f.write(post_commit_msg)
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        commit_sha = r.do_commit(
            b'empty commit',
            committer=b'Test Committer <*****@*****.**>',
            author=b'Test Author <*****@*****.**>',
            commit_timestamp=12345,
            commit_timezone=0,
            author_timestamp=12345,
            author_timezone=0)
        self.assertEqual([root_sha], r[commit_sha].parents)

        self.assertFalse(os.path.exists(path))

        post_commit_msg_fail = """#!/bin/sh
exit 1
"""
        with open(post_commit, 'w') as f:
            f.write(post_commit_msg_fail)
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        warnings.simplefilter("always", UserWarning)
        self.addCleanup(warnings.resetwarnings)
        warnings_list, restore_warnings = setup_warning_catcher()
        self.addCleanup(restore_warnings)

        commit_sha2 = r.do_commit(
            b'empty commit',
            committer=b'Test Committer <*****@*****.**>',
            author=b'Test Author <*****@*****.**>',
            commit_timestamp=12345,
            commit_timezone=0,
            author_timestamp=12345,
            author_timezone=0)
        self.assertEqual(len(warnings_list), 1, warnings_list)
        self.assertIsInstance(warnings_list[-1], UserWarning)
        self.assertTrue("post-commit hook failed: " in str(warnings_list[-1]))
        self.assertEqual([commit_sha], r[commit_sha2].parents)
Exemple #9
0
    def test_shell_hook_post_commit(self):
        if os.name != 'posix':
            self.skipTest('shell hook tests requires POSIX shell')

        repo_dir = self.mkdtemp()
        self.addCleanup(shutil.rmtree, repo_dir)

        r = Repo.init(repo_dir)
        self.addCleanup(r.close)

        (fd, path) = tempfile.mkstemp(dir=repo_dir)
        os.close(fd)
        post_commit_msg = """#!/bin/sh
rm """ + path + """
"""

        root_sha = r.do_commit(
            b'empty commit',
            committer=b'Test Committer <*****@*****.**>',
            author=b'Test Author <*****@*****.**>',
            commit_timestamp=12345, commit_timezone=0,
            author_timestamp=12345, author_timezone=0)
        self.assertEqual([], r[root_sha].parents)

        post_commit = os.path.join(r.controldir(), 'hooks', 'post-commit')

        with open(post_commit, 'wb') as f:
            f.write(post_commit_msg.encode(locale.getpreferredencoding()))
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        commit_sha = r.do_commit(
            b'empty commit',
            committer=b'Test Committer <*****@*****.**>',
            author=b'Test Author <*****@*****.**>',
            commit_timestamp=12345, commit_timezone=0,
            author_timestamp=12345, author_timezone=0)
        self.assertEqual([root_sha], r[commit_sha].parents)

        self.assertFalse(os.path.exists(path))

        post_commit_msg_fail = """#!/bin/sh
exit 1
"""
        with open(post_commit, 'w') as f:
            f.write(post_commit_msg_fail)
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        warnings.simplefilter("always", UserWarning)
        self.addCleanup(warnings.resetwarnings)
        warnings_list, restore_warnings = setup_warning_catcher()
        self.addCleanup(restore_warnings)

        commit_sha2 = r.do_commit(
            b'empty commit',
            committer=b'Test Committer <*****@*****.**>',
            author=b'Test Author <*****@*****.**>',
            commit_timestamp=12345, commit_timezone=0,
            author_timestamp=12345, author_timezone=0)
        expected_warning = UserWarning(
            'post-commit hook failed: Hook post-commit exited with '
            'non-zero status',)
        for w in warnings_list:
            if (type(w) == type(expected_warning) and
                    w.args == expected_warning.args):
                break
        else:
            raise AssertionError(
                'Expected warning %r not in %r' %
                (expected_warning, warnings_list))
        self.assertEqual([commit_sha], r[commit_sha2].parents)
Exemple #10
0
    def test_shell_hook_post_commit(self):
        if os.name != "posix":
            self.skipTest("shell hook tests requires POSIX shell")

        repo_dir = os.path.join(tempfile.mkdtemp())
        r = Repo.init(repo_dir)
        self.addCleanup(shutil.rmtree, repo_dir)

        (fd, path) = tempfile.mkstemp(dir=repo_dir)
        post_commit_msg = """#!/bin/sh
rm %(file)s
""" % {
            "file": path
        }

        root_sha = r.do_commit(
            "empty commit",
            committer="Test Committer <*****@*****.**>",
            author="Test Author <*****@*****.**>",
            commit_timestamp=12345,
            commit_timezone=0,
            author_timestamp=12345,
            author_timezone=0,
        )
        self.assertEqual([], r[root_sha].parents)

        post_commit = os.path.join(r.controldir(), "hooks", "post-commit")

        f = open(post_commit, "wb")
        try:
            f.write(post_commit_msg)
        finally:
            f.close()
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        commit_sha = r.do_commit(
            "empty commit",
            committer="Test Committer <*****@*****.**>",
            author="Test Author <*****@*****.**>",
            commit_timestamp=12345,
            commit_timezone=0,
            author_timestamp=12345,
            author_timezone=0,
        )
        self.assertEqual([root_sha], r[commit_sha].parents)

        self.assertFalse(os.path.exists(path))

        post_commit_msg_fail = """#!/bin/sh
exit 1
"""
        f = open(post_commit, "wb")
        try:
            f.write(post_commit_msg_fail)
        finally:
            f.close()
        os.chmod(post_commit, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)

        warnings.simplefilter("always", UserWarning)
        self.addCleanup(warnings.resetwarnings)
        warnings_list, restore_warnings = setup_warning_catcher()
        self.addCleanup(restore_warnings)

        commit_sha2 = r.do_commit(
            "empty commit",
            committer="Test Committer <*****@*****.**>",
            author="Test Author <*****@*****.**>",
            commit_timestamp=12345,
            commit_timezone=0,
            author_timestamp=12345,
            author_timezone=0,
        )
        self.assertEqual(len(warnings_list), 1)
        self.assertIsInstance(warnings_list[-1], UserWarning)
        self.assertTrue("post-commit hook failed: " in str(warnings_list[-1]))
        self.assertEqual([commit_sha], r[commit_sha2].parents)