hooks: expose user agent in the variables submitted to pull/push hooks.

This commit is contained in:
Marcin Kuzminski 2017-04-28 21:21:05 +02:00
parent 3262bcc634
commit 46dcc2730a
4 changed files with 13 additions and 3 deletions

View file

@ -162,6 +162,10 @@ def get_access_path(environ):
return path
def get_user_agent(environ):
return environ.get('HTTP_USER_AGENT')
def vcs_operation_context(
environ, repo_name, username, action, scm, check_locking=True,
is_shadow_repo=False):
@ -200,6 +204,7 @@ def vcs_operation_context(
'make_lock': make_lock,
'locked_by': locked_by,
'server_url': utils2.get_server_url(environ),
'user_agent': get_user_agent(environ),
'hooks': get_enabled_hook_classes(ui_settings),
'is_shadow_repo': is_shadow_repo,
}

View file

@ -43,6 +43,7 @@ def scm_extras(user_regular, repo_stub):
'config': '',
'server_url': 'http://example.com',
'make_lock': None,
'user-agent': 'some-client',
'locked_by': [None],
'commit_ids': ['a' * 40] * 3,
'is_shadow_repo': False,

View file

@ -34,8 +34,9 @@ from rhodecode.model import db
('scm', 'stub_scm'),
('hooks', ['stub_hook']),
('config', 'stub_ini_filename'),
('ip', 'fake_ip'),
('ip', '1.2.3.4'),
('server_url', 'https://example.com'),
('user_agent', 'client-text-v1.1'),
# TODO: johbo: Commpare locking parameters with `_get_rc_scm_extras`
# in hooks_utils.
('make_lock', None),
@ -71,7 +72,6 @@ def test_vcs_operation_context_can_skip_locking_check(mock_get_locking_state):
@patch.object(
base, 'get_enabled_hook_classes', Mock(return_value=['stub_hook']))
@patch.object(base, 'get_ip_addr', Mock(return_value="fake_ip"))
@patch('rhodecode.lib.utils2.get_server_url',
Mock(return_value='https://example.com'))
def call_vcs_operation_context(**kwargs_override):
@ -87,7 +87,9 @@ def call_vcs_operation_context(**kwargs_override):
'rhodecode.CONFIG', {'__file__': 'stub_ini_filename'})
settings_patch = patch.object(base, 'VcsSettingsModel')
with config_file_patch, settings_patch as settings_mock:
result = base.vcs_operation_context(environ={}, **kwargs)
result = base.vcs_operation_context(
environ={'HTTP_USER_AGENT': 'client-text-v1.1',
'REMOTE_ADDR': '1.2.3.4'}, **kwargs)
settings_mock.assert_called_once_with(repo='stub_repo_name')
return result

View file

@ -39,6 +39,7 @@ def test_post_push_truncates_commits(user_regular, repo_stub):
'config': '',
'server_url': 'http://example.com',
'make_lock': None,
'user_agent': 'some-client',
'locked_by': [None],
'commit_ids': ['abcde12345' * 4] * 30000,
'is_shadow_repo': False,
@ -72,6 +73,7 @@ def hook_extras(user_regular, repo_stub):
'config': '',
'server_url': 'http://example.com',
'make_lock': None,
'user_agent': 'some-client',
'locked_by': [None],
'commit_ids': [],
'is_shadow_repo': False,