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

r506:4c6b9282 default
r887:175782be default
Show More
test_admin_auth_settings.py
201 lines | 7.3 KiB | text/x-python | PythonLexer
/ rhodecode / tests / functional / test_admin_auth_settings.py
# -*- 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 pytest
from rhodecode.tests import assert_session_flash
from rhodecode.tests.utils import AssertResponse
from rhodecode.model.db import Session
from rhodecode.model.settings import SettingsModel
def assert_auth_settings_updated(response):
assert response.status_int == 302, 'Expected response HTTP Found 302'
assert_session_flash(response, 'Auth settings updated successfully')
@pytest.mark.usefixtures("autologin_user", "app")
class TestAuthSettingsController(object):
def _enable_plugins(self, plugins_list, csrf_token, override=None,
verify_response=False):
test_url = '/_admin/auth'
params = {
'auth_plugins': plugins_list,
'csrf_token': csrf_token,
}
if override:
params.update(override)
_enabled_plugins = []
for plugin in plugins_list.split(','):
plugin_name = plugin.partition('#')[-1]
enabled_plugin = '%s_enabled' % plugin_name
cache_ttl = '%s_cache_ttl' % plugin_name
# default params that are needed for each plugin,
# `enabled` and `cache_ttl`
params.update({
enabled_plugin: True,
cache_ttl: 0
})
_enabled_plugins.append(enabled_plugin)
# we need to clean any enabled plugin before, since they require
# form params to be present
db_plugin = SettingsModel().get_setting_by_name('auth_plugins')
db_plugin.app_settings_value = \
'egg:rhodecode-enterprise-ce#rhodecode'
Session().add(db_plugin)
Session().commit()
for _plugin in _enabled_plugins:
db_plugin = SettingsModel().get_setting_by_name(_plugin)
if db_plugin:
Session().delete(db_plugin)
Session().commit()
response = self.app.post(url=test_url, params=params)
if verify_response:
assert_auth_settings_updated(response)
return params
def _post_ldap_settings(self, params, override=None, force=False):
params.update({
'filter': 'user',
'user_member_of': '',
'user_search_base': '',
'user_search_filter': 'test_filter',
'host': 'dc.example.com',
'port': '999',
'tls_kind': 'PLAIN',
'tls_reqcert': 'NEVER',
'dn_user': 'test_user',
'dn_pass': 'test_pass',
'base_dn': 'test_base_dn',
'search_scope': 'BASE',
'attr_login': 'test_attr_login',
'attr_firstname': 'ima',
'attr_lastname': 'tester',
'attr_email': 'test@example.com',
'cache_ttl': '0',
})
if force:
params = {}
params.update(override or {})
test_url = '/_admin/auth/ldap/'
response = self.app.post(url=test_url, params=params)
return response
def test_index(self):
response = self.app.get('/_admin/auth')
response.mustcontain('Authentication Plugins')
@pytest.mark.parametrize("disable_plugin, needs_import", [
('egg:rhodecode-enterprise-ce#headers', None),
('egg:rhodecode-enterprise-ce#crowd', None),
('egg:rhodecode-enterprise-ce#jasig_cas', None),
('egg:rhodecode-enterprise-ce#ldap', None),
('egg:rhodecode-enterprise-ce#pam', "pam"),
])
def test_disable_plugin(self, csrf_token, disable_plugin, needs_import):
# TODO: johbo: "pam" is currently not available on darwin,
# although the docs state that it should work on darwin.
if needs_import:
pytest.importorskip(needs_import)
self._enable_plugins(
'egg:rhodecode-enterprise-ce#rhodecode,' + disable_plugin,
csrf_token, verify_response=True)
self._enable_plugins(
'egg:rhodecode-enterprise-ce#rhodecode', csrf_token,
verify_response=True)
def test_ldap_save_settings(self, csrf_token):
params = self._enable_plugins(
'egg:rhodecode-enterprise-ce#rhodecode,'
'egg:rhodecode-enterprise-ce#ldap',
csrf_token)
response = self._post_ldap_settings(params)
assert_auth_settings_updated(response)
new_settings = SettingsModel().get_auth_settings()
assert new_settings['auth_ldap_host'] == u'dc.example.com', \
'fail db write compare'
def test_ldap_error_form_wrong_port_number(self, csrf_token):
params = self._enable_plugins(
'egg:rhodecode-enterprise-ce#rhodecode,'
'egg:rhodecode-enterprise-ce#ldap',
csrf_token)
invalid_port_value = 'invalid-port-number'
response = self._post_ldap_settings(params, override={
'port': invalid_port_value,
})
assertr = AssertResponse(response)
assertr.element_contains(
'.form .field #port ~ .error-message',
invalid_port_value)
def test_ldap_error_form(self, csrf_token):
params = self._enable_plugins(
'egg:rhodecode-enterprise-ce#rhodecode,'
'egg:rhodecode-enterprise-ce#ldap',
csrf_token)
response = self._post_ldap_settings(params, override={
'attr_login': '',
})
response.mustcontain("""<span class="error-message">The LDAP Login"""
""" attribute of the CN must be specified""")
def test_post_ldap_group_settings(self, csrf_token):
params = self._enable_plugins(
'egg:rhodecode-enterprise-ce#rhodecode,'
'egg:rhodecode-enterprise-ce#ldap',
csrf_token)
response = self._post_ldap_settings(params, override={
'host': 'dc-legacy.example.com',
'port': '999',
'tls_kind': 'PLAIN',
'tls_reqcert': 'NEVER',
'dn_user': 'test_user',
'dn_pass': 'test_pass',
'base_dn': 'test_base_dn',
'filter': 'test_filter',
'search_scope': 'BASE',
'attr_login': 'test_attr_login',
'attr_firstname': 'ima',
'attr_lastname': 'tester',
'attr_email': 'test@example.com',
'cache_ttl': '60',
'csrf_token': csrf_token,
}
)
assert_auth_settings_updated(response)
new_settings = SettingsModel().get_auth_settings()
assert new_settings['auth_ldap_host'] == u'dc-legacy.example.com', \
'fail db write compare'