Exemplo n.º 1
0
def test_026_share_param_hosts(to_check, request):
    depends(request, ['CLUSTER_SMB_SHARE_CREATED'])

    rando_ips = ["192.168.0.240", "192.168.0.69"]
    payload = {to_check: rando_ips}
    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/sharing/smb/id/{SMB_SHARE_ID}'
    res = make_request('put', url, data=payload)
    assert res.status_code == 200, res.text

    for ip in CLUSTER_IPS:
        payload = {
            'msg': 'method',
            'method': 'smb.getparm',
            'params': [f'hosts {to_check[5:]}', "CL_SMB"]
        }
        res = make_ws_request(ip, payload)
        assert res.get('error') is None, res

        assert res['result'] == rando_ips

    payload = {to_check: []}
    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/sharing/smb/id/{SMB_SHARE_ID}'
    res = make_request('put', url, data=payload)
    assert res.status_code == 200, res.text

    for ip in CLUSTER_IPS:
        payload = {
            'msg': 'method',
            'method': 'smb.getparm',
            'params': [f'hosts {to_check[5:]}', "CL_SMB"]
        }
        res = make_ws_request(ip, payload)
        assert res.get('error') is None, res

        assert res['result'] == []
Exemplo n.º 2
0
def test_024_share_comment(request):
    depends(request, ['CLUSTER_SMB_SHARE_CREATED'])
    payload = {"comment": "test comment"}
    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/sharing/smb/id/{SMB_SHARE_ID}'
    res = make_request('put', url, data=payload)
    assert res.status_code == 200, res.text

    for ip in CLUSTER_IPS:
        payload = {
            'msg': 'method',
            'method': 'smb.getparm',
            'params': ["comment", "CL_SMB"]
        }
        res = make_ws_request(ip, payload)
        assert res.get('error') is None, res
        assert res['result'] == 'test comment'

    payload = {"comment": ""}
    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/sharing/smb/id/{SMB_SHARE_ID}'
    res = make_request('put', url, data=payload)
    assert res.status_code == 200, res.text

    for ip in CLUSTER_IPS:
        payload = {
            'msg': 'method',
            'method': 'smb.getparm',
            'params': ["comment", "CL_SMB"]
        }
        res = make_ws_request(ip, payload)
        assert res.get('error') is None, res
        assert res['result'] == ''
def test_010_filesystem_setperm_recursive(request):
    depends(request, ['FS_BASIC_TEST_FILES_CREATED'])
    payload = {
        "path": CLUSTER_PATH,
        "mode": "777",
        "options": {
            "recursive": True
        }
    }
    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/filesystem/setperm/'
    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text

    try:
        status = wait_on_job(res.json(), CLUSTER_IPS[0], 5)
    except JobTimeOut:
        assert False, JobTimeOut
    else:
        assert status['state'] == 'SUCCESS', status

    payload = {'path': CLUSTER_PATH}
    url = f'http://{CLUSTER_IPS[1]}/api/v2.0/filesystem/listdir/'
    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text
    data = res.json()
    for entry in data:
        mode = stat.S_IMODE(entry['mode']) & ~stat.S_IFDIR
        assert entry['acl'] is False
        assert f'{mode:03o}' == '777'
Exemplo n.º 4
0
def test_003_bind_ldap(request):
    depends(request, ['DS_LDAP_NETWORK_CONFIGURED'])

    payload = {
        "hostname": [CLUSTER_LDAP['HOSTNAME']],
        "basedn": CLUSTER_LDAP['BASEDN'],
        "binddn": CLUSTER_LDAP['BINDDN'],
        "bindpw": CLUSTER_LDAP['BINDPW'],
        "ssl": "ON",
        "enable": True
    }
    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/ldap/'
    res = make_request('put', url, data=payload)
    assert res.status_code == 200, res.text

    try:
        status = wait_on_job(res.json()['job_id'], CLUSTER_IPS[0], 300)
    except JobTimeOut:
        assert False, JobTimeOut
    else:
        assert status['state'] == 'SUCCESS', status

    for ip in CLUSTER_IPS:
        payload = {
            'msg': 'method',
            'method': 'ldap.started',
        }
        res = make_ws_request(ip, payload)
        assert res.get('error') is None, res

        url = f'http://{ip}/api/v2.0/ldap/get_state'
        res = make_request('get', url)
        assert res.status_code == 200, f'ip: {ip}, res: {res.text}'
        assert res.json() == 'HEALTHY'
Exemplo n.º 5
0
def test_050_leave_activedirectory(request):
    depends(request, ['JOINED_AD'])

    payload = {
        "username": CLUSTER_ADS['USERNAME'],
        "password": CLUSTER_ADS['PASSWORD']
    }
    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/activedirectory/leave/'
    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text

    try:
        status = wait_on_job(res.json(), CLUSTER_IPS[0], 300)
    except JobTimeOut:
        assert False, JobTimeOut
    else:
        assert status['state'] == 'SUCCESS', status

    for ip in CLUSTER_IPS:
        url = f'http://{ip}/api/v2.0/activedirectory/get_state'
        res = make_request('get', url)
        assert res.status_code == 200, f'ip: {ip}, res: {res.text}'
        assert res.json() == 'DISABLED'

        url = f'http://{ip}/api/v2.0/activedirectory/started'
        res = make_request('get', url)
        assert res.status_code == 200, f'ip: {ip}, res: {res.text}'
        assert res.json() is False
Exemplo n.º 6
0
def test_006_validate_kerberos_settings(ip, request):
    depends(request, ['JOINED_AD'])

    payload = {
        'query-filters': [["realm", "=", CLUSTER_ADS['DOMAIN'].upper()]],
        'query-options': {'get': True},
    }
    url = f'http://{ip}/api/v2.0/kerberos/realm'
    res = make_request('get', url, data=payload)
    assert res.status_code == 200, res.text

    payload = {
        'query-filters': [["name", "=", 'AD_MACHINE_ACCOUNT']],
        'query-options': {'get': True},
    }
    url = f'http://{ip}/api/v2.0/kerberos/keytab'
    res = make_request('get', url, data=payload)
    assert res.status_code == 200, res.text

    # check that kinit succeeded
    payload = {
        'msg': 'method',
        'method': 'kerberos.check_ticket',
    }
    res = make_ws_request(ip, payload)
    assert res.get('error') is None, res

    # check that keytab was generated
    payload = {
        'msg': 'method',
        'method': 'kerberos.keytab.kerberos_principal_choices',
    }
    res = make_ws_request(ip, payload)
    assert res.get('error') is None, res
    assert len(res['result']) != 0, res
Exemplo n.º 7
0
def test_003_join_activedirectory(request):
    depends(request, ['DS_NETWORK_CONFIGURED'])

    payload = {
        "domainname": CLUSTER_ADS['DOMAIN'],
        "bindname": CLUSTER_ADS['USERNAME'],
        "bindpw": CLUSTER_ADS['PASSWORD'],
        "enable": True
    }
    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/activedirectory/'
    res = make_request('put', url, data=payload)
    assert res.status_code == 200, res.text

    try:
        status = wait_on_job(res.json()['job_id'], CLUSTER_IPS[0], 300)
    except JobTimeOut:
        assert False, JobTimeOut
    else:
        assert status['state'] == 'SUCCESS', status

    # Need to wait a little for cluster state to settle down

    for ip in CLUSTER_IPS:
        url = f'http://{ip}/api/v2.0/activedirectory/started'
        res = make_request('get', url)
        assert res.status_code == 200, f'ip: {ip}, res: {res.text}'
        assert res.json()

        url = f'http://{ip}/api/v2.0/activedirectory/get_state'
        res = make_request('get', url)
        assert res.status_code == 200, f'ip: {ip}, res: {res.text}'
        assert res.json() == 'HEALTHY'
Exemplo n.º 8
0
def test_005_validate_cached_ad_accounts(ip, request):
    depends(request, ['DS_ACCOUNTS_CONFIGURED'])

    payload = {
        'query-filters': [["method", "=", "activedirectory.fill_cache"]],
        'query-options': {'order_by': ['-id']},
    }
    url = f'http://{ip}/api/v2.0/core/get_jobs'
    res = make_request('get', url, data=payload)
    assert res.status_code == 200, res.text

    try:
        status = wait_on_job(res.json()[0]['id'], ip, 300)
    except JobTimeOut:
        assert False, JobTimeOut
    else:
        assert status['state'] == 'SUCCESS', status

    payload = {
        'query-filters': [["local", "=", False]],
        'query-options': {'extra': {"additional_information": ['DS']}},
    }
    url = f'http://{ip}/api/v2.0/user'
    res = make_request('get', url, data=payload)
    assert res.status_code == 200, res.text
    assert len(res.json()) != 0, 'No cached users'

    url = f'http://{ip}/api/v2.0/group'
    res = make_request('get', url, data=payload)
    assert res.status_code == 200, res.text
    assert len(res.json()) != 0, 'No cached groups'
Exemplo n.º 9
0
def add_peers():
    """
    Add the peers to the TSP (Trusted Storage Pool). We choose a single
    node to send these requests since glusterd coordinates the network
    requests to the other nodes.
    """
    nodes = [v for k, v in CLUSTER_INFO.items() if k in ('NODE_B_DNS', 'NODE_C_DNS')]
    for node in nodes:
        # start the job to add a peer
        ans = make_request('post', f'http://{CLUSTER_INFO["NODE_A_IP"]}/api/v2.0/gluster/peer', data={'hostname': node})
        assert ans.status_code == 200, ans.text

        # wait on the peer to be added
        try:
            status = wait_on_job(ans.json(), CLUSTER_INFO['NODE_A_IP'], 10)
        except JobTimeOut:
            assert False, JobTimeOut
        else:
            assert status['state'] == 'SUCCESS', status

    # query a node for the peers (it returns all peer information)
    ans = make_request('get', '/gluster/peer')
    assert ans.status_code == 200, ans.text
    # use casefold() for purpose of hostname validation sense case does not matter
    # but the resolvable names on the network might not match _exactly_ with what
    # was given to us in the config (i.e. DNS1.HOSTNAME.BLAH == DNS1.hostname.BLAH)
    assert set([i['hostname'].casefold() for i in ans.json()]) == set([i.casefold() for i in GPD]), ans.json()
Exemplo n.º 10
0
    def setUpClass(cls):
        """Standart SetUpClass method of unittest.TestCase."""
        cls.api_rooms_url = 'http://makechat-web/api/rooms'
        cls.api_login_url = 'http://makechat-web/api/login'

        User.drop_collection()  # erase the users collection
        Room.drop_collection()  # erase the rooms collection

        cls.user = User.objects.create(
            username='******', email='*****@*****.**',
            password=encrypt_password('test'))

        cls.admin = User.objects.create(
            username='******', email='*****@*****.**',
            password=encrypt_password('admin'), is_superuser=True)

        res = make_request(prepare_request(
            cls.api_login_url, {'username': '******', 'password': '******'}))
        cls.user_session = res.headers['set-cookie'] \
            .split(';')[0].split('=')[1]

        res = make_request(prepare_request(
            cls.api_login_url, {'username': '******', 'password': '******'}))
        cls.admin_session = res.headers['set-cookie'] \
            .split(';')[0].split('=')[1]
Exemplo n.º 11
0
def test_050_unbind_ldap(request):
    depends(request, ['BOUND_LDAP'])

    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/ldap'
    payload = {
        "has_samba_schema": False,
        "enable": False,
    }
    res = make_request('put', url, data=payload)
    assert res.status_code == 200, res.text

    try:
        status = wait_on_job(res.json()['job_id'], CLUSTER_IPS[0], 300)
    except JobTimeOut:
        assert False, JobTimeOut
    else:
        assert status['state'] == 'SUCCESS', status

    for ip in CLUSTER_IPS:
        url = f'http://{ip}/api/v2.0/ldap/get_state'
        res = make_request('get', url)
        assert res.status_code == 200, f'ip: {ip}, res: {res.text}'
        assert res.json() == 'DISABLED'

        payload = {
            'msg': 'method',
            'method': 'ldap.started',
        }
        res = make_ws_request(ip, payload)
        assert res.get('error') is None, res
Exemplo n.º 12
0
    def test_return_type(self):
        page = make_request(self.test_url)
        self.assertIn("Countries of the World: A Simple Example", page.title.text)

        text = make_request(self.test_url, return_type="text")
        self.assertIn("<!doctype html>", text.strip()[:32])

        response = make_request(self.test_url, return_type="response")
        self.assertEquals(response.status_code, 200)
Exemplo n.º 13
0
    def test_proxy_check(self):
        blocked_proxy_check = lambda r: "scrape this site" in r.text.lower()
        allowed_proxy_check = lambda r: "scrape this site" not in r.text.lower()

        with self.assertRaises(TypeError):
            # TypeError due to trying to remove null proxy from proxy list
            make_request(self.test_url, proxy_check=blocked_proxy_check)

        make_request(self.test_url, proxy_check=allowed_proxy_check)
Exemplo n.º 14
0
def setup_network(ip):
    # the cluster nodes are assigned an IP
    # address via DHCP reservations, however,
    # it's a prerequisite that the peers in
    # the cluster have static IP addresses
    result = {'ERROR': ''}

    # setup router/dns/defgw first
    print(f'Setting up default gateway and dns on {ip}')
    url = f'http://{ip}/api/v2.0/network/configuration'
    payload = {
        'ipv4gateway': CLUSTER_INFO['DEFGW'],
        'nameserver1': CLUSTER_INFO['DNS1']
    }
    ans = make_request('put', url, data=payload)
    if ans.status_code != 200:
        result['ERROR'] = f'Failed to configure gateway on {ip}:{ans.text}'
        return result

    # setup the static IP address
    print(f'Setting up static ip on {ip}')
    url = f'http://{ip}/api/v2.0/interface/id/{CLUSTER_INFO["INTERFACE"]}'
    payload = {
        'ipv4_dhcp': False,
        'aliases': [{
            'address': ip,
            'netmask': CLUSTER_INFO['NETMASK'],
        }],
    }
    ans = make_request('put', url, data=payload)
    if ans.status_code != 200:
        result[
            'ERROR'] = f'Failed to configure static IP information for {ip}:{ans.text}'
        return result

    # commit changes
    print(f'Commit network changes on {ip}')
    url = f'http://{ip}/api/v2.0/interface/commit'
    payload = {'rollback': True, 'checkin_timeout': 5}
    ans = make_request('post', url, data=payload)
    if ans.status_code != 200:
        result[
            'ERROR'] = f'Failed to commit static IP information for {ip}:{ans.text}'
        return result

    # checkin the changes (finalize them)
    print(f'Checkin network changes on {ip}')
    url = f'http://{ip}/api/v2.0/interface/checkin'
    ans = make_request('get', url)
    if ans.status_code != 200:
        result[
            'ERROR'] = 'Failed to commit static IP information for {ip}:{ans.text}'
        return result

    return result
Exemplo n.º 15
0
    def test_1_create_token(self):
        """Attempt to create token."""
        res = make_request(prepare_request(
            self.api_tokens_url, {'name': 'token1'}, session=self.session))
        self.assertEqual(res.content.get('name'), 'token1')
        self.assertEqual(res.code, 201)

        res = make_request(prepare_request(
            self.api_tokens_url, {'name': 'token2'}, session=self.session))
        self.assertEqual(res.content.get('name'), 'token2')
        self.assertEqual(res.code, 201)
Exemplo n.º 16
0
def test_004_verify_ad_accounts_present(ip, request):
    depends(request, ['JOINED_AD'])

    payload = {"username": f'administrator@{CLUSTER_ADS["DOMAIN"]}'}
    url = f'http://{ip}/api/v2.0/user/get_user_obj/'
    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text

    payload = {"groupname": fr'{CLUSTER_ADS["DOMAIN"]}\domain users'}
    url = f'http://{ip}/api/v2.0/group/get_group_obj/'
    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text
Exemplo n.º 17
0
def fetch_metrics(project_name, organization_name):

    should_look_for_more_issues = True
    page = 1
    all_issues = [[]]
    all_comments = [{'total': 0, 'avg_len':0, 'total_len':0}]
    index = 0
    week_number = None

    while(should_look_for_more_issues):
        link = u.github_issues_link(organization_name, project_name, page)

        issues = u.make_request(link)

        for issue in issues:
            comments = u.make_request(link=issue['comments_url'])

            issue['created_at'] = u.get_datetime_object(issue['created_at'])
            
            if(week_number is None):
                week_number = u.get_week_number(issue['created_at'])

            number_of_commented_chars = 0

            for comment in comments:
                string = comment['body']
                number_of_commented_chars += len(string)

            if(u.get_week_number(issue['created_at']) is week_number):
                all_issues[index].append(issue)
                all_comments[index]['total'] += len(comments)
                all_comments[index]['total_len'] += number_of_commented_chars
            else:
                week_number = u.get_week_number(issue['created_at'])
                
                try:
                    all_comments[index]['avg_len'] = all_comments[index]['total_len']/all_comments[index]['total']
                except ZeroDivisionError:
                    all_comments[index]['avg_len'] = 0.0
                
                index += 1

                all_issues.append([issue])
                all_comments.append({'total': len(comments), 'avg_len':0, 'total_len': number_of_commented_chars})

        if(len(issues) is 0):
            should_look_for_more_issues = False
        else:
            page+=1

    return {'issues': all_issues[::-1], 'comments': all_comments[::-1]}
def test_002_enable_and_start_ssh(ip, request):
    depends(request, ['FS_BASIC_GLUSTER_VOLUME_MOUNTED'])

    payload = {
        "rootlogin": True,
    }
    url = f'http://{CLUSTER_IPS[1]}/api/v2.0/ssh/'
    res = make_request('put', url, data=payload)
    assert res.status_code == 200, res.text

    url = f'http://{ip}/api/v2.0/service/start'
    payload = {"service": "ssh"}
    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text
Exemplo n.º 19
0
def test_004_verify_ldap_accounts_present(ip, request):
    depends(request, ['BOUND_LDAP'])

    passwd = ssh_test(ip, "getent passwd")

    payload = {"username": CLUSTER_LDAP["TEST_USERNAME"]}
    url = f'http://{ip}/api/v2.0/user/get_user_obj/'
    res = make_request('post', url, data=payload)
    assert res.status_code == 200, passwd['output']

    payload = {"groupname": CLUSTER_LDAP["TEST_GROUPNAME"]}
    url = f'http://{ip}/api/v2.0/group/get_group_obj/'
    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text
Exemplo n.º 20
0
def get_all_repos_from_org(organization_name, startswith_text=''):
    should_look_for_more_projects = True
    page = 1
    project_list = []

    while(should_look_for_more_projects):
        link = u.github_projects_from_organization_link(organization_name, page)

        projects = u.make_request(link)

        if 'message' in projects:
            if projects['message'] == 'Not Found':
                print("Looks like {0} is not an organization. Maybe you typed the wrong name.".format(organization_name))
                exit(0)

        for project in projects:
            if project['name'].startswith(startswith_text):
                project_list.append(project['name'])

        if(len(projects) is 0):
            should_look_for_more_projects = False
        else:
            page+=1

    return project_list
Exemplo n.º 21
0
 def download_feature_info(self):
     try:
         search_url = self.feature_info_url + self.clear_code(self.code)
         self.log("Start downloading area info: %s" % search_url)
         response = make_request(search_url)
         resp = response
         data = json.loads(resp)
         if data:
             feature = data.get("feature")
             if feature:
                 attrs = feature.get("attrs")
                 if attrs:
                     self.attrs = attrs
                     self.code_id = attrs["id"]
                 if feature.get("extent"):
                     self.extent = feature["extent"]
                 if feature.get("center"):
                     x = feature["center"]["x"]
                     y = feature["center"]["y"]
                     if self.coord_out == "EPSG:4326":
                         (x, y) = xy2lonlat(x, y)
                     self.center = {"x": x, "y": y}
                     self.attrs["center"] = self.center
                     self.log("Area info downloaded.")
             return feature
     except TimeoutException:
         raise TimeoutException()
     except Exception as error:
         self.error(error)
     return False
Exemplo n.º 22
0
 def test_3_get_all_rooms(self):
     """Attempt to get all rooms."""
     res = make_request(prepare_request(
         self.api_rooms_url, {}, method='GET', session=self.admin_session))
     self.assertEqual(res.code, 200)
     self.assertEqual([
         x['name'] for x in res.content['items']], ['room1', 'room2'])
Exemplo n.º 23
0
def test_031_verify_share_removed(ip, request):
    depends(request, ['CLUSTER_SMB_SHARE_CREATED'])

    url = f'http://{ip}/api/v2.0/sharing/smb?id={SMB_SHARE_ID}'
    res = make_request('get', url)
    assert res.status_code == 200, res.text
    assert res.json() == [], res.text
Exemplo n.º 24
0
def test_027_knownfail_invalid_cluster_params(to_check, request):
    depends(request, ['CLUSTER_SMB_SHARE_CREATED'])

    payload = {to_check: True}
    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/sharing/smb/id/{SMB_SHARE_ID}'
    res = make_request('put', url, data=payload)
    assert res.status_code == 422, res.text
Exemplo n.º 25
0
    def test_2_invalid_creds(self):
        """Attempt to login with incorrect credentials."""
        # invalid password
        res = make_request(prepare_request(
            self.api_url, {'username': '******', 'password': '******'}))
        self.assertEqual(res.code, 401)

        # invalid username
        res = make_request(prepare_request(
            self.api_url, {'username': '******', 'password': '******'}))
        self.assertEqual(res.code, 401)

        # invalid username and password
        res = make_request(prepare_request(
            self.api_url, {'username': '******', 'password': '******'}))
        self.assertEqual(res.code, 401)
Exemplo n.º 26
0
 def get_account_info(self):
     """
     Get user's account info.
     """
     
     url = '%s/v1/account' % api_base_url
     return make_request(url)
Exemplo n.º 27
0
def test_001_validate_smb_bind_ips(ip, request):
    url = f'http://{ip}/api/v2.0/smb/bindip_choices'
    res = make_request('get', url)
    assert res.status_code == 200, res.text

    smb_ip_set = set(res.json().values())
    cluster_ip_set = set(PUBLIC_IPS)
    assert smb_ip_set == cluster_ip_set, smb_ip_set
Exemplo n.º 28
0
def test_032_disable_smb(ip, request):
    depends(request, ["SMB_SERVICE_STARTED"])

    url = f'http://{ip}/api/v2.0/service/stop'
    payload = {"service": "cifs"}

    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text
Exemplo n.º 29
0
def test_008_disable_recycle(request):
    depends(request, ['CLUSTER_SMB_SHARE_CREATED'])
    payload = {
        "recyclebin": False,
    }
    url = f'http://{CLUSTER_IPS[1]}/api/v2.0/sharing/smb/id/{SMB_SHARE_ID}'
    res = make_request('put', url, data=payload)
    assert res.status_code == 200, res.text
Exemplo n.º 30
0
def test_004_start_smb_service(ip, request):
    depends(request, ['CLUSTER_SMB_SHARE_CREATED'])

    url = f'http://{ip}/api/v2.0/service/start'
    payload = {"service": "cifs"}

    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text
Exemplo n.º 31
0
 def test_3_valid_form_data_email_exist(self):
     """Attempt to register with valid form data and existing email."""
     res = make_request(prepare_request(
         self.api_url, {'username': '******', 'email': '*****@*****.**',
                        'password1': 'test3', 'password2': 'test3'}))
     self.assertEqual(res.code, 400)
     self.assertEqual(res.content.get('description'),
                      'Email is already taken.')
Exemplo n.º 32
0
def test_008_create_clustered_smb_share(request):
    depends(request, ['JOINED_AD'])
    global ds_smb_share_id
    global ds_wrk

    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/filesystem/mkdir/'
    res = make_request('post', url, data=SHARE_FUSE_PATH)
    assert res.status_code == 200, res.text

    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/user/get_user_obj/'
    payload = {"username": f'{CLUSTER_ADS["USERNAME"]}@{CLUSTER_ADS["DOMAIN"]}'}
    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text
    user_obj = res.json()

    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/filesystem/chown/'
    payload = {"path": SHARE_FUSE_PATH, "uid": user_obj["pw_uid"]}
    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text

    try:
        status = wait_on_job(res.json(), CLUSTER_IPS[0], 300)
    except JobTimeOut:
        assert False, JobTimeOut
    else:
        assert status['state'] == 'SUCCESS', status

    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/sharing/smb/'
    payload = {
        "comment": "AD clustered SMB share",
        "path": '/ds_smb_share_01',
        "name": "DS_CL_SMB",
        "purpose": "NO_PRESET",
        "shadowcopy": False,
        "cluster_volname": CLUSTER_INFO["GLUSTER_VOLUME"]
    }

    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text
    ds_smb_share_id = res.json()['id']

    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/smb'
    res = make_request('get', url)
    assert res.status_code == 200, res.text
    ds_wrk = res.json()['workgroup']
Exemplo n.º 33
0
def test_002_validate_network_configuration(ip, request):
    depends(request, ['VALID_SMB_BIND_IPS'])

    url = f'http://{ip}/api/v2.0/network/configuration/'
    res = make_request('get', url)
    assert res.status_code == 200, res.text

    data = res.json()
    assert data['nameserver1'] == CLUSTER_INFO['DNS1']
    assert data['ipv4gateway'] == CLUSTER_INFO['DEFGW']

    payload = CLUSTER_ADS['DOMAIN']
    url = f'http://{ip}/api/v2.0/activedirectory/domain_info/'
    res = make_request('post', url, data=payload)
    assert res.status_code == 200, res.text

    domain_info = res.json()
    assert abs(domain_info['Server time offset']) < 180
Exemplo n.º 34
0
def get(url):
    return utils.make_request(
        'GET',
        url,
        headers={
            'user-agent': config.gh_user_agent,
            'Authorization': 'token {}'.format(config.gh_token),
            'Accept': 'application/vnd.github.black-cat-preview+json',
        })
Exemplo n.º 35
0
def test_022_enable_streams(request):
    depends(request, ['CLUSTER_SMB_SHARE_CREATED'])

    payload = {
        "streams": True,
    }
    url = f'http://{CLUSTER_IPS[0]}/api/v2.0/sharing/smb/id/{SMB_SHARE_ID}'
    res = make_request('put', url, data=payload)
    assert res.status_code == 200, res.text
Exemplo n.º 36
0
def add_public_ips_to_ctdb():
    for priv_ip, pub_ip in zip(CLUSTER_IPS, PUBLIC_IPS):
        res = make_request('post', f'http://{priv_ip}/api/v2.0/ctdb/general/status', data={'all_nodes': False})
        this_node = res.json()[0]['pnn']

        payload = {
            'pnn': this_node,
            'ip': pub_ip,
            'netmask': CLUSTER_INFO['NETMASK'],
            'interface': CLUSTER_INFO['INTERFACE']
        }
        res = make_request('post', f'http://{priv_ip}/api/v2.0/ctdb/public/ips', data=payload)
        try:
            status = wait_on_job(res.json(), priv_ip, 5)
        except JobTimeOut:
            assert False, JobTimeOut
        else:
            assert status['state'] == 'SUCCESS', status
Exemplo n.º 37
0
 def wrapper(url_id):
     """For cache"""
     payload = {'user_id': 0, 'recid': url_id}
     response = utils.make_request(
         _PG_API_URL + '/group/referral', json.dumps(payload),
         method='POST')
     logging.info(response)
     if response.get('success'):
         url_id = response.get('reason')
     return url_id
Exemplo n.º 38
0
 def test_2_get_user_tokens(self):
     """Attempt to get user tokens."""
     res = make_request(prepare_request(
         self.api_tokens_url, {}, method='GET', session=self.session))
     self.assertEqual(res.code, 200)
     items = res.content['items']
     self.assertEqual(len(items), 2)
     self.assertEqual(items[0]['name'], 'token1')
     self.assertEqual(items[0]['user']['$oid'], str(self.user.pk))
     self.assertEqual(items[1]['name'], 'token2')
     self.assertEqual(items[1]['user']['$oid'], str(self.user.pk))
Exemplo n.º 39
0
    def get_videos(self, uuid=None):
        """
        Get videos for this user.

        If there is a uuid provided, we'll retrieve a single video's details.
        If there is no uuid, it will get all the videos in the user's account.
        """

        url = '%s/v1/videos' % api_base_url
        if uuid:
            url = '%s/%s' % (url, uuid)
        return make_request(url)
Exemplo n.º 40
0
    def create_video(self, data=None):
        """
        Create a new video.

        Will throw an APIError if there is no json_data present.
        """

        if not data:
            raise APIError("You must provide a data to create a video.")

        url = '%s/v1/videos' % api_base_url
        return make_request(url, 'POST', data)
Exemplo n.º 41
0
    def test_2_create_room_wit_admin_permissions(self):
        """Attempt to create room with admin permissions."""
        res = make_request(prepare_request(
            self.api_rooms_url, {'name': 'room1'}, session=self.admin_session))
        self.assertEqual(res.code, 201)
        self.assertEqual(res.content.get('name'), 'room1')
        self.assertEqual(res.content.get('members'), [
            {
                '$oid': str(
                    Member.objects.get(profile=self.admin, role='owner').id)
            }
        ])

        res = make_request(prepare_request(
            self.api_rooms_url, {'name': 'room2'}, session=self.admin_session))
        self.assertEqual(res.code, 201)
        self.assertEqual(res.content.get('name'), 'room2')
        self.assertEqual(res.content.get('members'), [
            {
                '$oid': str(
                    Member.objects.get(profile=self.admin, role='owner').id)
            }
        ])
Exemplo n.º 42
0
    def get_video_status(self, uuid=None):
        """
        Get the video's status.

        If the video is currently encoding, we can see how far along it is.
        If the video is done encoding, or there was an error, we can find that
        out here as well.
        """

        if not uuid:
            raise APIError("You must provide a uuid to update a video.")

        url = '%s/v1/videos/%s/status' % (api_base_url, uuid)
        return make_request(url, 'GET')
Exemplo n.º 43
0
    def setUpClass(cls):
        """Standart SetUpClass method of unittest.TestCase."""
        cls.api_tokens_url = 'http://makechat-web/api/tokens'
        cls.api_login_url = 'http://makechat-web/api/login'

        User.drop_collection()  # erase the users collection
        Token.drop_collection()  # erase the tokens collection

        cls.user = User.objects.create(
            username='******', email='*****@*****.**',
            password=encrypt_password('test'))

        res = make_request(prepare_request(
            cls.api_login_url, {'username': '******', 'password': '******'}))
        cls.session = res.headers['set-cookie'].split(';')[0].split('=')[1]
Exemplo n.º 44
0
    def update_video(self, uuid=None, data=None):
        """
        Update an existing video.

        A uuid and some json data (dict) are required here.
        """

        if not uuid:
            raise APIError("You must provide a uuid to update a video.")
        if not data:
            raise APIError("You must provide a data to update a video.")

        url = '%s/v1/videos' % api_base_url
        url = '%s/%s' % (url, uuid)
        return make_request(url, 'PUT', data)
Exemplo n.º 45
0
    def get_authorization_response(self, object):
        '''Defines the HTTP POST request to SugarSync's API and returns a 
        HTTP Response. Normally, object should be a child class.'''

        url = object.URL
        # Create the HTTP headers
        headers = { 'User-Agent' : object.USER_AGENT,
                    'Content-Type' : "application/xml; charset=UTF-8" }
        '''If you are serving up XML as the message body without doing any 
        other encoding on it, then you probably want application/xml.'''

        # Make a request using HTTP POST because data keyword param. is not 
        # empty, if data is empty => GET request
        self.request = urllib2.Request(url, data=object.data, headers=headers)
        response = utils.make_request(self.request)

        return response
Exemplo n.º 46
0
    def test_4_invalid_form_data(self):
        """Attempt to register with invalid form data."""
        # username, email, password2 are misssing
        res = make_request(prepare_request(
            self.api_url, {'password1': 'test2'}))
        self.assertEqual(res.code, 400)
        self.assertEqual(res.content.get('title'), 'Missing parameter')

        # email, password2 are misssing
        res = make_request(prepare_request(
            self.api_url, {'username': '******', 'password1': 'test2'}))
        self.assertEqual(res.code, 400)
        self.assertEqual(res.content.get('title'), 'Missing parameter')

        # password2 is misssing
        res = make_request(prepare_request(
            self.api_url, {'username': '******', 'email': '*****@*****.**',
                           'password1': 'test2'}))
        self.assertEqual(res.code, 400)
        self.assertEqual(res.content.get('title'), 'Missing parameter')

        #  Passwords do not match
        res = make_request(prepare_request(
            self.api_url, {'username': '******', 'email': '*****@*****.**',
                           'password1': 'test2', 'password2': '2222'}))
        self.assertEqual(res.code, 400)
        self.assertEqual(res.content.get('description'),
                         'Passwords do not match.')

        #  Bad username string which contains non ASCII chars
        res = make_request(prepare_request(
            self.api_url, {'username': '******', 'email': '*****@*****.**',
                           'password1': 'test2', 'password2': 'test2'}))
        self.assertEqual(res.code, 400)
        self.assertEqual(res.content.get('description'),
                         "{'username': '******'}")

        #  Bad username string which contains non ASCII chars
        res = make_request(prepare_request(
            self.api_url, {'username': '******', 'email': 'test@a',
                           'password1': 'test2', 'password2': 'test2'}))
        self.assertEqual(res.code, 400)
        self.assertEqual(res.content.get('description'),
                         "{'email': 'Invalid Mail-address: test@a'}")
Exemplo n.º 47
0
def post_data(step, url):
    make_request(url, world.post_data)
Exemplo n.º 48
0
 def make_request(self, url):
     response = make_request(url, self.with_proxy)
     return response
Exemplo n.º 49
0
 def test_1_ping_api_user_is_authenticated(self):
     """Attempt to ping api with successful authorization."""
     res = make_request(prepare_request(
         self.api_ping_url, {}, method='GET', session=self.user_session))
     self.assertEqual(res.code, 200)
Exemplo n.º 50
0
 def test_1_valid_creds(self):
     """Attempt to login with correct credentials."""
     res = make_request(prepare_request(
         self.api_url, {'username': '******', 'password': '******'}))
     self.assertEqual(res.code, 200)
Exemplo n.º 51
0
 def test_1_valid_form_data(self):
     """Attempt to register with valid form data."""
     res = make_request(prepare_request(
         self.api_url, {'username': '******', 'email': '*****@*****.**',
                        'password1': 'test2', 'password2': 'test2'}))
     self.assertEqual(res.code, 201)
Exemplo n.º 52
0
 def test_1_create_room_without_admin_permissions(self):
     """Attempt to create room without admin permissions."""
     res = make_request(prepare_request(
         self.api_rooms_url, {'name': 'room1'}, session=self.user_session))
     self.assertEqual(res.code, 403)
Exemplo n.º 53
0
 def delete(self, *args, **kwargs):
     scope = '/admin/directory/v1/groups/{}'.format(self.email)
     request = utils.make_request('DELETE', 'www.googleapis.com', scope)
     return super(MailingList, self).delete(*args, **kwargs)
Exemplo n.º 54
0
 def update(self):
     scope = '/admin/directory/v1/groups/{}'.format(self.email)
     request = utils.make_request('PUT', 'www.googleapis.com', scope)
     return request