##// END OF EJS Templates
vcs: Minimal change to expose the shadow repository...
vcs: Minimal change to expose the shadow repository Based on my original research, this was the "minimal" starting point. It shows that three concepts are needed for the "repo_name": * From the security standpoint we think of the shadow repository having the same ACL as the target repository of the pull request. This is because the pull request itself is considered to be a part of the target repository. Out of this thought, the variable "acl_repo_name" is used whenever we want to check permissions or when we need the database configuration of the repository. An alternative name would have been "db_repo_name", but the usage for ACL checking is the most important one. * From the web interaction perspective, we need the URL which was originally used to get to the repository. This is because based on this base URL commands can be identified. Especially for Git this is important, so that the commands are correctly recognized. Since the URL is in the focus, this is called "url_repo_name". * Finally we have to deal with the repository on the file system. This is what the VCS layer deal with normally, so this name is called "vcs_repo_name". The original repository interaction is a special case where all three names are the same. When interacting with a pull request, these three names are typically all different. This change is minimal in a sense that it just makes the interaction with a shadow repository barely work, without checking any special constraints yet. This was the starting point for further work on this topic.

File last commit:

r1:854a839a default
r887:175782be default
Show More
test_repo_groups.py
223 lines | 7.8 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
# Copyright (C) 2010-2016 RhodeCode GmbH
#
# 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/
import os
from sqlalchemy.exc import IntegrityError
import pytest
from rhodecode.tests import TESTS_TMP_PATH
from rhodecode.tests.fixture import Fixture
from rhodecode.model.repo_group import RepoGroupModel
from rhodecode.model.repo import RepoModel
from rhodecode.model.db import RepoGroup
from rhodecode.model.meta import Session
fixture = Fixture()
def _update_group(id_, group_name, desc='desc', parent_id=None):
form_data = fixture._get_group_create_params(group_name=group_name,
group_desc=desc,
group_parent_id=parent_id)
gr = RepoGroupModel().update(id_, form_data)
return gr
def _update_repo(name, **kwargs):
form_data = fixture._get_repo_create_params(**kwargs)
if 'repo_name' not in kwargs:
form_data['repo_name'] = name
if 'perm_additions' not in kwargs:
form_data['perm_additions'] = []
if 'perm_updates' not in kwargs:
form_data['perm_updates'] = []
if 'perm_deletions' not in kwargs:
form_data['perm_deletions'] = []
r = RepoModel().update(name, **form_data)
return r
class TestRepoGroups:
@pytest.fixture(autouse=True)
def prepare(self, request):
self.g1 = fixture.create_repo_group('test1', skip_if_exists=True)
self.g2 = fixture.create_repo_group('test2', skip_if_exists=True)
self.g3 = fixture.create_repo_group('test3', skip_if_exists=True)
request.addfinalizer(Session.remove)
def __check_path(self, *path):
"""
Checks the path for existance !
"""
path = [TESTS_TMP_PATH] + list(path)
path = os.path.join(*path)
return os.path.isdir(path)
def __delete_group(self, id_):
RepoGroupModel().delete(id_)
def test_create_group(self):
g = fixture.create_repo_group('newGroup')
Session().commit()
assert g.full_path == 'newGroup'
assert self.__check_path('newGroup')
def test_create_same_name_group(self):
with pytest.raises(IntegrityError):
fixture.create_repo_group('newGroup')
Session().rollback()
def test_same_subgroup(self):
sg1 = fixture.create_repo_group('test1/sub1')
assert sg1.parent_group == self.g1
assert sg1.full_path == 'test1/sub1'
assert self.__check_path('test1', 'sub1')
ssg1 = fixture.create_repo_group('test1/sub1/subsub1')
assert ssg1.parent_group == sg1
assert ssg1.full_path == 'test1/sub1/subsub1'
assert self.__check_path('test1', 'sub1', 'subsub1')
def test_remove_group(self):
sg1 = fixture.create_repo_group('deleteme')
self.__delete_group(sg1.group_id)
assert RepoGroup.get(sg1.group_id) is None
assert not self.__check_path('deteteme')
sg1 = fixture.create_repo_group('test1/deleteme')
self.__delete_group(sg1.group_id)
assert RepoGroup.get(sg1.group_id) is None
assert not self.__check_path('test1', 'deteteme')
def test_rename_single_group(self):
sg1 = fixture.create_repo_group('initial')
_update_group(sg1.group_id, 'after')
assert self.__check_path('after')
assert RepoGroup.get_by_group_name('initial') is None
def test_update_group_parent(self):
sg1 = fixture.create_repo_group('test1/initial')
_update_group(sg1.group_id, 'after', parent_id=self.g1.group_id)
assert self.__check_path('test1', 'after')
assert RepoGroup.get_by_group_name('test1/initial') is None
_update_group(sg1.group_id, 'after', parent_id=self.g3.group_id)
assert self.__check_path('test3', 'after')
assert RepoGroup.get_by_group_name('test3/initial') is None
new_sg1 = _update_group(sg1.group_id, 'hello')
assert self.__check_path('hello')
assert RepoGroup.get_by_group_name('hello') == new_sg1
def test_subgrouping_with_repo(self):
g1 = fixture.create_repo_group('g1')
g2 = fixture.create_repo_group('g2')
# create new repo
r = fixture.create_repo('john')
assert r.repo_name == 'john'
# put repo into group
r = _update_repo('john', repo_group=g1.group_id)
Session().commit()
assert r.repo_name == 'g1/john'
_update_group(g1.group_id, 'g1', parent_id=g2.group_id)
assert self.__check_path('g2', 'g1')
# test repo
assert r.repo_name == RepoGroup.url_sep().join(
['g2', 'g1', r.just_name])
def test_move_to_root(self):
fixture.create_repo_group('t11')
g2 = fixture.create_repo_group('t11/t22')
assert g2.full_path == 't11/t22'
assert self.__check_path('t11', 't22')
g2 = _update_group(g2.group_id, 'g22', parent_id=None)
Session().commit()
assert g2.group_name == 'g22'
# we moved out group from t1 to '' so it's full path should be 'g2'
assert g2.full_path == 'g22'
assert not self.__check_path('t11', 't22')
assert self.__check_path('g22')
def test_rename_top_level_group_in_nested_setup(self):
g1 = fixture.create_repo_group('L1')
g2 = fixture.create_repo_group('L1/L2')
g3 = fixture.create_repo_group('L1/L2/L3')
r = fixture.create_repo('L1/L2/L3/L3_REPO', repo_group=g3.group_id)
# rename L1 all groups should be now changed
_update_group(g1.group_id, 'L1_NEW')
Session().commit()
assert g1.full_path == 'L1_NEW'
assert g2.full_path == 'L1_NEW/L2'
assert g3.full_path == 'L1_NEW/L2/L3'
assert r.repo_name == 'L1_NEW/L2/L3/L3_REPO'
def test_change_parent_of_top_level_group_in_nested_setup(self):
g1 = fixture.create_repo_group('R1')
g2 = fixture.create_repo_group('R1/R2')
g3 = fixture.create_repo_group('R1/R2/R3')
g4 = fixture.create_repo_group('R1_NEW')
r = fixture.create_repo('R1/R2/R3/R3_REPO', repo_group=g3.group_id)
# rename L1 all groups should be now changed
_update_group(g1.group_id, 'R1', parent_id=g4.group_id)
Session().commit()
assert g1.full_path == 'R1_NEW/R1'
assert g2.full_path == 'R1_NEW/R1/R2'
assert g3.full_path == 'R1_NEW/R1/R2/R3'
assert r.repo_name == 'R1_NEW/R1/R2/R3/R3_REPO'
def test_change_parent_of_top_level_group_in_nested_setup_with_rename(
self):
g1 = fixture.create_repo_group('X1')
g2 = fixture.create_repo_group('X1/X2')
g3 = fixture.create_repo_group('X1/X2/X3')
g4 = fixture.create_repo_group('X1_NEW')
r = fixture.create_repo('X1/X2/X3/X3_REPO', repo_group=g3.group_id)
# rename L1 all groups should be now changed
_update_group(g1.group_id, 'X1_PRIM', parent_id=g4.group_id)
Session().commit()
assert g1.full_path == 'X1_NEW/X1_PRIM'
assert g2.full_path == 'X1_NEW/X1_PRIM/X2'
assert g3.full_path == 'X1_NEW/X1_PRIM/X2/X3'
assert r.repo_name == 'X1_NEW/X1_PRIM/X2/X3/X3_REPO'