##// END OF EJS Templates
deps: bumped venusian==3.1.0 for python 3.12 compat
deps: bumped venusian==3.1.0 for python 3.12 compat

File last commit:

r5608:6d33e504 default
r5622:5bcb0167 default
Show More
test_server_hg.py
139 lines | 5.0 KiB | text/x-python | PythonLexer
core: updated copyright to 2024
r5608 # Copyright (C) 2016-2024 RhodeCode GmbH
ssh: embedded ssh support...
r2043 #
# 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/
Mercurial: fix ssh-server support for UI objects...
r3626 import os
tests: fixed test suite for celery adoption
r5607
ssh-support: enabled full handling of all backends via SSH....
r2187 import mock
ssh: embedded ssh support...
r2043 import pytest
ssh-support: don't use API calls to fetch the data....
r2186 from rhodecode.apps.ssh_support.lib.backends.hg import MercurialServer
dan
tests: fixed some pytest deprecated calls, and warnings.
r3098 from rhodecode.apps.ssh_support.tests.conftest import plain_dummy_env, plain_dummy_user
ssh: embedded ssh support...
r2043
class MercurialServerCreator(object):
root = '/tmp/repo/path/'
hg_path = '/usr/local/bin/hg'
config_data = {
'app:main': {
ssh-support: enabled full handling of all backends via SSH....
r2187 'ssh.executable.hg': hg_path,
feat(configs): deprecared old hooks protocol and ssh wrapper....
r5496 'vcs.hooks.protocol.v2': 'celery',
tests: fixed test suite for celery adoption
r5607 'app.service_api.host': 'http://localhost',
'app.service_api.token': 'secret4',
'rhodecode.api.url': '/_admin/api',
ssh: embedded ssh support...
r2043 }
}
repo_name = 'test_hg'
dan
tests: fixed some pytest deprecated calls, and warnings.
r3098 user = plain_dummy_user()
ssh: embedded ssh support...
r2043
tests: fixed test suite for celery adoption
r5607 def __init__(self, service_api_url, ini_file):
self.service_api_url = service_api_url
self.ini_file = ini_file
ssh: embedded ssh support...
r2043
def create(self, **kwargs):
tests: fixed test suite for celery adoption
r5607 self.config_data['app:main']['app.service_api.host'] = self.service_api_url
ssh: embedded ssh support...
r2043 parameters = {
ssh-support: enabled full handling of all backends via SSH....
r2187 'store': self.root,
tests: fixed test suite for celery adoption
r5607 'ini_path': self.ini_file,
ssh: embedded ssh support...
r2043 'user': self.user,
'repo_name': self.repo_name,
'user_permissions': {
tests: fixed test suite for celery adoption
r5607 self.repo_name: 'repository.admin'
ssh: embedded ssh support...
r2043 },
feat(ssh-wrapper-speedup): major rewrite of code to address imports problem with ssh-wrapper-v2...
r5325 'settings': self.config_data['app:main'],
dan
tests: fixed some pytest deprecated calls, and warnings.
r3098 'env': plain_dummy_env()
ssh: embedded ssh support...
r2043 }
parameters.update(kwargs)
server = MercurialServer(**parameters)
return server
tests: fixed test suite for celery adoption
r5607 @pytest.fixture(scope='module')
def hg_server(request, module_app, rhodecode_factory, available_port_factory):
ini_file = module_app._pyramid_settings['__file__']
vcsserver_host = module_app._pyramid_settings['vcs.server']
store_dir = os.path.dirname(ini_file)
# start rhodecode for service API
rc = rhodecode_factory(
request,
store_dir=store_dir,
port=available_port_factory(),
overrides=(
{'handler_console': {'level': 'DEBUG'}},
{'app:main': {'vcs.server': vcsserver_host}},
{'app:main': {'repo_store.path': store_dir}}
))
service_api_url = f'http://{rc.bind_addr}'
return MercurialServerCreator(service_api_url, ini_file)
ssh-support: enabled full handling of all backends via SSH....
r2187
tests: fixed test suite for celery adoption
r5607 class TestMercurialServer:
ssh-support: enabled full handling of all backends via SSH....
r2187
Mercurial: fix ssh-server support for UI objects...
r3626 def test_command(self, hg_server, tmpdir):
ssh: embedded ssh support...
r2043 server = hg_server.create()
Mercurial: fix ssh-server support for UI objects...
r3626 custom_hgrc = os.path.join(str(tmpdir), 'hgrc')
ssh: embedded ssh support...
r2043 expected_command = (
Mercurial: fix ssh-server support for UI objects...
r3626 'cd {root}; HGRCPATH={custom_hgrc} {hg_path} -R {root}{repo_name} serve --stdio'.format(
root=hg_server.root, custom_hgrc=custom_hgrc, hg_path=hg_server.hg_path,
ssh: embedded ssh support...
r2043 repo_name=hg_server.repo_name)
)
Mercurial: fix ssh-server support for UI objects...
r3626 server_command = server.tunnel.command(custom_hgrc)
assert expected_command == server_command
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 @pytest.mark.parametrize('permissions, action, code', [
({}, 'pull', -2),
({'test_hg': 'repository.read'}, 'pull', 0),
({'test_hg': 'repository.read'}, 'push', -2),
({'test_hg': 'repository.write'}, 'push', 0),
({'test_hg': 'repository.admin'}, 'push', 0),
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 ])
def test_permission_checks(self, hg_server, permissions, action, code):
server = hg_server.create(user_permissions=permissions)
result = server._check_permissions(action)
assert result is code
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 @pytest.mark.parametrize('permissions, value', [
({}, False),
({'test_hg': 'repository.read'}, False),
({'test_hg': 'repository.write'}, True),
({'test_hg': 'repository.admin'}, True),
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 ])
def test_has_write_permissions(self, hg_server, permissions, value):
server = hg_server.create(user_permissions=permissions)
result = server.has_write_perm()
assert result is value
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 def test_run_returns_executes_command(self, hg_server):
ssh: embedded ssh support...
r2043 server = hg_server.create()
ssh-support: enabled full handling of all backends via SSH....
r2187 from rhodecode.apps.ssh_support.lib.backends.hg import MercurialTunnelWrapper
tests: fixed some flacky tests on docker.
r4654 os.environ['SSH_CLIENT'] = '127.0.0.1'
ssh-support: enabled full handling of all backends via SSH....
r2187 with mock.patch.object(MercurialTunnelWrapper, 'create_hooks_env') as _patch:
_patch.return_value = 0
with mock.patch.object(MercurialTunnelWrapper, 'command', return_value='date'):
tests: fixed test suite for celery adoption
r5607 exit_code = server.run(tunnel_extras={'config': server.ini_path})
ssh: embedded ssh support...
r2043
assert exit_code == (0, False)
ssh-support: enabled full handling of all backends via SSH....
r2187