Пример #1
0
    def test_if_scheme_is_honoured_for_marathon_apps(self,
                                                     master_ar_process_pertest,
                                                     mocker,
                                                     valid_user_header):
        # 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)

        # Mock TLS-enabled Marathon app
        app_dict = app_from_template('scheduler-alwaysthere',
                                     443,
                                     ip="127.0.0.4",
                                     scheme='https')
        new_apps = {
            "apps": [
                app_dict,
            ]
        }
        mocker.send_command(endpoint_id='http://127.0.0.1:8080',
                            func_name='set_apps_response',
                            aux_data=new_apps)

        url = master_ar_process_pertest.make_url_from_path(
            "/service/scheduler-alwaysthere/")
        resp = requests.get(url,
                            allow_redirects=False,
                            headers=valid_user_header)

        assert resp.status_code == 200
        req_data = resp.json()
        assert req_data['endpoint_id'] == "https://127.0.0.4:443"
Пример #2
0
    def test_if_scheme_is_honoured_for_marathon_apps(
            self, master_ar_process_pertest, mocker, valid_user_header):
        # 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)

        # Mock TLS-enabled Marathon app
        app_dict = app_from_template(
            'scheduler-alwaysthere', 443, ip="127.0.0.4", scheme='https')
        new_apps = {"apps": [app_dict, ]}
        mocker.send_command(
            endpoint_id='http://127.0.0.1:8080',
            func_name='set_apps_response',
            aux_data=new_apps)

        url = master_ar_process_pertest.make_url_from_path("/service/scheduler-alwaysthere/")
        resp = requests.get(url,
                            allow_redirects=False,
                            headers=valid_user_header)

        assert resp.status_code == 200
        req_data = resp.json()
        assert req_data['endpoint_id'] == "https://127.0.0.4:443"
Пример #3
0
    def test_if_only_matching_scheme_redirects_are_adjusted_for_marathon_apps(
            self, master_ar_process_pertest, mocker, valid_user_header):
        # 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)

        # Mock TLS-enabled Marathon app
        app_dict = app_from_template('scheduler-alwaysthere',
                                     443,
                                     ip="127.0.0.4",
                                     scheme='https')
        new_apps = {
            "apps": [
                app_dict,
            ]
        }
        mocker.send_command(endpoint_id='http://127.0.0.1:8080',
                            func_name='set_apps_response',
                            aux_data=new_apps)

        # Non-matching:
        mocker.send_command(endpoint_id="https://127.0.0.4:443",
                            func_name='always_redirect',
                            aux_data="http://127.0.0.1/")
        url = master_ar_process_pertest.make_url_from_path(
            "/service/scheduler-alwaysthere/foo/bar")
        r = requests.get(url, allow_redirects=False, headers=valid_user_header)
        assert r.status_code == 307
        assert r.headers['Location'] == "http://127.0.0.1/"

        # Matching:
        mocker.send_command(endpoint_id="https://127.0.0.4:443",
                            func_name='always_redirect',
                            aux_data="https://127.0.0.1/")
        url = master_ar_process_pertest.make_url_from_path(
            "/service/scheduler-alwaysthere/foo/bar")
        r = requests.get(url, allow_redirects=False, headers=valid_user_header)
        assert r.status_code == 307
        assert r.headers[
            'Location'] == "http://127.0.0.1/service/scheduler-alwaysthere/"
Пример #4
0
    def test_if_only_matching_scheme_redirects_are_adjusted_for_marathon_apps(
            self, master_ar_process_pertest, mocker, valid_user_header):
        # 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)

        # Mock TLS-enabled Marathon app
        app_dict = app_from_template(
            'scheduler-alwaysthere', 443, ip="127.0.0.4", scheme='https')
        new_apps = {"apps": [app_dict, ]}
        mocker.send_command(
            endpoint_id='http://127.0.0.1:8080',
            func_name='set_apps_response',
            aux_data=new_apps)

        # Non-matching:
        mocker.send_command(
            endpoint_id="https://127.0.0.4:443",
            func_name='always_redirect',
            aux_data="http://127.0.0.1/")
        url = master_ar_process_pertest.make_url_from_path(
            "/service/scheduler-alwaysthere/foo/bar")
        r = requests.get(url, allow_redirects=False, headers=valid_user_header)
        assert r.status_code == 307
        assert r.headers['Location'] == "http://127.0.0.1/"

        # Matching:
        mocker.send_command(
            endpoint_id="https://127.0.0.4:443",
            func_name='always_redirect',
            aux_data="https://127.0.0.1/")
        url = master_ar_process_pertest.make_url_from_path(
            "/service/scheduler-alwaysthere/foo/bar")
        r = requests.get(url, allow_redirects=False, headers=valid_user_header)
        assert r.status_code == 307
        absolute = urljoin(url, r.headers['Location'])
        assert absolute == "http://127.0.0.1/service/scheduler-alwaysthere/"