def test_if_upstream_request_is_correct(self, master_ar_process_perclass, valid_user_header, path, upstream_path, http_ver): generic_correct_upstream_request_test( master_ar_process_perclass, valid_user_header, path, upstream_path, http_ver, )
def test_if_webui_url_path_is_normalized( self, master_ar_process_pertest, mocker, valid_user_header): # Remove the data from Marathon mock mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data={"apps": []}) # Remove the data from MesosDNS mock mocker.send_command(endpoint_id='http://127.0.0.1:8123', func_name='set_srv_response', aux_data=EMPTY_SRV) # Test webui_url entry withouth trailing slash: fwrk = framework_from_template( SCHEDULER_FWRK_ALWAYSTHERE_ID, "scheduler-alwaysthere", "http://127.0.0.15:16001") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk]) generic_correct_upstream_dest_test( master_ar_process_pertest, valid_user_header, '/service/scheduler-alwaysthere/foo/bar/', "http://127.0.0.15:16001" ) generic_correct_upstream_request_test( master_ar_process_pertest, valid_user_header, '/service/scheduler-alwaysthere/foo/bar/', '/foo/bar/', http_ver='websockets' ) # Test webui_url entry with trailing slash: fwrk = framework_from_template( SCHEDULER_FWRK_ALWAYSTHERE_ID, "scheduler-alwaysthere", "http://127.0.0.15:16001/") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk]) generic_correct_upstream_dest_test( master_ar_process_pertest, valid_user_header, '/service/scheduler-alwaysthere/foo/bar/', "http://127.0.0.15:16001" ) generic_correct_upstream_request_test( master_ar_process_pertest, valid_user_header, '/service/scheduler-alwaysthere/foo/bar/', '/foo/bar/', http_ver='websockets' )
def test_if_upstream_request_is_correct(self, master_ar_process, valid_user_header, path_given, path_expected): prefixed_pg = agent_prefix + path_given generic_correct_upstream_request_test( master_ar_process, valid_user_header, prefixed_pg, path_expected, http_ver="HTTP/1.1", )
def test_if_upstream_request_is_correct(self, agent_ar_process, valid_user_header, path_given, path_expected): generic_correct_upstream_request_test(agent_ar_process, valid_user_header, path_given, path_expected, http_ver="HTTP/1.1" )
def test_if_upstream_request_is_correct( self, master_ar_process_perclass, valid_user_header, path, upstream_path, http_ver): generic_correct_upstream_request_test(master_ar_process_perclass, valid_user_header, path, upstream_path, http_ver, )
def test_if_leader_is_local_state_is_handled(self, nginx_class, valid_user_header): ar = nginx_class() path_sent = '/dcos-history-service/foo/bar?a1=GET+param&a2=foobarism' path_expected = '/foo/bar?a1=GET+param&a2=foobarism' with GuardedSubprocess(ar): generic_correct_upstream_dest_test(ar, valid_user_header, path_sent, "http://127.0.0.1:15055") generic_correct_upstream_request_test(ar, valid_user_header, path_sent, path_expected) generic_upstream_headers_verify_test(ar, valid_user_header, path_sent)
def test_if_upstream_request_is_correct(self, agent_ar_process_perclass, valid_user_header, path, upstream_path, http_ver, vhost): req_headers = copy.deepcopy(valid_user_header) if vhost is not None: req_headers["Host"] = vhost generic_correct_upstream_request_test( agent_ar_process_perclass, req_headers, path, upstream_path, http_ver, )
def test_if_leader_is_nonlocal_state_is_handled(self, nginx_class, valid_user_header, dns_server_mock): ar = nginx_class() path_sent = '/dcos-history-service/foo/bar?a1=GET+param&a2=foobarism' path_expected = '/dcos-history-service/foo/bar?a1=GET+param&a2=foobarism' dns_server_mock.set_dns_entry('leader.mesos.', ip='127.0.0.3') with GuardedSubprocess(ar): generic_correct_upstream_dest_test(ar, valid_user_header, path_sent, "http://127.0.0.3:80") generic_correct_upstream_request_test(ar, valid_user_header, path_sent, path_expected) generic_upstream_headers_verify_test( ar, valid_user_header, path_sent, assert_headers={"DCOS-Forwarded": "true"})
def test_if_req_url_rewriting_can_be_configured(self, master_ar_process_pertest, mocker, valid_user_header, label_val, should_rewrite): # If `DCOS_SERVICE_REWRITE_REQUEST_URLS` is set to `false` (string) or # `false` (boolean), Admin Router will not strip the context path and # the upstream request will be made with the same the URL path as the client # request has been made. In any other case it the prefix will be stripped # Remove the data from MesosDNS and Mesos mocks w.r.t. resolved service mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[]) mocker.send_command(endpoint_id='http://127.0.0.1:8123', func_name='set_srv_response', aux_data=EMPTY_SRV) # Set non-standard socket for the applicaiton srv = SCHEDULER_APP_ALWAYSTHERE_DIFFERENTPORT if label_val is not None: srv['labels']['DCOS_SERVICE_REWRITE_REQUEST_URLS'] = label_val new_apps = { "apps": [ srv, ] } mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data=new_apps) # Check if the location now resolves correctly to the new app socket if should_rewrite: path_expected = "/foo/bar/" else: path_expected = "/service/scheduler-alwaysthere/foo/bar/" generic_correct_upstream_request_test( master_ar_process_pertest, valid_user_header, '/service/scheduler-alwaysthere/foo/bar/', path_expected, http_ver='websockets')
def test_if_req_url_rewriting_can_be_configured( self, master_ar_process_pertest, mocker, valid_user_header, label_val, should_rewrite): # If `DCOS_SERVICE_REWRITE_REQUEST_URLS` is set to `false` (string) or # `false` (boolean), Admin Router will not strip the context path and # the upstream request will be made with the same the URL path as the client # request has been made. In any other case it the prefix will be stripped # Remove the data from MesosDNS and Mesos mocks w.r.t. resolved service mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[]) mocker.send_command(endpoint_id='http://127.0.0.1:8123', func_name='set_srv_response', aux_data=EMPTY_SRV) # Set non-standard socket for the applicaiton srv = SCHEDULER_APP_ALWAYSTHERE_DIFFERENTPORT if label_val is not None: srv['labels']['DCOS_SERVICE_REWRITE_REQUEST_URLS'] = label_val new_apps = {"apps": [srv, ]} mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data=new_apps) # Check if the location now resolves correctly to the new app socket if should_rewrite: path_expected = "/foo/bar/" else: path_expected = "/service/scheduler-alwaysthere/foo/bar/" generic_correct_upstream_request_test( master_ar_process_pertest, valid_user_header, '/service/scheduler-alwaysthere/foo/bar/', path_expected, http_ver='websockets' )
def test_if_leader_is_local_state_is_handled( self, nginx_class, valid_user_header): ar = nginx_class() path_sent = '/dcos-history-service/foo/bar?a1=GET+param&a2=foobarism' path_expected = '/foo/bar?a1=GET+param&a2=foobarism' with GuardedSubprocess(ar): generic_correct_upstream_dest_test( ar, valid_user_header, path_sent, "http://127.0.0.1:15055") generic_correct_upstream_request_test( ar, valid_user_header, path_sent, path_expected) generic_upstream_headers_verify_test( ar, valid_user_header, path_sent)
def test_if_leader_is_nonlocal_state_is_handled( self, nginx_class, valid_user_header, dns_server_mock): ar = nginx_class() path_sent = '/dcos-history-service/foo/bar?a1=GET+param&a2=foobarism' path_expected = '/dcos-history-service/foo/bar?a1=GET+param&a2=foobarism' dns_server_mock.set_dns_entry('leader.mesos.', ip='127.0.0.3') with GuardedSubprocess(ar): generic_correct_upstream_dest_test( ar, valid_user_header, path_sent, "http://127.0.0.3:80") generic_correct_upstream_request_test( ar, valid_user_header, path_sent, path_expected) generic_upstream_headers_verify_test( ar, valid_user_header, path_sent, assert_headers={"DCOS-Forwarded": "true"})