def test_clone_after_repo_was_locked_hg(self, rc_web_server, tmpdir): # lock repo r = Repository.get_by_repo_name(HG_REPO) Repository.lock(r, User.get_by_username(TEST_USER_ADMIN_LOGIN).user_id) # pull fails since repo is locked clone_url = rc_web_server.repo_clone_url(HG_REPO) stdout, stderr = Command('/tmp').execute( 'hg clone', clone_url, tmpdir.strpath) msg = ("""abort: HTTP Error 423: Repository `%s` locked by user `%s`""" % (HG_REPO, TEST_USER_ADMIN_LOGIN)) assert msg in stderr
def test_push_new_file_hg(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(HG_REPO) stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) stdout, stderr = _add_files_and_push('hg', tmpdir.strpath, clone_url=clone_url) assert 'pushing to' in stdout assert 'size summary' in stdout
def test_push_back_to_wrong_url_hg(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(HG_REPO) stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) stdout, stderr = _add_files_and_push( 'hg', tmpdir.strpath, clone_url=rc_web_server.repo_clone_url('not-existing')) assert 'HTTP Error 404: Not Found' in stderr
def test_push_new_file_git(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(GIT_REPO) stdout, stderr = Command('/tmp').execute('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)
def test_ip_restriction_hg(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(HG_REPO) stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) assert 'abort: HTTP Error 403: Forbidden' in stderr finally: # release IP restrictions for ip in UserIpMap.getAll(): UserIpMap.delete(ip.ip_id) Session().commit() time.sleep(2) stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) _check_proper_clone(stdout, stderr, 'hg')
def test_push_wrong_credentials_hg(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(HG_REPO) stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) push_url = rc_web_server.repo_clone_url(HG_REPO, user='******', passwd='name') stdout, stderr = _add_files_and_push('hg', tmpdir.strpath, clone_url=push_url) assert 'abort: authorization failed' in stderr
def test_push_wrong_credentials_git(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(GIT_REPO) stdout, stderr = Command('/tmp').execute('git clone', clone_url, tmpdir.strpath) push_url = rc_web_server.repo_clone_url(GIT_REPO, user='******', passwd='name') stdout, stderr = _add_files_and_push('git', tmpdir.strpath, clone_url=push_url) assert 'fatal: Authentication failed' in stderr
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_and_create_lock_git(self, rc_web_server, tmpdir): # enable locking r = Repository.get_by_repo_name(GIT_REPO) r.enable_locking = True Session().add(r) Session().commit() # clone clone_url = rc_web_server.repo_clone_url(GIT_REPO) stdout, stderr = Command('/tmp').execute( 'git clone', clone_url, tmpdir.strpath) # check if lock was made r = Repository.get_by_repo_name(GIT_REPO) assert r.locked[0] == User.get_by_username( TEST_USER_ADMIN_LOGIN).user_id
def test_clone_after_repo_was_locked_git(self, rc_web_server, tmpdir): # lock repo r = Repository.get_by_repo_name(GIT_REPO) Repository.lock(r, User.get_by_username(TEST_USER_ADMIN_LOGIN).user_id) # pull fails since repo is locked clone_url = rc_web_server.repo_clone_url(GIT_REPO) stdout, stderr = Command('/tmp').execute('git clone', clone_url, tmpdir.strpath) lock_msg = ( 'remote: ERROR: Repository `vcs_test_git` locked by user ' + '`test_admin`. Reason:`lock_auto`') assert lock_msg in stderr assert 'remote: Pre pull hook failed: aborting' in stderr assert 'fatal: remote did not send all necessary objects' in stderr
def test_push_invalidates_cache_hg(self, rc_web_server, tmpdir): key = CacheKey.query().filter(CacheKey.cache_key == HG_REPO).scalar() if not key: key = CacheKey(HG_REPO, HG_REPO) key.cache_active = True Session().add(key) Session().commit() clone_url = rc_web_server.repo_clone_url(HG_REPO) stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) stdout, stderr = _add_files_and_push('hg', tmpdir.strpath, clone_url=clone_url, files_no=1) key = CacheKey.query().filter(CacheKey.cache_key == HG_REPO).one() assert key.cache_active is False
def test_push_on_locked_repo_by_other_user_hg(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(HG_REPO) stdout, stderr = Command('/tmp').execute( 'hg clone', clone_url, tmpdir.strpath) # lock repo r = Repository.get_by_repo_name(HG_REPO) # let this user actually push ! RepoModel().grant_user_permission(repo=r, user=TEST_USER_REGULAR_LOGIN, perm='repository.write') Session().commit() Repository.lock(r, User.get_by_username(TEST_USER_ADMIN_LOGIN).user_id) # push fails repo is locked by other user ! push_url = rc_web_server.repo_clone_url( HG_REPO, user=TEST_USER_REGULAR_LOGIN, passwd=TEST_USER_REGULAR_PASS) stdout, stderr = _add_files_and_push( 'hg', tmpdir.strpath, clone_url=push_url) msg = ("""abort: HTTP Error 423: Repository `%s` locked by user `%s`""" % (HG_REPO, TEST_USER_ADMIN_LOGIN)) assert msg in stderr
def test_push_invalidates_cache_git(self, rc_web_server, tmpdir): key = CacheKey.query().filter(CacheKey.cache_key == GIT_REPO).scalar() if not key: key = CacheKey(GIT_REPO, GIT_REPO) key.cache_active = True Session().add(key) Session().commit() clone_url = rc_web_server.repo_clone_url(GIT_REPO) stdout, stderr = Command('/tmp').execute('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, files_no=1) _check_proper_git_push(stdout, stderr) key = CacheKey.query().filter(CacheKey.cache_key == GIT_REPO).one() assert key.cache_active is False
def test_clone_wrong_credentials_git_ret_code(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(GIT_REPO, passwd='bad!') stdout, stderr = Command('/tmp').execute('git clone', clone_url, tmpdir.strpath) assert 'The requested URL returned error: 403' in stderr
def test_clone_wrong_credentials_hg_ret_code(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(HG_REPO, passwd='bad!') stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) assert 'abort: HTTP Error 403: Forbidden' in stderr
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()
def test_clone_hg_repo_with_group_by_admin(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(HG_REPO_WITH_GROUP) stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) _check_proper_clone(stdout, stderr, 'hg')
def test_clone_hg_repo_by_id_by_admin(self, rc_web_server, tmpdir): repo_id = Repository.get_by_repo_name(HG_REPO).repo_id clone_url = rc_web_server.repo_clone_url('_%s' % repo_id) stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) _check_proper_clone(stdout, stderr, 'hg')
def test_clone_wrong_credentials_hg(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(HG_REPO, passwd='bad!') stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) assert 'abort: authorization failed' in stderr
def test_clone_wrong_credentials_git(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(GIT_REPO, passwd='bad!') stdout, stderr = Command('/tmp').execute('git clone', clone_url, tmpdir.strpath) assert 'fatal: Authentication failed' in stderr
def test_clone_git_dir_as_hg(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(GIT_REPO) stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) assert 'HTTP Error 404: Not Found' in stderr
def test_clone_hg_repo_as_git(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url(HG_REPO) stdout, stderr = Command('/tmp').execute('git clone', clone_url, tmpdir.strpath) assert 'not found' in stderr
def test_clone_non_existing_path_hg(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url('trololo') stdout, stderr = Command('/tmp').execute('hg clone', clone_url, tmpdir.strpath) assert 'HTTP Error 404: Not Found' in stderr
def test_clone_non_existing_path_git(self, rc_web_server, tmpdir): clone_url = rc_web_server.repo_clone_url('trololo') stdout, stderr = Command('/tmp').execute('git clone', clone_url) assert 'not found' in stderr