def test_git_sets_default_branch_if_not_master(backend_git, tmpdir, disable_locking, rc_web_server): empty_repo = backend_git.create_repo() clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name) cmd = Command(tmpdir.strpath) cmd.execute('git clone', clone_url) repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name)) repo.in_memory_commit.add(FileNode('file', content='')) repo.in_memory_commit.commit(message='Commit on branch test', author='Automatic test', branch='test') repo_cmd = Command(repo.path) stdout, stderr = repo_cmd.execute('git push --verbose origin test') _check_proper_git_push(stdout, stderr, branch='test', should_set_default_branch=True) stdout, stderr = cmd.execute('git clone', clone_url, empty_repo.repo_name + '-clone') _check_proper_clone(stdout, stderr, 'git') # Doing an explicit commit in order to get latest user logs on MySQL Session().commit()
def test_clone_git_repo_by_id_by_admin(self, rc_web_server, tmpdir): repo_id = Repository.get_by_repo_name(GIT_REPO).repo_id clone_url = rc_web_server.repo_clone_url('_%s' % repo_id) cmd = Command('/tmp') stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath) _check_proper_clone(stdout, stderr, 'git') cmd.assert_returncode_success()
def test_clone_git_repo_shallow_by_admin(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(GIT_REPO) cmd = Command('/tmp') stdout, stderr = cmd.execute('git clone --depth=1', clone_url, tmpdir.strpath) assert '' == stdout assert 'Cloning into' in stderr cmd.assert_returncode_success()
def test_ip_restriction_git(self, rc_web_server, tmpdir): user_model = UserModel() try: user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32') Session().commit() time.sleep(2) clone_url = rc_web_server.repo_clone_url(GIT_REPO) stdout, stderr = Command('/tmp').execute('git clone', clone_url, tmpdir.strpath) msg = "The requested URL returned error: 403" assert msg in stderr finally: # release IP restrictions for ip in UserIpMap.getAll(): UserIpMap.delete(ip.ip_id) Session().commit() time.sleep(2) cmd = Command('/tmp') stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath) cmd.assert_returncode_success() _check_proper_clone(stdout, stderr, 'git')
def test_clone_git_repo_with_group_by_admin(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(GIT_REPO_WITH_GROUP) cmd = Command('/tmp') stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath) _check_proper_clone(stdout, stderr, 'git') cmd.assert_returncode_success()