##// 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:

r824:9a53b89b default
r887:175782be default
Show More
test_changelog.py
192 lines | 7.3 KiB | text/x-python | PythonLexer
# -*- 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 re
import pytest
from rhodecode.controllers.changelog import DEFAULT_CHANGELOG_SIZE
from rhodecode.tests import url, TestController
from rhodecode.tests.utils import AssertResponse
MATCH_HASH = re.compile(r'<span class="commit_hash">r(\d+):[\da-f]+</span>')
class TestChangelogController(TestController):
def test_index(self, backend):
self.log_user()
response = self.app.get(url(controller='changelog', action='index',
repo_name=backend.repo_name))
first_idx = -1
last_idx = -DEFAULT_CHANGELOG_SIZE
self.assert_commit_range_on_page(
response, first_idx, last_idx, backend)
@pytest.mark.backends("hg", "git")
def test_index_filtered_by_branch(self, backend):
self.log_user()
self.app.get(
url(
controller='changelog',
action='index',
repo_name=backend.repo_name,
branch=backend.default_branch_name),
status=200)
@pytest.mark.backends("svn")
def test_index_filtered_by_branch_svn(self, autologin_user, backend):
repo = backend['svn-simple-layout']
response = self.app.get(
url(
controller='changelog',
action='index',
repo_name=repo.repo_name,
branch='trunk'),
status=200)
self.assert_commits_on_page(
response, indexes=[15, 12, 7, 3, 2, 1])
def test_index_filtered_by_wrong_branch(self, backend):
self.log_user()
branch = 'wrong-branch-name'
response = self.app.get(
url(
controller='changelog',
action='index',
repo_name=backend.repo_name,
branch=branch),
status=302)
expected_url = '/{repo}/changelog/{branch}'.format(
repo=backend.repo_name, branch=branch)
assert expected_url in response.location
response = response.follow()
expected_warning = 'Branch {} is not found.'.format(branch)
assert expected_warning in response.body
def assert_commits_on_page(self, response, indexes):
found_indexes = [int(idx) for idx in MATCH_HASH.findall(response.body)]
assert found_indexes == indexes
@pytest.mark.xfail_backends("svn", reason="Depends on branch support")
def test_index_filtered_by_branch_with_merges(
self, autologin_user, backend):
# Note: The changelog of branch "b" does not contain the commit "a1"
# although this is a parent of commit "b1". And branch "b" has commits
# which have a smaller index than commit "a1".
commits = [
{'message': 'a'},
{'message': 'b', 'branch': 'b'},
{'message': 'a1', 'parents': ['a']},
{'message': 'b1', 'branch': 'b', 'parents': ['b', 'a1']},
]
backend.create_repo(commits)
self.app.get(
url('changelog_home',
controller='changelog',
action='index',
repo_name=backend.repo_name,
branch='b'),
status=200)
@pytest.mark.backends("hg")
def test_index_closed_branches(self, autologin_user, backend):
repo = backend['closed_branch']
response = self.app.get(
url(
controller='changelog',
action='index',
repo_name=repo.repo_name,
branch='experimental'),
status=200)
self.assert_commits_on_page(
response, indexes=[3, 1])
def test_index_pagination(self, backend):
self.log_user()
# pagination, walk up to page 6
changelog_url = url(
controller='changelog', action='index',
repo_name=backend.repo_name)
for page in range(1, 7):
response = self.app.get(changelog_url, {'page': page})
first_idx = -DEFAULT_CHANGELOG_SIZE * (page - 1) - 1
last_idx = -DEFAULT_CHANGELOG_SIZE * page
self.assert_commit_range_on_page(response, first_idx, last_idx, backend)
def assert_commit_range_on_page(
self, response, first_idx, last_idx, backend):
input_template = (
"""<input class="commit-range" id="%(raw_id)s" """
"""name="%(raw_id)s" type="checkbox" value="1" />"""
)
commit_span_template = """<span class="commit_hash">r%s:%s</span>"""
repo = backend.repo
first_commit_on_page = repo.get_commit(commit_idx=first_idx)
response.mustcontain(
input_template % {'raw_id': first_commit_on_page.raw_id})
response.mustcontain(commit_span_template % (
first_commit_on_page.idx, first_commit_on_page.short_id)
)
last_commit_on_page = repo.get_commit(commit_idx=last_idx)
response.mustcontain(
input_template % {'raw_id': last_commit_on_page.raw_id})
response.mustcontain(commit_span_template % (
last_commit_on_page.idx, last_commit_on_page.short_id)
)
first_commit_of_next_page = repo.get_commit(commit_idx=last_idx - 1)
first_span_of_next_page = commit_span_template % (
first_commit_of_next_page.idx, first_commit_of_next_page.short_id)
assert first_span_of_next_page not in response
def test_index_with_filenode(self, backend):
self.log_user()
response = self.app.get(url(
controller='changelog', action='index', revision='tip',
f_path='/vcs/exceptions.py', repo_name=backend.repo_name))
# history commits messages
response.mustcontain('Added exceptions module, this time for real')
response.mustcontain('Added not implemented hg backend test case')
response.mustcontain('Added BaseChangeset class')
def test_index_with_filenode_that_is_dirnode(self, backend):
self.log_user()
response = self.app.get(url(controller='changelog', action='index',
revision='tip', f_path='/tests',
repo_name=backend.repo_name))
assert response.status == '302 Found'
def test_index_with_filenode_not_existing(self, backend):
self.log_user()
response = self.app.get(url(controller='changelog', action='index',
revision='tip', f_path='/wrong_path',
repo_name=backend.repo_name))
assert response.status == '302 Found'