MCPcopy Create free account
hub / github.com/bugy/script-server / mock_request_handler

Function mock_request_handler

src/tests/audit_utils_test.py:9–29  ·  view source on GitHub ↗
(ip=None, proxy_username=None, auth_username=None, proxied_ip=None)

Source from the content-addressed store, hash-verified

7
8
9def mock_request_handler(ip=None, proxy_username=None, auth_username=None, proxied_ip=None):
10 handler_mock = mock_object()
11
12 handler_mock.application = mock_object()
13
14 handler_mock.application.identification = mock_object()
15 handler_mock.application.identification.identify_for_audit = lambda x: auth_username
16
17 handler_mock.request = mock_object()
18 handler_mock.request.headers = {}
19 if proxy_username:
20 credentials = proxy_username + ':pwd'
21 credentials_base64 = base64.encodebytes(credentials.encode('utf-8'))
22 handler_mock.request.headers['Authorization'] = 'Basic ' + credentials_base64.decode('utf-8')
23
24 handler_mock.request.remote_ip = ip
25
26 if proxied_ip:
27 handler_mock.request.headers['X-Forwarded-For'] = proxied_ip
28
29 return handler_mock
30
31
32def get_audit_name(request_handler):

Calls 1

mock_objectFunction · 0.90

Tested by

no test coverage detected