def test_if_ar_sets_correct_useragent_while_resolving_via_mesosdns( self, master_ar_process_pertest, mocker, valid_user_header): # Remove the data from Mesos and Marathon mocks w.r.t. resolved service mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data={"apps": []}) mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[SCHEDULER_FWRK_ALWAYSTHERE_NOWEBUI]) # Make mesos-dns record requests: mocker.send_command(endpoint_id='http://127.0.0.1:8123', func_name='record_requests') url = master_ar_process_pertest.make_url_from_path("/service/scheduler-alwaysthere/") requests.get( url, allow_redirects=False, headers=valid_user_header) r_reqs = mocker.send_command(endpoint_id='http://127.0.0.1:8123', func_name='get_recorded_requests') assert len(r_reqs) == 1 verify_header(r_reqs[0]['headers'], 'User-Agent', 'Master Admin Router')
def test_if_ui_files_are_handled(self, master_ar_process_perclass, valid_user_header, uniq_content, path): url = master_ar_process_perclass.make_url_from_path('/{}'.format(path)) with overridden_file_content( '/var/lib/dcos/dcos-ui-update-service/dist/ui/{}'.format(path), uniq_content): resp = requests.get(url, allow_redirects=False, headers=valid_user_header) assert resp.status_code == 200 resp.encoding = 'utf-8' assert resp.text == uniq_content verify_header(resp.headers.items(), 'X-Frame-Options', 'DENY')
def test_if_ui_files_are_handled(self, master_ar_process_perclass, valid_user_header, uniq_content, path): url = master_ar_process_perclass.make_url_from_path('/{}'.format(path)) with overridden_file_content( '/opt/mesosphere/active/dcos-ui/usr/{}'.format(path), uniq_content): resp = requests.get(url, allow_redirects=False, headers=valid_user_header) assert resp.status_code == 200 resp.encoding = 'utf-8' assert resp.text == uniq_content verify_header(resp.headers.items(), 'X-Frame-Options', 'SAMEORIGIN')
def test_if_master_ar_sets_correct_useragent_while_quering_iam( self, master_ar_process_pertest, mocker, valid_user_header): mocker.send_command(endpoint_id='http://127.0.0.1:8101', func_name='record_requests') assert_endpoint_response( master_ar_process_pertest, '/mesos_dns/v1/reflect/me', 200, headers=valid_user_header, ) r_reqs = mocker.send_command(endpoint_id='http://127.0.0.1:8101', func_name='get_recorded_requests') assert len(r_reqs) == 1 verify_header(r_reqs[0]['headers'], 'User-Agent', 'Master Admin Router')
def test_if_ui_files_are_handled( self, master_ar_process_perclass, valid_user_header, uniq_content, path): url = master_ar_process_perclass.make_url_from_path('/{}'.format(path)) with overridden_file_content( '/opt/mesosphere/active/dcos-ui/usr/{}'.format(path), uniq_content): resp = requests.get( url, allow_redirects=False, headers=valid_user_header) assert resp.status_code == 200 resp.encoding = 'utf-8' assert resp.text == uniq_content verify_header(resp.headers.items(), 'X-Frame-Options', 'DENY')
def test_if_backend_requests_have_useragent_set_correctly( self, nginx_class, mocker, valid_user_header): # Enable recording for marathon mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='record_requests') # Enable recording for Mesos mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='record_requests') # Make regular polling occur later than usual, so that we get a single # cache refresh: ar = nginx_class(cache_poll_period=60, cache_expiration=55) with GuardedSubprocess(ar): # Initiate cache refresh by issuing a request: ping_mesos_agent(ar, valid_user_header) mesos_requests = mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='get_recorded_requests') marathon_requests = mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='get_recorded_requests') assert len(mesos_requests) == 1 assert len(marathon_requests) == 2 # We could use a loop here, but let's make it a bit easier to debug: verify_header(mesos_requests[0]['headers'], 'User-Agent', 'Master Admin Router') verify_header(marathon_requests[0]['headers'], 'User-Agent', 'Master Admin Router') verify_header(marathon_requests[1]['headers'], 'User-Agent', 'Master Admin Router')
def test_if_ar_sets_correct_useragent_while_resolving_via_mesosdns( self, master_ar_process_pertest, mocker, valid_user_header): # Remove the data from Mesos and Marathon mocks w.r.t. resolved service mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data={"apps": []}) mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[SCHEDULER_FWRK_ALWAYSTHERE_NOWEBUI]) # Make mesos-dns record requests: mocker.send_command(endpoint_id='http://127.0.0.1:8123', func_name='record_requests') url = master_ar_process_pertest.make_url_from_path( "/service/scheduler-alwaysthere/") requests.get(url, allow_redirects=False, headers=valid_user_header) r_reqs = mocker.send_command(endpoint_id='http://127.0.0.1:8123', func_name='get_recorded_requests') assert len(r_reqs) == 1 verify_header(r_reqs[0]['headers'], 'User-Agent', 'Master Admin Router')
def test_if_upstream_request_is_correct(self, valid_user_header, agent_ar_process): url = agent_ar_process.make_url_from_path( "/system/v1/metrics/some/path") resp = requests.get(url, allow_redirects=False, headers=valid_user_header) assert resp.status_code == 200 req_data = resp.json() assert req_data['method'] == 'GET' assert req_data['path'] == '/some/path' assert req_data['request_version'] == 'HTTP/1.0' verify_header(req_data['headers'], 'X-Forwarded-For', '127.0.0.1') verify_header(req_data['headers'], 'X-Forwarded-Proto', 'http') verify_header(req_data['headers'], 'X-Real-IP', '127.0.0.1')
def test_if_upstream_request_is_correct(self, valid_user_header, agent_ar_process): url = agent_ar_process.make_url_from_path("/system/v1/metrics/some/path") resp = requests.get(url, allow_redirects=False, headers=valid_user_header) assert resp.status_code == 200 req_data = resp.json() assert req_data['method'] == 'GET' assert req_data['path'] == '/some/path' assert req_data['request_version'] == 'HTTP/1.0' verify_header(req_data['headers'], 'X-Forwarded-For', '127.0.0.1') verify_header(req_data['headers'], 'X-Forwarded-Proto', 'http') verify_header(req_data['headers'], 'X-Real-IP', '127.0.0.1')