feat(svn-config): moved svn related config keys to *.ini file. Fixes: RCCE-60

This commit is contained in:
Serhii Ilin 2024-02-28 09:34:14 +02:00
parent 16c169bec2
commit 25f36e9654
11 changed files with 45 additions and 82 deletions

View file

@ -615,6 +615,12 @@ vcs.connection_timeout = 3600
; Legacy available options are: pre-1.4-compatible, pre-1.5-compatible, pre-1.6-compatible, pre-1.8-compatible, pre-1.9-compatible ; Legacy available options are: pre-1.4-compatible, pre-1.5-compatible, pre-1.6-compatible, pre-1.8-compatible, pre-1.9-compatible
#vcs.svn.compatible_version = 1.8 #vcs.svn.compatible_version = 1.8
; Enable SVN proxy of requests over HTTP
vcs.svn.proxy.enabled = true
; host to connect to running SVN subsystem
vcs.svn.proxy.host = http://svn:8090
; Cache flag to cache vcsserver remote calls locally ; Cache flag to cache vcsserver remote calls locally
; It uses cache_region `cache_repo` ; It uses cache_region `cache_repo`
vcs.methods.cache = true vcs.methods.cache = true

View file

@ -566,6 +566,12 @@ vcs.connection_timeout = 3600
; Legacy available options are: pre-1.4-compatible, pre-1.5-compatible, pre-1.6-compatible, pre-1.8-compatible, pre-1.9-compatible ; Legacy available options are: pre-1.4-compatible, pre-1.5-compatible, pre-1.6-compatible, pre-1.8-compatible, pre-1.9-compatible
#vcs.svn.compatible_version = 1.8 #vcs.svn.compatible_version = 1.8
; Enable SVN proxy of requests over HTTP
vcs.svn.proxy.enabled = true
; host to connect to running SVN subsystem
vcs.svn.proxy.host = http://svn:8090
; Cache flag to cache vcsserver remote calls locally ; Cache flag to cache vcsserver remote calls locally
; It uses cache_region `cache_repo` ; It uses cache_region `cache_repo`
vcs.methods.cache = true vcs.methods.cache = true

View file

@ -1,4 +1,3 @@
# Copyright (C) 2010-2023 RhodeCode GmbH # Copyright (C) 2010-2023 RhodeCode GmbH
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@ -52,13 +51,13 @@ def assert_clone_url(response, server, repo, disabled=False):
@pytest.mark.usefixtures('app') @pytest.mark.usefixtures('app')
class TestSummaryView(object): class TestSummaryView(object):
def test_index(self, autologin_user, backend, http_host_only_stub): def test_index(self, autologin_user, backend, http_host_only_stub):
repo_id = backend.repo.repo_id repo_id = backend.repo.repo_id
repo_name = backend.repo_name repo_name = backend.repo_name
with mock.patch('rhodecode.lib.helpers.is_svn_without_proxy',
return_value=False): response = self.app.get(
response = self.app.get( route_path('repo_summary', repo_name=repo_name))
route_path('repo_summary', repo_name=repo_name))
# repo type # repo type
response.mustcontain( response.mustcontain(
@ -71,37 +70,43 @@ class TestSummaryView(object):
# clone url... # clone url...
assert_clone_url(response, http_host_only_stub, repo_name) assert_clone_url(response, http_host_only_stub, repo_name)
assert_clone_url(response, http_host_only_stub, '_{}'.format(repo_id)) assert_clone_url(response, http_host_only_stub, f'_{repo_id}')
def test_index_svn_without_proxy( def test_index_svn_without_proxy(
self, autologin_user, backend_svn, http_host_only_stub): self, autologin_user, backend_svn, http_host_only_stub):
repo_id = backend_svn.repo.repo_id repo_id = backend_svn.repo.repo_id
repo_name = backend_svn.repo_name repo_name = backend_svn.repo_name
response = self.app.get(route_path('repo_summary', repo_name=repo_name))
# clone url...
# by default the SVN is enabled now, this is how inputs look when it's disabled
with mock.patch('rhodecode.lib.helpers.is_svn_without_proxy', return_value=True):
response = self.app.get(
route_path('repo_summary', repo_name=repo_name),
status=200)
# clone url test...
assert_clone_url(response, http_host_only_stub, repo_name, disabled=True) assert_clone_url(response, http_host_only_stub, repo_name, disabled=True)
assert_clone_url(response, http_host_only_stub, '_{}'.format(repo_id), disabled=True) assert_clone_url(response, http_host_only_stub, f'_{repo_id}', disabled=True)
def test_index_with_trailing_slash( def test_index_with_trailing_slash(
self, autologin_user, backend, http_host_only_stub): self, autologin_user, backend, http_host_only_stub):
repo_id = backend.repo.repo_id repo_id = backend.repo.repo_id
repo_name = backend.repo_name repo_name = backend.repo_name
with mock.patch('rhodecode.lib.helpers.is_svn_without_proxy', trailing_slash = '/'
return_value=False): response = self.app.get(
response = self.app.get( route_path('repo_summary', repo_name=repo_name) + trailing_slash,
route_path('repo_summary', repo_name=repo_name) + '/', status=200)
status=200)
# clone url... # clone url...
assert_clone_url(response, http_host_only_stub, repo_name) assert_clone_url(response, http_host_only_stub, repo_name)
assert_clone_url(response, http_host_only_stub, '_{}'.format(repo_id)) assert_clone_url(response, http_host_only_stub, f'_{repo_id}')
def test_index_by_id(self, autologin_user, backend): def test_index_by_id(self, autologin_user, backend):
repo_id = backend.repo.repo_id repo_id = backend.repo.repo_id
response = self.app.get( response = self.app.get(
route_path('repo_summary', repo_name='_%s' % (repo_id,))) route_path('repo_summary', repo_name=f'_{repo_id}'))
# repo type # repo type
response.mustcontain( response.mustcontain(

View file

@ -244,9 +244,10 @@ class SubversionServer(VcsServer):
# if exit_code: # if exit_code:
# return exit_code, False # return exit_code, False
req = self.env['request'] req = self.env.get('request')
server_url = req.host_url + req.script_name if req:
extras['server_url'] = server_url server_url = req.host_url + req.script_name
extras['server_url'] = server_url
log.debug('Using %s binaries from path %s', self.backend, self._path) log.debug('Using %s binaries from path %s', self.backend, self._path)
exit_code = self.tunnel.run(extras) exit_code = self.tunnel.run(extras)

View file

@ -542,6 +542,8 @@ def sanitize_settings_and_apply_defaults(global_config, settings):
settings_maker.make_setting('statsd.statsd_ipv6', False, parser='bool') settings_maker.make_setting('statsd.statsd_ipv6', False, parser='bool')
settings_maker.make_setting('vcs.svn.compatible_version', '') settings_maker.make_setting('vcs.svn.compatible_version', '')
settings_maker.make_setting('vcs.svn.proxy.enabled', 'true', parser='bool')
settings_maker.make_setting('vcs.svn.proxy.host', 'http://svn:8090')
settings_maker.make_setting('vcs.hooks.protocol', 'http') settings_maker.make_setting('vcs.hooks.protocol', 'http')
settings_maker.make_setting('vcs.hooks.host', '*') settings_maker.make_setting('vcs.hooks.host', '*')
settings_maker.make_setting('vcs.scm_app_implementation', 'http') settings_maker.make_setting('vcs.scm_app_implementation', 'http')

View file

@ -74,6 +74,7 @@ from webhelpers2.html.tags import (
from webhelpers2.number import format_byte_size from webhelpers2.number import format_byte_size
# python3.11 backport fixes for webhelpers2 # python3.11 backport fixes for webhelpers2
from rhodecode import ConfigGet
from rhodecode.lib._vendor.webhelpers_backports import raw_select from rhodecode.lib._vendor.webhelpers_backports import raw_select
from rhodecode.lib.action_parser import action_parser from rhodecode.lib.action_parser import action_parser
@ -916,9 +917,7 @@ def get_repo_type_by_name(repo_name):
def is_svn_without_proxy(repository): def is_svn_without_proxy(repository):
if is_svn(repository): if is_svn(repository):
from rhodecode.model.settings import VcsSettingsModel return not ConfigGet().get_bool('vcs.svn.proxy.enabled')
conf = VcsSettingsModel().get_ui_settings_as_config_obj()
return not str2bool(conf.get('vcs_svn_proxy', 'http_requests_enabled'))
return False return False

View file

@ -27,6 +27,7 @@ import urllib.parse
import requests import requests
from pyramid.httpexceptions import HTTPNotAcceptable from pyramid.httpexceptions import HTTPNotAcceptable
from rhodecode import ConfigGet
from rhodecode.lib import rc_cache from rhodecode.lib import rc_cache
from rhodecode.lib.middleware import simplevcs from rhodecode.lib.middleware import simplevcs
from rhodecode.lib.middleware.utils import get_path_info from rhodecode.lib.middleware.utils import get_path_info
@ -232,12 +233,10 @@ class SimpleSvn(simplevcs.SimpleVCS):
return DisabledSimpleSvnApp(config) return DisabledSimpleSvnApp(config)
def _is_svn_enabled(self): def _is_svn_enabled(self):
conf = self.repo_vcs_config return ConfigGet().get_bool('vcs.svn.proxy.enabled')
return str2bool(conf.get('vcs_svn_proxy', 'http_requests_enabled'))
def _create_config(self, extras, repo_name, scheme='http'): def _create_config(self, extras, repo_name, scheme='http'):
conf = self.repo_vcs_config server_url = ConfigGet().get_str('vcs.svn.proxy.host')
server_url = conf.get('vcs_svn_proxy', 'http_server_url')
server_url = server_url or self.DEFAULT_HTTP_SERVER server_url = server_url or self.DEFAULT_HTTP_SERVER
extras['subversion_http_server_url'] = server_url extras['subversion_http_server_url'] = server_url

View file

@ -421,10 +421,6 @@ class _BaseVcsSettingsForm(formencode.Schema):
rhodecode_git_use_rebase_for_merging = v.StringBoolean(if_missing=False) rhodecode_git_use_rebase_for_merging = v.StringBoolean(if_missing=False)
rhodecode_git_close_branch_before_merging = v.StringBoolean(if_missing=False) rhodecode_git_close_branch_before_merging = v.StringBoolean(if_missing=False)
# svn
vcs_svn_proxy_http_requests_enabled = v.StringBoolean(if_missing=False)
vcs_svn_proxy_http_server_url = v.UnicodeString(strip=True, if_missing=None)
# cache # cache
rhodecode_diff_cache = v.StringBoolean(if_missing=False) rhodecode_diff_cache = v.StringBoolean(if_missing=False)

View file

@ -499,11 +499,6 @@ class VcsSettingsModel(object):
('vcs_git_lfs', 'store_location') ('vcs_git_lfs', 'store_location')
) )
GLOBAL_SVN_SETTINGS = (
('vcs_svn_proxy', 'http_requests_enabled'),
('vcs_svn_proxy', 'http_server_url')
)
SVN_BRANCH_SECTION = 'vcs_svn_branch' SVN_BRANCH_SECTION = 'vcs_svn_branch'
SVN_TAG_SECTION = 'vcs_svn_tag' SVN_TAG_SECTION = 'vcs_svn_tag'
SSL_SETTING = ('web', 'push_ssl') SSL_SETTING = ('web', 'push_ssl')
@ -718,17 +713,6 @@ class VcsSettingsModel(object):
# branch/tags patterns # branch/tags patterns
self._create_svn_settings(self.global_settings, data) self._create_svn_settings(self.global_settings, data)
http_requests_enabled, http_server_url = self.GLOBAL_SVN_SETTINGS
http_requests_enabled_key, http_server_url_key = self._get_settings_keys(
self.GLOBAL_SVN_SETTINGS, data)
self._create_or_update_ui(
self.global_settings, *http_requests_enabled,
value=safe_str(data[http_requests_enabled_key]))
self._create_or_update_ui(
self.global_settings, *http_server_url,
value=data[http_server_url_key])
def update_global_ssl_setting(self, value): def update_global_ssl_setting(self, value):
self._create_or_update_ui( self._create_or_update_ui(
self.global_settings, *self.SSL_SETTING, value=value) self.global_settings, *self.SSL_SETTING, value=value)

View file

@ -170,42 +170,6 @@
</div> </div>
% endif % endif
% if display_globals:
<div class="panel panel-default">
<div class="panel-heading" id="vcs-global-svn-options">
<h3 class="panel-title">${_('Global Subversion Settings')}<a class="permalink" href="#vcs-global-svn-options"> ¶</a></h3>
</div>
<div class="panel-body">
<div class="field">
<div class="checkbox">
${h.checkbox('vcs_svn_proxy_http_requests_enabled' + suffix, 'True', **kwargs)}
<label for="vcs_svn_proxy_http_requests_enabled${suffix}">${_('Proxy subversion HTTP requests')}</label>
</div>
<div class="label">
<span class="help-block">
${_('Subversion HTTP Support. Enables communication with SVN over HTTP protocol.')}
<a href="${h.route_url('enterprise_svn_setup')}" target="_blank">${_('SVN Protocol setup Documentation')}</a>.
</span>
</div>
</div>
<div class="field">
<div class="label">
<label for="vcs_svn_proxy_http_server_url">${_('Subversion HTTP Server URL')}</label><br/>
</div>
<div class="input">
${h.text('vcs_svn_proxy_http_server_url',size=59)}
% if c.svn_proxy_generate_config:
<span class="buttons">
<button class="btn btn-primary" id="vcs_svn_generate_cfg">${_('Generate Apache Config')}</button>
</span>
% endif
</div>
</div>
</div>
</div>
% endif
% if display_globals or repo_type in ['svn']: % if display_globals or repo_type in ['svn']:
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading" id="vcs-svn-options"> <div class="panel-heading" id="vcs-svn-options">

View file

@ -108,6 +108,7 @@ def ini_config(request, tmpdir_factory, rcserver_port, vcsserver_port):
'vcs.server.protocol': 'http', 'vcs.server.protocol': 'http',
'vcs.scm_app_implementation': 'http', 'vcs.scm_app_implementation': 'http',
'vcs.svn.proxy.enabled': 'true',
'vcs.hooks.protocol': 'http', 'vcs.hooks.protocol': 'http',
'vcs.hooks.host': '*', 'vcs.hooks.host': '*',
'app.service_api.token': 'service_secret_token', 'app.service_api.token': 'service_secret_token',