예제 #1
0
 def setUp(self):
     """
     测试case开始
     :resurn:
     """
     Gremlin().gremlin_post('graph.truncateBackend();',
                            auth=auth)  # gremlin语句进行clear操作
     # 创建group
     body = {
         "group_name": "gremlin",
         "group_description": "group can execute gremlin"
     }
     code, res = Auth().post_groups(body, auth=auth)
     print(code, res)
     # 创建 target
     body = {
         "target_url":
         '%s:%d' % (_cfg.graph_host, _cfg.server_port),
         "target_name":
         "gremlin",
         "target_graph":
         _cfg.graph_name,
         "target_resources": [{
             "type": "GREMLIN",
             "properties": None,
             "label": "*"
         }]
     }
     code, res = Auth().post_targets(body, auth=auth)
     print(code, res)
예제 #2
0
 def test_target_update(self):
     """
     获取 target
     """
     # premise
     body = {
         "target_url":
         '%s:%d' % (_cfg.graph_host, _cfg.server_port),
         "target_name":
         "gremlin",
         "target_graph":
         _cfg.graph_name,
         "target_resources": [{
             "type": "GREMLIN",
             "properties": None,
             "label": "*"
         }]
     }
     code, res = Auth().post_targets(body, auth=auth)
     print(code, res)
     # test
     body = {
         "target_name": "gremlin",
         "target_url": '%s:%d' % (_cfg.graph_host, _cfg.server_port),
         "target_graph": _cfg.graph_name,
         "target_resources": [{
             "type": "VERTEX"
         }]
     }
     code, res = Auth().update_targets(body, res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 200, msg='code check fail')
     self.assertEqual(res['target_resources'][0]['type'], 'VERTEX',
                      'res check fail')
예제 #3
0
 def __init__(self):
     """初始化"""
     self.auth = Auth()
     self.target_graph = _cfg.graph_name
     self.target_url = _cfg.graph_host + ":" + str(_cfg.server_port)
     self.auth_user = "******"
     self.auth_password = _cfg.test_password['tester']
예제 #4
0
 def test_user_delete(self):
     """
     删除 user
     """
     # premise
     body = {"user_name": "tester", "user_password": "******"}
     code, res = Auth().post_users(body, auth=auth)
     print(code, res)
     # test
     code, res = Auth().delete_users(res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 204, msg='code check fail')
예제 #5
0
 def test_user_one(self):
     """
     获取user
     """
     # premise
     body = {"user_name": "tester", "user_password": "******"}
     code, res = Auth().post_users(body, auth=auth)
     print(code, res)
     # test
     code, res = Auth().get_user(res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 200, msg='code check fail')
     self.assertEqual(res['id'], '-63:tester', 'res check fail')
예제 #6
0
 def test_access_delete(self):
     """
     删除 access
     """
     # premise
     body = {
         'group': '-69:gremlin',
         'target': '-77:gremlin',
         'access_permission': 'EXECUTE'
     }
     code, res = Auth().post_accesses(body, auth=auth)
     # test
     code, res = Auth().delete_accesses(res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 204, msg='code check fail')
예제 #7
0
 def test_groups_delete(self):
     """
     删除 groups
     """
     # premise
     body = {
         "group_name": "gremlin",
         "group_description": "group can execute gremlin"
     }
     code, res = Auth().post_groups(body, auth=auth)
     print(code, res)
     # test
     code, res = Auth().delete_groups(res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 204, msg='code check fail')
예제 #8
0
 def test_groups_one(self):
     """
     获取 group
     """
     # premise
     body = {
         "group_name": "gremlin",
         "group_description": "group can execute gremlin"
     }
     code, res = Auth().post_groups(body, auth=auth)
     print(code, res)
     # test
     code, res = Auth().get_group(res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 200, msg='code check fail')
     self.assertEqual(res['id'], '-69:gremlin', 'res check fail')
예제 #9
0
 def test_user_one_role(self):
     """
     获取user角色
     """
     # premise
     permission_list = [{
         'target_list': [
             {
                 'type': 'GRANT'
             },
             # {'type': 'STATUS'}
         ],
         'permission': 'WRITE',
         'name': 'grant_write'
     }]
     user_id = set_auth.post_auth(permission_list)
     # test
     code, res = Auth().get_users_role(user_id, auth=auth)
     print(code, res)
     self.assertEqual(code, 200, msg='code check fail')
     self.assertEqual(
         res['roles'], {
             'hugegraph': {
                 'WRITE': [{
                     'type': 'GRANT',
                     'label': '*',
                     'properties': None
                 }]
             }
         }, 'res check fail')
예제 #10
0
 def test_belong_delete(self):
     """
     删除 belong
     """
     # premise
     body = {
         'group': '-69:gremlin',
         'user': '******',
         'belong_description': 'belong gremlin'
     }
     code, res = Auth().post_belongs(body, auth=auth)
     print(code, res)
     # test
     code, res = Auth().delete_belongs(res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 204, msg='code check fail')
예제 #11
0
 def test_access_list(self):
     """
     获取 access
     """
     # premise
     body = {
         'group': '-69:gremlin',
         'target': '-77:gremlin',
         'access_permission': 'EXECUTE'
     }
     code, res = Auth().post_accesses(body, auth=auth)
     # test
     code, res = Auth().get_accesses(auth=auth)
     print(code, res)
     self.assertEqual(code, 200, msg='code check fail')
     self.assertEqual(res['accesses'][0]['id'],
                      'S-69:gremlin>-88>18>S-77:gremlin', 'res check fail')
예제 #12
0
 def test_access_update(self):
     """
     更新 access
     """
     # premise
     body = {
         'group': '-69:gremlin',
         'target': '-77:gremlin',
         'access_permission': 'EXECUTE'
     }
     code, res = Auth().post_accesses(body, auth=auth)
     # test
     body = {"access_description": "access description rename"}
     code, res = Auth().update_accesses(body, res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 200, msg='code check fail')
     self.assertEqual(res['id'], 'S-69:gremlin>-88>18>S-77:gremlin',
                      'res check fail')
예제 #13
0
 def test_belong_one(self):
     """
     获取 belong
     """
     # premise
     body = {
         'group': '-69:gremlin',
         'user': '******',
         'belong_description': 'belong gremlin'
     }
     code, res = Auth().post_belongs(body, auth=auth)
     print(code, res)
     # test
     code, res = Auth().get_belong(res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 200, msg='code check fail')
     self.assertEqual(res['id'], 'S-63:tester>-82>>S-69:gremlin',
                      'res check fail')
예제 #14
0
 def setUp(self):
     """
     测试case开始
     :resurn:
     """
     Gremlin().gremlin_post('graph.truncateBackend();',
                            auth=auth)  # gremlin语句进行clear操作
     # 创建group
     body = {
         "group_name": "gremlin",
         "group_description": "group can execute gremlin"
     }
     code, res = Auth().post_groups(body, auth=auth)
     print(code, res)
     # 创建 user
     body = {"user_name": "tester", "user_password": "******"}
     code, res = Auth().post_users(body, auth=auth)
     print(code, res)
예제 #15
0
 def test_user_create(self):
     """
     创建 user
     """
     body = {"user_name": "tester", "user_password": "******"}
     code, res = Auth().post_users(body, auth=auth)
     print(code, res)
     self.assertEqual(code, 201, msg='code check fail')
     self.assertEqual(res['id'], '-63:tester', 'res check fail')
예제 #16
0
 def test_belong_update(self):
     """
     更新 belong
     """
     # premise
     body = {
         'group': '-69:gremlin',
         'user': '******',
         'belong_description': 'belong gremlin'
     }
     code, res = Auth().post_belongs(body, auth=auth)
     print(code, res)
     # test
     body = {"belong_description": "belong description rename"}
     code, res = Auth().update_belongs(body, res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 200, msg='code check fail')
     self.assertEqual(res['id'], 'S-63:tester>-82>>S-69:gremlin',
                      'res check fail')
예제 #17
0
 def test_user_update(self):
     """
     获取 user
     """
     # premise
     body = {"user_name": "tester", "user_password": "******"}
     code, res = Auth().post_users(body, auth=auth)
     print(code, res)
     # test
     body = {
         "user_name": "tester",
         "user_password": "******",
         "user_phone": "138",
         "user_avatar": "tester.png",
         "user_email": "*****@*****.**"
     }
     code, res = Auth().update_users(body, res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 200, msg='code check fail')
     self.assertEqual(res['user_avatar'], 'tester.png', 'res check fail')
예제 #18
0
 def test_groups_update(self):
     """
     更新groups
     """
     # premise
     body = {
         "group_name": "gremlin",
         "group_description": "group can execute gremlin"
     }
     code, res = Auth().post_groups(body, auth=auth)
     print(code, res)
     # test
     body = {
         "group_name": "gremlin",
         "group_description": "group_update  description"
     }
     code, res = Auth().update_groups(body, res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 200, msg='code check fail')
     self.assertEqual(res['group_description'], 'group_update  description',
                      'res check fail')
예제 #19
0
 def test_groups_create(self):
     """
     创建 groups
     """
     body = {
         "group_name": "gremlin",
         "group_description": "group can execute gremlin"
     }
     code, res = Auth().post_groups(body, auth=auth)
     print(code, res)
     self.assertEqual(code, 201, 'code check fail')
     self.assertEqual(res['group_name'], 'gremlin', 'code check fail')
예제 #20
0
 def test_access_create(self):
     """
     创建 access
     """
     body = {
         'group': '-69:gremlin',
         'target': '-77:gremlin',
         'access_permission': 'EXECUTE'
     }
     code, res = Auth().post_accesses(body, auth=auth)
     print(code, res)
     self.assertEqual(code, 201, msg='code check fail')
     self.assertEqual(res['id'], 'S-69:gremlin>-88>18>S-77:gremlin',
                      'res check fail')
예제 #21
0
 def test_belong_create(self):
     """
     创建 belong
     """
     body = {
         'group': '-69:gremlin',
         'user': '******',
         'belong_description': 'belong gremlin'
     }
     code, res = Auth().post_belongs(body, auth=auth)
     print(code, res)
     self.assertEqual(code, 201, msg='code check fail')
     self.assertEqual(res['id'], 'S-63:tester>-82>>S-69:gremlin',
                      'res check fail')
예제 #22
0
 def test_target_delete(self):
     """
     删除 target
     """
     # premise
     body = {
         "target_url":
         '%s:%d' % (_cfg.graph_host, _cfg.server_port),
         "target_name":
         "gremlin",
         "target_graph":
         _cfg.graph_name,
         "target_resources": [{
             "type": "GREMLIN",
             "properties": None,
             "label": "*"
         }]
     }
     code, res = Auth().post_targets(body, auth=auth)
     print(code, res)
     # test
     code, res = Auth().delete_targets(res['id'], auth=auth)
     print(code, res)
     self.assertEqual(code, 204, msg='code check fail')
예제 #23
0
 def test_target_create(self):
     """
     创建 target
     """
     body = {
         "target_url":
         '%s:%d' % (_cfg.graph_host, _cfg.server_port),
         "target_name":
         "gremlin",
         "target_graph":
         _cfg.graph_name,
         "target_resources": [{
             "type": "GREMLIN",
             "properties": None,
             "label": "*"
         }]
     }
     code, res = Auth().post_targets(body, auth=auth)
     print(code, res)
     self.assertEqual(code, 201, msg='code check fail')
     self.assertEqual(res['id'], '-77:gremlin', 'res check fail')
예제 #24
0
class AuthBody(object):
    """
    权限公共方法
    """
    def __init__(self):
        """初始化"""
        self.auth = Auth()
        self.target_graph = _cfg.graph_name
        self.target_url = _cfg.graph_host + ":" + str(_cfg.server_port)
        self.auth_user = "******"
        self.auth_password = _cfg.test_password['tester']

    def create_target(self, target_list, name):
        """
        创建资源
        """
        body = {
            "target_name": name + "_target",
            "target_graph": self.target_graph,
            "target_url": self.target_url,
            "target_resources": target_list
        }
        status, res = self.auth.post_targets(body=body, auth=auth)
        # print(status, res)
        return res["id"]

    def create_group(self, name):
        """创建组"""
        body = {
            "group_name": name + "_group",
            "group_description": "%s graph_test" % (name + "_group")
        }
        status, res = self.auth.post_groups(body, auth=auth)
        # print(status, res)
        return res["id"]

    def create_access(self, group, target, premission):
        """创建group到target的连接"""
        body = {
            "group": group,
            "target": target,
            "access_permission": premission
        }
        status, res = self.auth.post_accesses(body, auth=auth)
        # print(status, res)
        return res["id"]

    def create_user(self):
        """创建用户user"""
        user_id = ''
        status, res = self.auth.get_users(auth=auth)
        for user in res['users']:
            if user['user_name'] == self.auth_user:
                user_id = user['id']
            else:
                pass
        if user_id == '':
            body = {
                "user_name": self.auth_user,
                "user_password": self.auth_password,
            }
            status, res = self.auth.post_users(body, auth=auth)
            user_id = res['id']
        return user_id

    def create_belong(self, user, group):
        """创建用户的授权"""
        body = {
            "user": user,
            "group": group,
        }
        status, res = self.auth.post_belongs(body, auth=auth)
        # print(status, res)

    def create_auth(self,
                    type_list,
                    permission,
                    target_name="target_name",
                    groupname="group_test",
                    name="test001",
                    pw="123456"):
        """创建一个用户,并为其指定权限"""
        target_id = self.create_target(type_list, target_name)
        group_id = self.create_group(groupname)
        access_id = self.create_access(group_id, target_id, permission)
        user_id = self.create_user()
        self.create_belong(user_id, group_id)
        return user_id