Пример #1
0
    def test_fail(self):
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.AllAuth
[kittygit]
repo_dir = %s 
        """.strip() % self.test_dir
        test_settings = fake_settings(settings_str)

        user = '******' % random.randint(0, 100)
        repo_name = 'repo-%d' % random.randint(0, 100)
        repo = '%s/%s.git' % (user, repo_name)
        streams = (sys.stdin, sys.stdout, sys.stderr)
        random_root_patterns = random.randint(1, 100)
        request = Request(user, "kitty-git create-repo 'repo'", test_settings, streams, random_root_patterns)
        settings = handlers.get_settings(request)
        full_repo_dir = utils.get_full_repo_dir(settings, user, repo_name) 

        self.mox.StubOutWithMock(subprocess, 'call')
        subprocess.call(
            args=['git','--git-dir=.', 'init', '--bare'],
            cwd=full_repo_dir,
            stdout=sys.stderr,
            close_fds=True
        ).AndReturn(random.randint(1,100))   

        self.assertRaises(NappingCatException, handlers.create_repo, request, repo_name) 
Пример #2
0
    def test_operation_successful(self):
        test_dir = self.test_dir
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.AllAuth
[kittygit]
repo_dir = %s 
        """.strip() % test_dir
        test_settings = fake_settings(settings_str)

        repo_name = 'something-%d' % random.randint(0, 100)
        full_repo_name = 'random-user-%d/%s' % (random.randint(0, 100), repo_name)

        directory = '%s/%s.git' % (test_dir, full_repo_name)
        with open('/dev/null', 'w') as output:
            operations.create_repository('git', output, output, output, directory)

        other_user = '******' % random.randint(0, 100)
        with open('/dev/null', 'w') as out_stream:
            with open('/dev/null', 'w') as err_stream:
                streams = (sys.stdin, out_stream, err_stream)
                random_root_patterns = random.randint(1, 100)
                request = Request(other_user, 'kitty-git fork', test_settings, streams, random_root_patterns)
                expected_dir = os.path.expanduser('%s/%s/%s.git' % (test_dir, other_user, repo_name))
                result = handlers.fork_repo(request, full_repo_name)

        self.assertTrue(isinstance(result, Response))
        self.assertTrue(repo_name in result.content['message'])
        self.assertTrue(os.path.isdir(directory))
        self.assertTrue(os.path.isdir(expected_dir))
Пример #3
0
    def test_success_with_template_dir(self):
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.AllAuth
[kittygit]
repo_dir = %s 
        """.strip() % self.test_dir
        test_settings = fake_settings(settings_str)

        user = '******' % random.randint(0, 100)
        repo_name = 'repo-%d' % random.randint(0, 100)
        repo = '%s/%s.git' % (user, repo_name)
        with open('/dev/null', 'w') as out_stream:
            with open('/dev/null', 'w') as err_stream:
                streams = (sys.stdin, out_stream, err_stream)
                random_root_patterns = random.randint(1, 100)
                request = Request(user, "kitty-git create-repo 'repo'", test_settings, streams, random_root_patterns)
                settings = handlers.get_settings(request)
                full_repo_dir = utils.get_full_repo_dir(settings, user, repo_name) 

                result = handlers.create_repo(request, repo_name, os.path.join(os.getcwd(), 'tests/support'))
        self.assertTrue(user in result.content['message'])
        self.assertTrue(repo_name in result.content['message'])
        self.assertTrue(os.path.isdir(full_repo_dir))
        self.assertTrue(os.path.isfile('tests/support/hooks/post-commit'))
        import time; time.sleep(1)      # pass the time for a bit for things to 
                                        # flush to disk
        self.assertTrue(os.path.isfile('%s/hooks/post-commit' % full_repo_dir))
Пример #4
0
    def test_unauthorized(self):
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.NoAuth
[kittygit]
        """.strip()

        test_settings = fake_settings(settings_str)
        random_root_patterns = random.randint(1, 100)
        with open('/dev/null', 'rw') as stream:
            request = Request('random-user-%d' % random.randint(0, 100), 'kitty-git fork', test_settings, (stream, stream, stream), random_root_patterns)
            self.assertRaises(KittyGitUnauthorized, handlers.fork_repo, request, 'user-dne/random%d' % random.randint(0,100))
Пример #5
0
    def test_no_permission(self):
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.NoAuth
[kittygit]
        """.strip()
        test_settings = fake_settings(settings_str)
        with open('/dev/null', 'w') as out_stream:
            with open('/dev/null', 'w') as err_stream:
                streams = (sys.stdin, out_stream, err_stream)
                random_root_patterns = random.randint(1, 100)
                request = Request('random-user-%d' % random.randint(0, 100), "kitty-git create-repo 'repo'", test_settings, streams, random_root_patterns)
                self.assertRaises(KittyGitUnauthorized, handlers.create_repo, request, 'repo-%d' % random.randint(0,10))
Пример #6
0
    def test_init(self):
        random_user = random.randint(1,100)
        random_command = random.randint(1,100)
        random_root_patterns = random.randint(1,100)
        random_settings = fake_settings("""
[kittyconfig]
auth = tests.gittests.test_utils.AllAuth
""".strip()) 
        random_stream = random.randint(1, 100)
        req = request.Request(random_user, random_command, random_settings, streams=[random_stream]*3, root_patterns=random_root_patterns) 
        self.assertEqual(req.user, random_user)
        self.assertEqual(req.command, random_command)
        self.assertEqual(req.settings, random_settings)
        self.assertEqual(req.root_patterns, random_root_patterns)

        for key in ('in', 'out', 'err'):
            self.assertEqual(getattr(req, 'std%s'%key), random_stream)
Пример #7
0
    def test_successful(self):
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.AllAuth
[kittygit]
repo_dir = %s 
        """.strip() % self.test_dir
        test_settings = fake_settings(settings_str)
        user = '******' % random.randint(0, 100)
        repo_name = str(random.randint(0,100))
        repo = '%s/%s.git' % (user, repo_name)
        variants = (
            ("git-upload-pack '%s'", "-upload-pack "),
            ("git upload-pack '%s'", " upload-pack "),
            ("git-receive-pack '%s'", "-receive-pack "),
            ("git receive-pack '%s'", " receive-pack "),
        )

        streams = (sys.stdin, sys.stdout, sys.stderr)
        for cmd, action in variants:
            random_root_patterns = random.randint(1, 100)
            request = Request(user, cmd % repo, test_settings, streams, random_root_patterns)
            path = utils.get_full_repo_dir(handlers.get_settings(request), user, repo_name)
            with open('/dev/null', 'w') as output:
                operations.create_repository('git', output, output, output, path, bare=True)
            self.mox.StubOutWithMock(subprocess, 'call')
            subprocess.call(
                args=['git', 'shell', '-c', ' '.join(['git%s'%action.strip(), "'%s'"%path])],
                cwd=path,
                stdout=sys.stdout,
                stderr=sys.stderr,
                stdin=sys.stdin,
            ).AndReturn(0)
            self.mox.ReplayAll()
            result = handlers.handle_git(request, action)

            self.assertTrue(isinstance(result, Response))
            self.assertTrue(user in str(result))
            self.assertTrue(repo_name in str(result))
            self.mox.UnsetStubs()
            shutil.rmtree(path)
Пример #8
0
    def test_bad_repo_raises_bad_parameter(self):
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.AllAuth
[kittygit]
repo_dir = %s 
        """.strip() % self.test_dir
        test_settings = fake_settings(settings_str)
        repo = 'blah/%d.git' % random.randint(0, 100)
        variants = (
            ("git-upload-pack '%s'", "-upload-pack "),
            ("git upload-pack '%s'", " upload-pack "),
            ("git-receive-pack '%s'", "-receive-pack "),
            ("git receive-pack '%s'", " receive-pack "),
        )

        streams = (sys.stdin, sys.stdout, sys.stderr)
        for cmd, action in variants:
            random_root_patterns = random.randint(1, 100)
            request = Request('random-user-%d' % random.randint(0, 100), cmd % repo, test_settings, streams, random_root_patterns)
            self.assertRaises(KittyGitBadParameter, handlers.handle_git, request, action) 
Пример #9
0
    def test_no_permission(self):
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.NoAuth
[kittygit]
        """.strip()
        test_settings = fake_settings(settings_str)

        repo = 'blah/%d.git' % random.randint(0, 100)
        variants = (
            ("git-upload-pack '%s'", "-upload-pack "),
            ("git upload-pack '%s'", " upload-pack "),
            ("git-receive-pack '%s'", "-receive-pack "),
            ("git receive-pack '%s'", " receive-pack "),
        )

        streams = (sys.stdin, sys.stdout, sys.stderr)
        for cmd, action in variants:
            random_root_patterns = random.randint(1, 100)
            request = Request('random-user-%d' % random.randint(0, 100), cmd % repo, test_settings, streams, random_root_patterns)
            self.assertRaises(KittyGitUnauthorized, handlers.handle_git, request, action) 
Пример #10
0
    def test_operation_failed(self):
        test_dir = self.test_dir
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.AllAuth
[kittygit]
repo_dir = %s 
        """.strip() % test_dir
        test_settings = fake_settings(settings_str)

        repo_name = 'something-%d' % random.randint(0, 100)
        full_repo_name = 'random-user-%d/%s' % (random.randint(0, 100), repo_name)
        directory = '%s/%s.git' % (test_dir, full_repo_name)
        other_user = '******' % random.randint(0, 100)
        with open('/dev/null', 'w') as out_stream:
            with open('/dev/null', 'w') as err_stream:
                streams = (sys.stdin, out_stream, err_stream)
                random_root_patterns = random.randint(1, 100)
                request = Request(other_user, 'kitty-git fork', test_settings, streams, random_root_patterns)
                expected_dir = os.path.expanduser('%s/%s/%s.git' % (test_dir, other_user, repo_name))

                self.assertRaises(NappingCatException, handlers.fork_repo, request, full_repo_name)
                self.assertFalse(os.path.isdir(directory))
                self.assertFalse(os.path.isdir(expected_dir))
Пример #11
0
    def test_success(self):
        settings_str = """
[kittyconfig]
auth = tests.gittests.test_utils.AllAuth
[kittygit]
repo_dir = %s 
        """.strip() % self.test_dir
        test_settings = fake_settings(settings_str)

        user = '******' % random.randint(0, 100)
        repo_name = 'repo-%d' % random.randint(0, 100)
        repo = '%s/%s.git' % (user, repo_name)
        with open('/dev/null', 'w') as out_stream:
            with open('/dev/null', 'w') as err_stream:
                streams = (sys.stdin, out_stream, err_stream)
                random_root_patterns = random.randint(1, 100)
                request = Request(user, "kitty-git create-repo 'repo'", test_settings, streams, random_root_patterns)
                settings = handlers.get_settings(request)
                full_repo_dir = utils.get_full_repo_dir(settings, user, repo_name) 

                result = handlers.create_repo(request, repo_name)
        self.assertTrue(user in result.content['message'])
        self.assertTrue(repo_name in result.content['message'])
        self.assertTrue(os.path.isdir(full_repo_dir))