Exemplo n.º 1
0
    def test_if_public_ip_detect_script_failue_is_handled(
            self, master_ar_process_perclass, valid_user_header):
        url = master_ar_process_perclass.make_url_from_path('/metadata')
        filter_regexp = {
            'Traceback \(most recent call last\):':
            SearchCriteria(1, True),
            ("FileNotFoundError: \[Errno 2\] No such file or directory:"
             " '/usr/local/detect_ip_public_data.txt'"):
            SearchCriteria(1, True),
        }
        lbf = LineBufferFilter(
            filter_regexp,
            line_buffer=master_ar_process_perclass.stderr_line_buffer)

        with lbf, overriden_file_content(
                '/usr/local/detect_ip_public_data.txt'):
            os.unlink('/usr/local/detect_ip_public_data.txt')
            resp = requests.get(url,
                                allow_redirects=False,
                                headers=valid_user_header)

        assert resp.status_code == 200
        assert lbf.extra_matches == {}
        resp_data = resp.json()
        assert resp_data['PUBLIC_IPV4'] == "127.0.0.1"
Exemplo n.º 2
0
    def test_if_public_ip_detect_script_execution_is_timed_out(
            self, master_ar_process_perclass, valid_user_header):
        url = master_ar_process_perclass.make_url_from_path('/metadata')

        ts_start = time.time()
        with overriden_file_content('/usr/local/detect_ip_public_data.txt',
                                    "timeout 10"):
            requests.get(url, allow_redirects=False, headers=valid_user_header)
        ts_total = time.time() - ts_start

        assert ts_total < 10
Exemplo n.º 3
0
    def test_if_public_ip_detect_script_nonzero_exit_status_is_handled(
            self, master_ar_process_perclass, valid_user_header):
        url = master_ar_process_perclass.make_url_from_path('/metadata')

        with overriden_file_content('/usr/local/detect_ip_public_data.txt',
                                    "break with 1"):
            resp = requests.get(url,
                                allow_redirects=False,
                                headers=valid_user_header)

        assert resp.status_code == 200
        resp_data = resp.json()
        assert resp_data['PUBLIC_IPV4'] == "127.0.0.1"
Exemplo n.º 4
0
    def test_if_public_ip_detection_works(self, master_ar_process_perclass,
                                          valid_user_header, public_ip):
        url = master_ar_process_perclass.make_url_from_path('/metadata')

        with overriden_file_content('/usr/local/detect_ip_public_data.txt',
                                    "return ip {}".format(public_ip)):
            resp = requests.get(url,
                                allow_redirects=False,
                                headers=valid_user_header)

        assert resp.status_code == 200
        resp_data = resp.json()
        assert resp_data['PUBLIC_IPV4'] == public_ip
Exemplo n.º 5
0
    def test_if_missing_clusterid_file_is_handled(
            self, master_ar_process_perclass, valid_user_header):
        url = master_ar_process_perclass.make_url_from_path('/metadata')

        with overriden_file_content('/var/lib/dcos/cluster-id'):
            os.unlink('/var/lib/dcos/cluster-id')
            resp = requests.get(
                url,
                allow_redirects=False,
                headers=valid_user_header)

        assert resp.status_code == 200
        resp_data = resp.json()
        assert 'CLUSTER_ID' not in resp_data
Exemplo n.º 6
0
    def test_if_dcos_metadata_is_served(
            self, master_ar_process_perclass, valid_user_header, content):
        url = master_ar_process_perclass.make_url_from_path(
            '/dcos-metadata/dcos-version.json')

        with overriden_file_content(
                '/opt/mesosphere/active/dcos-metadata/etc/dcos-version.json',
                content):
            resp = requests.get(
                url,
                allow_redirects=False,
                headers=valid_user_header
                )

        assert resp.status_code == 200
        assert resp.text == content
Exemplo n.º 7
0
    def test_if_buildinfo_is_served(
            self, master_ar_process_perclass, valid_user_header, content):
        url = master_ar_process_perclass.make_url_from_path(
            '/pkgpanda/active.buildinfo.full.json')

        with overriden_file_content(
                '/opt/mesosphere/active.buildinfo.full.json',
                content):
            resp = requests.get(
                url,
                allow_redirects=False,
                headers=valid_user_header
                )

        assert resp.status_code == 200
        assert resp.text == content
Exemplo n.º 8
0
    def test_if_metadata_files_are_handled(self, master_ar_process,
                                           valid_user_header, uniq_content,
                                           path):

        url = master_ar_process.make_url_from_path(
            '/dcos-metadata/{}'.format(path))

        with overriden_file_content(
                '/opt/mesosphere/active/dcos-metadata/etc/{}'.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
Exemplo n.º 9
0
    def test_if_login_url_works(
        self,
        nginx_class,
        oa_redir,
        oa_client_id,
        oa_cluster_id,
    ):
        ar = nginx_class(ouath_client_id=oa_client_id,
                         ouath_auth_redirector=oa_redir)
        url = ar.make_url_from_path('/login?a=1&b=2')
        expected_path = "{}/login?client={}&cluster_id={}&a=1&b=2".format(
            oa_redir, oa_client_id, oa_cluster_id)

        with overriden_file_content('/var/lib/dcos/cluster-id', oa_cluster_id):
            with GuardedSubprocess(ar):
                r = requests.get(url, allow_redirects=False)

        assert r.status_code == 302
        assert r.headers['Location'] == expected_path
Exemplo n.º 10
0
    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 overriden_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')
Exemplo n.º 11
0
    def test_if_clusterid_is_returned(self, master_ar_process_perclass,
                                      valid_user_header):
        url = master_ar_process_perclass.make_url_from_path('/metadata')

        resp = requests.get(url,
                            allow_redirects=False,
                            headers=valid_user_header)

        assert resp.status_code == 200
        resp_data = resp.json()
        assert resp_data[
            'CLUSTER_ID'] == 'fdb1d7c0-06cf-4d65-bb9b-a8920bb854ef'

        with overriden_file_content('/var/lib/dcos/cluster-id',
                                    "fd21689b-4fe2-4779-8c30-9125149eef11"):
            resp = requests.get(url,
                                allow_redirects=False,
                                headers=valid_user_header)

        assert resp.status_code == 200
        resp_data = resp.json()
        assert resp_data[
            'CLUSTER_ID'] == "fd21689b-4fe2-4779-8c30-9125149eef11"