##// END OF EJS Templates
deps: bumped psycopg2==2.10.0 for python 3.13 compat
deps: bumped psycopg2==2.10.0 for python 3.13 compat

File last commit:

r5608:6d33e504 default
r5621:c6f79eaa default
Show More
test_vcs_operations_git.py
200 lines | 8.0 KiB | text/x-python | PythonLexer
/ rhodecode / tests / vcs_operations / test_vcs_operations_git.py
core: updated copyright to 2024
r5608 # Copyright (C) 2010-2024 RhodeCode GmbH
fix(svn): svn events fixes and change the way how we handle the events
r5459 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
"""
Test suite for making push/pull operations, on specially modified INI files
.. important::
You must have git >= 1.8.5 for tests to work fine. With 68b939b git started
to redirect things to stderr instead of stdout.
"""
import time
import pytest
from rhodecode.model.db import Repository, UserIpMap
from rhodecode.model.meta import Session
from rhodecode.model.repo import RepoModel
from rhodecode.model.user import UserModel
from rhodecode.tests import (GIT_REPO, TEST_USER_ADMIN_LOGIN)
from rhodecode.tests.vcs_operations import (
Command, _check_proper_clone, _check_proper_git_push,
_add_files_and_push, GIT_REPO_WITH_GROUP)
tests: fixed test suite for celery adoption
r5607 @pytest.mark.usefixtures(
"init_pyramid_app",
"repo_group_repos",
"disable_anonymous_user",
"disable_locking",
)
class TestVCSOperationsGit:
fix(svn): svn events fixes and change the way how we handle the events
r5459
tests: fixed test suite for celery adoption
r5607 def test_clone_git_repo_by_admin(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url(GIT_REPO)
cmd = Command(tmpdir.strpath)
fix(svn): svn events fixes and change the way how we handle the events
r5459 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
_check_proper_clone(stdout, stderr, 'git')
cmd.assert_returncode_success()
tests: fixed test suite for celery adoption
r5607 def test_clone_git_repo_by_admin_with_git_suffix(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url(GIT_REPO)
cmd = Command(tmpdir.strpath)
fix(svn): svn events fixes and change the way how we handle the events
r5459 stdout, stderr = cmd.execute('git clone', clone_url+".git", tmpdir.strpath)
_check_proper_clone(stdout, stderr, 'git')
cmd.assert_returncode_success()
tests: fixed test suite for celery adoption
r5607 def test_clone_git_repo_by_id_by_admin(self, rcstack, tmpdir):
fix(svn): svn events fixes and change the way how we handle the events
r5459 repo_id = Repository.get_by_repo_name(GIT_REPO).repo_id
tests: fixed test suite for celery adoption
r5607 clone_url = rcstack.repo_clone_url('_%s' % repo_id)
cmd = Command(tmpdir.strpath)
fix(svn): svn events fixes and change the way how we handle the events
r5459 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
_check_proper_clone(stdout, stderr, 'git')
cmd.assert_returncode_success()
tests: fixed test suite for celery adoption
r5607 def test_clone_git_repo_with_group_by_admin(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url(GIT_REPO_WITH_GROUP)
cmd = Command(tmpdir.strpath)
fix(svn): svn events fixes and change the way how we handle the events
r5459 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
_check_proper_clone(stdout, stderr, 'git')
cmd.assert_returncode_success()
tests: fixed test suite for celery adoption
r5607 def test_clone_git_repo_shallow_by_admin(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url(GIT_REPO)
cmd = Command(tmpdir.strpath)
fix(svn): svn events fixes and change the way how we handle the events
r5459 stdout, stderr = cmd.execute(
'git clone --depth=1', clone_url, tmpdir.strpath)
assert '' == stdout
assert 'Cloning into' in stderr
cmd.assert_returncode_success()
tests: fixed test suite for celery adoption
r5607 def test_clone_wrong_credentials_git(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url(GIT_REPO, passwd='bad!')
stdout, stderr = Command(tmpdir.strpath).execute(
fix(svn): svn events fixes and change the way how we handle the events
r5459 'git clone', clone_url, tmpdir.strpath)
assert 'fatal: Authentication failed' in stderr
tests: fixed test suite for celery adoption
r5607 def test_clone_git_dir_as_hg(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url(GIT_REPO)
stdout, stderr = Command(tmpdir.strpath).execute(
fix(svn): svn events fixes and change the way how we handle the events
r5459 'hg clone', clone_url, tmpdir.strpath)
assert 'HTTP Error 404: Not Found' in stderr
tests: fixed test suite for celery adoption
r5607 def test_clone_non_existing_path_hg(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url('trololo')
stdout, stderr = Command(tmpdir.strpath).execute(
fix(svn): svn events fixes and change the way how we handle the events
r5459 'hg clone', clone_url, tmpdir.strpath)
assert 'HTTP Error 404: Not Found' in stderr
tests: fixed test suite for celery adoption
r5607 def test_clone_non_existing_path_git(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url('trololo')
stdout, stderr = Command(tmpdir.strpath).execute('git clone', clone_url)
fix(svn): svn events fixes and change the way how we handle the events
r5459 assert 'not found' in stderr
tests: fixed test suite for celery adoption
r5607 def test_clone_git_with_slashes(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url('//' + GIT_REPO)
stdout, stderr = Command(tmpdir.strpath).execute('git clone', clone_url)
fix(svn): svn events fixes and change the way how we handle the events
r5459 assert 'not found' in stderr
def test_clone_existing_path_git_not_in_database(
tests: fixed test suite for celery adoption
r5607 self, rcstack, tmpdir, fs_repo_only):
fix(svn): svn events fixes and change the way how we handle the events
r5459 db_name = fs_repo_only('not-in-db-git', repo_type='git')
tests: fixed test suite for celery adoption
r5607 clone_url = rcstack.repo_clone_url(db_name)
stdout, stderr = Command(tmpdir.strpath).execute(
fix(svn): svn events fixes and change the way how we handle the events
r5459 'git clone', clone_url, tmpdir.strpath)
assert 'not found' in stderr
def test_clone_existing_path_git_not_in_database_different_scm(
tests: fixed test suite for celery adoption
r5607 self, rcstack, tmpdir, fs_repo_only):
fix(svn): svn events fixes and change the way how we handle the events
r5459 db_name = fs_repo_only('not-in-db-hg', repo_type='hg')
tests: fixed test suite for celery adoption
r5607 clone_url = rcstack.repo_clone_url(db_name)
stdout, stderr = Command(tmpdir.strpath).execute(
fix(svn): svn events fixes and change the way how we handle the events
r5459 'git clone', clone_url, tmpdir.strpath)
assert 'not found' in stderr
tests: fixed test suite for celery adoption
r5607 def test_clone_non_existing_store_path_git(self, rcstack, tmpdir, user_util):
fix(svn): svn events fixes and change the way how we handle the events
r5459 repo = user_util.create_repo(repo_type='git')
tests: fixed test suite for celery adoption
r5607 clone_url = rcstack.repo_clone_url(repo.repo_name)
fix(svn): svn events fixes and change the way how we handle the events
r5459
# Damage repo by removing it's folder
RepoModel()._delete_filesystem_repo(repo)
tests: fixed test suite for celery adoption
r5607 stdout, stderr = Command(tmpdir.strpath).execute(
fix(svn): svn events fixes and change the way how we handle the events
r5459 'git clone', clone_url, tmpdir.strpath)
assert 'not found' in stderr
tests: fixed test suite for celery adoption
r5607 def test_push_new_file_git(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url(GIT_REPO)
stdout, stderr = Command(tmpdir.strpath).execute(
fix(svn): svn events fixes and change the way how we handle the events
r5459 'git clone', clone_url, tmpdir.strpath)
# commit some stuff into this repo
stdout, stderr = _add_files_and_push(
'git', tmpdir.strpath, clone_url=clone_url)
_check_proper_git_push(stdout, stderr)
tests: fixed test suite for celery adoption
r5607 def test_push_wrong_credentials_git(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url(GIT_REPO)
stdout, stderr = Command(tmpdir.strpath).execute(
fix(svn): svn events fixes and change the way how we handle the events
r5459 'git clone', clone_url, tmpdir.strpath)
tests: fixed test suite for celery adoption
r5607 push_url = rcstack.repo_clone_url(
fix(svn): svn events fixes and change the way how we handle the events
r5459 GIT_REPO, user='bad', passwd='name')
stdout, stderr = _add_files_and_push(
'git', tmpdir.strpath, clone_url=push_url)
assert 'fatal: Authentication failed' in stderr
tests: fixed test suite for celery adoption
r5607 def test_push_back_to_wrong_url_git(self, rcstack, tmpdir):
clone_url = rcstack.repo_clone_url(GIT_REPO)
stdout, stderr = Command(tmpdir.strpath).execute(
fix(svn): svn events fixes and change the way how we handle the events
r5459 'git clone', clone_url, tmpdir.strpath)
stdout, stderr = _add_files_and_push(
'git', tmpdir.strpath,
tests: fixed test suite for celery adoption
r5607 clone_url=rcstack.repo_clone_url('not-existing'))
fix(svn): svn events fixes and change the way how we handle the events
r5459
assert 'not found' in stderr
tests: fixed test suite for celery adoption
r5607 def test_ip_restriction_git(self, rcstack, tmpdir):
fix(svn): svn events fixes and change the way how we handle the events
r5459 user_model = UserModel()
try:
user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
Session().commit()
time.sleep(2)
tests: fixed test suite for celery adoption
r5607 clone_url = rcstack.repo_clone_url(GIT_REPO)
stdout, stderr = Command(tmpdir.strpath).execute(
fix(svn): svn events fixes and change the way how we handle the events
r5459 '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)
tests: fixed test suite for celery adoption
r5607 cmd = Command(tmpdir.strpath)
fix(svn): svn events fixes and change the way how we handle the events
r5459 stdout, stderr = cmd.execute('git clone', clone_url, tmpdir.strpath)
cmd.assert_returncode_success()
_check_proper_clone(stdout, stderr, 'git')