##// END OF EJS Templates
hooks: expose user agent in the variables submitted to pull/push hooks.
marcink -
r1710:7173cb6f default
parent child Browse files
Show More
@@ -162,6 +162,10 b' def get_access_path(environ):'
162 return path
162 return path
163
163
164
164
165 def get_user_agent(environ):
166 return environ.get('HTTP_USER_AGENT')
167
168
165 def vcs_operation_context(
169 def vcs_operation_context(
166 environ, repo_name, username, action, scm, check_locking=True,
170 environ, repo_name, username, action, scm, check_locking=True,
167 is_shadow_repo=False):
171 is_shadow_repo=False):
@@ -200,6 +204,7 b' def vcs_operation_context('
200 'make_lock': make_lock,
204 'make_lock': make_lock,
201 'locked_by': locked_by,
205 'locked_by': locked_by,
202 'server_url': utils2.get_server_url(environ),
206 'server_url': utils2.get_server_url(environ),
207 'user_agent': get_user_agent(environ),
203 'hooks': get_enabled_hook_classes(ui_settings),
208 'hooks': get_enabled_hook_classes(ui_settings),
204 'is_shadow_repo': is_shadow_repo,
209 'is_shadow_repo': is_shadow_repo,
205 }
210 }
@@ -43,6 +43,7 b' def scm_extras(user_regular, repo_stub):'
43 'config': '',
43 'config': '',
44 'server_url': 'http://example.com',
44 'server_url': 'http://example.com',
45 'make_lock': None,
45 'make_lock': None,
46 'user-agent': 'some-client',
46 'locked_by': [None],
47 'locked_by': [None],
47 'commit_ids': ['a' * 40] * 3,
48 'commit_ids': ['a' * 40] * 3,
48 'is_shadow_repo': False,
49 'is_shadow_repo': False,
@@ -34,8 +34,9 b' from rhodecode.model import db'
34 ('scm', 'stub_scm'),
34 ('scm', 'stub_scm'),
35 ('hooks', ['stub_hook']),
35 ('hooks', ['stub_hook']),
36 ('config', 'stub_ini_filename'),
36 ('config', 'stub_ini_filename'),
37 ('ip', 'fake_ip'),
37 ('ip', '1.2.3.4'),
38 ('server_url', 'https://example.com'),
38 ('server_url', 'https://example.com'),
39 ('user_agent', 'client-text-v1.1'),
39 # TODO: johbo: Commpare locking parameters with `_get_rc_scm_extras`
40 # TODO: johbo: Commpare locking parameters with `_get_rc_scm_extras`
40 # in hooks_utils.
41 # in hooks_utils.
41 ('make_lock', None),
42 ('make_lock', None),
@@ -71,7 +72,6 b' def test_vcs_operation_context_can_skip_'
71
72
72 @patch.object(
73 @patch.object(
73 base, 'get_enabled_hook_classes', Mock(return_value=['stub_hook']))
74 base, 'get_enabled_hook_classes', Mock(return_value=['stub_hook']))
74 @patch.object(base, 'get_ip_addr', Mock(return_value="fake_ip"))
75 @patch('rhodecode.lib.utils2.get_server_url',
75 @patch('rhodecode.lib.utils2.get_server_url',
76 Mock(return_value='https://example.com'))
76 Mock(return_value='https://example.com'))
77 def call_vcs_operation_context(**kwargs_override):
77 def call_vcs_operation_context(**kwargs_override):
@@ -87,7 +87,9 b' def call_vcs_operation_context(**kwargs_'
87 'rhodecode.CONFIG', {'__file__': 'stub_ini_filename'})
87 'rhodecode.CONFIG', {'__file__': 'stub_ini_filename'})
88 settings_patch = patch.object(base, 'VcsSettingsModel')
88 settings_patch = patch.object(base, 'VcsSettingsModel')
89 with config_file_patch, settings_patch as settings_mock:
89 with config_file_patch, settings_patch as settings_mock:
90 result = base.vcs_operation_context(environ={}, **kwargs)
90 result = base.vcs_operation_context(
91 environ={'HTTP_USER_AGENT': 'client-text-v1.1',
92 'REMOTE_ADDR': '1.2.3.4'}, **kwargs)
91 settings_mock.assert_called_once_with(repo='stub_repo_name')
93 settings_mock.assert_called_once_with(repo='stub_repo_name')
92 return result
94 return result
93
95
@@ -39,6 +39,7 b' def test_post_push_truncates_commits(use'
39 'config': '',
39 'config': '',
40 'server_url': 'http://example.com',
40 'server_url': 'http://example.com',
41 'make_lock': None,
41 'make_lock': None,
42 'user_agent': 'some-client',
42 'locked_by': [None],
43 'locked_by': [None],
43 'commit_ids': ['abcde12345' * 4] * 30000,
44 'commit_ids': ['abcde12345' * 4] * 30000,
44 'is_shadow_repo': False,
45 'is_shadow_repo': False,
@@ -72,6 +73,7 b' def hook_extras(user_regular, repo_stub)'
72 'config': '',
73 'config': '',
73 'server_url': 'http://example.com',
74 'server_url': 'http://example.com',
74 'make_lock': None,
75 'make_lock': None,
76 'user_agent': 'some-client',
75 'locked_by': [None],
77 'locked_by': [None],
76 'commit_ids': [],
78 'commit_ids': [],
77 'is_shadow_repo': False,
79 'is_shadow_repo': False,
General Comments 0
You need to be logged in to leave comments. Login now