Beispiel #1
0
 def saveInterAndUpdateProject(self, interCollectionName, interJson):
     interName = interJson["name"]
     projectId = interJson["projectId"]
     interId = interJson["_id"]
     if interJson["isNewUser"]:
         interJson["username"] = interJson["runUsername"]
         interJson["password"] = interJson["runPassword"]
     else:
         interJson["username"] = ""
         interJson["password"] = ""
     interJson.pop("isNewUser")
     interJson.pop("runUsername")
     interJson.pop("runPassword")
     interJson.pop("projectId")
     interJson.pop("_id")
     interJson.pop("interCollectionName")
     interJson.pop("projectCollectionName")
     if interId == '':
         interId = commonController(interCollectionName).insert(interJson)
         projectInfo = self.projectController.getById(projectId)
         projectInfo.pop("_id")
         interList = projectInfo["list"]
         interList.append({"interId": str(interId), "interName": interName})
         projectInfo["list"] = interList
         updateRes = self.projectController.updateById(
             projectId, projectInfo)
     else:
         updateRes = commonController(interCollectionName).updateById(
             interId, interJson)
     return "done"
Beispiel #2
0
    def request(self, flow: mitmproxy.http.HTTPFlow):

        if flow.request.host == "vhsupply.staging.viewchain.net":
            if "application/json" in flow.request.headers["accept"]:
                self.num = self.num + 1
                sys = "supply"
                interName = flow.request.path
                path = flow.request.path
                method = flow.request.method
                headerList = {}
                paramsList = {}
                for key in flow.request.headers:
                    if key in [
                            "accept", "accept-language", "content-length",
                            "content-type"
                    ]:
                        headerList[key] = flow.request.headers[key]
                if method.lower() == 'post' and flow.request.headers[
                        "content-type"] != "application/x-www-form-urlencoded":
                    paramsList = json.loads(flow.request.get_text())
                    if "_t" in paramsList:
                        paramsList.pop("_t")
                elif method.lower() == 'get':
                    KeyParam = ''
                    ValueParam = ''
                    paramPath = flow.request.path.split("?")[-1]
                    for param in paramPath.split("&"):
                        temp_List = param.split("=")
                        if len(temp_List) == 2:
                            KeyParam = temp_List[0]
                            ValueParam = temp_List[1]
                        elif len(temp_List) == 1:
                            KeyParam = temp_List[0]
                    paramsList[KeyParam] = ValueParam
                    if "_t" in paramsList:
                        paramsList.pop("_t")
                jsonInfo = {
                    "sys": sys,
                    "name": interName,
                    "path": path,
                    "method": method,
                    "header": headerList,
                    "params": paramsList,
                    "projectName": '',
                    "username": '',
                    "password": '',
                    "expectedResult": ''
                }
                interId = commonController("inter").insert(jsonInfo)
                projectInfo["list"].append({
                    "interId": str(interId),
                    "interName": interName
                })
                commonController("interProject").updateById(
                    projectId, projectInfo)
Beispiel #3
0
def getProjectAndIntersByProjectId():
    _id = request.args.get('_id')
    projectCollectionName = request.args.get('projectCollectionName')
    interCollectionName = request.args.get('interCollectionName')
    projectInfo = commonController(
        projectCollectionName).getProjectAndIntersByProjectId(
            _id, interCollectionName)
    return json.dumps(projectInfo)
Beispiel #4
0
 def __init__(self, loginEnvId, loginEnvCollectionName, username, password):
     result = commonController(loginEnvCollectionName).getById(loginEnvId)
     self.supplyUrl = result["supply"]["url"]
     self.supplyPath = result["supply"]["path"]
     self.hospUrl = result["hosp"]["url"]
     self.hospPath = result["hosp"]["path"]
     self.userName = username
     self.passWord = password
Beispiel #5
0
 def __init__(self, collectionName):
     self.projectController = commonController(collectionName)
Beispiel #6
0
 def runInterProjectInter(self, projectId, interId, projectCollectionName,
                          interCollectionName, loginEnvCollectionName):
     projectInfo = commonController(projectCollectionName).getById(
         projectId)
     interInfo = commonController(interCollectionName).getById(interId)
     loginEnvId = projectInfo["loginEnvId"]
     loginEnvInfo = commonController(loginEnvCollectionName).getById(
         loginEnvId)
     supplyUsername = projectInfo["supplyUsername"]
     supplyPassword = projectInfo["supplyPassword"]
     hospUsername = projectInfo["hospUsername"]
     hospPassword = projectInfo["hospPassword"]
     env = loginEnvInfo["name"]
     sys = interInfo["sys"]
     supplyUrl = loginEnvInfo["supply"]["url"]
     supplyPath = loginEnvInfo["supply"]["path"]
     hospUrl = loginEnvInfo["hosp"]["url"]
     hospPath = loginEnvInfo["hosp"]["path"]
     runUsername = ''
     runPassword = ''
     if sys == "supply":
         if interInfo["username"] != '':
             runUsername = interInfo["username"]
             runPassword = interInfo["password"]
         else:
             runUsername = supplyUsername
             runPassword = supplyPassword
     elif sys == "hosp":
         if interInfo["username"] != '':
             runUsername = interInfo["username"]
             runPassword = interInfo["password"]
         else:
             runUsername = hospUsername
             runUsername = hospPassword
     interInfo["expectedResult"] = str(interInfo["expectedResult"]).replace(
         '\\"', '"')
     expectedResult = interInfo["expectedResult"]
     runJson = {
         "sys": sys,
         "path": interInfo["path"],
         "method": interInfo["method"],
         "header": interInfo["header"],
         "params": interInfo["params"],
         "runUsername": runUsername,
         "runPassword": runPassword
     }
     if sys == "supply":
         res = requestsTemp(loginEnvId, loginEnvCollectionName, runUsername,
                            runPassword).supplyRequests(runJson)
     resDict = {}
     resDict["res"] = res
     resStr = json.dumps(res, ensure_ascii=False)
     if expectedResult != '':
         if expectedResult in resStr:
             isPass = True
         else:
             isPass = False
     else:
         isPass = ''
     resDict["isPass"] = isPass
     return resDict
Beispiel #7
0
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("--proxy-server=http://127.0.0.1:8080")
browser = webdriver.Chrome(chrome_options=chromeOptions)
projectName = "系统录制" + str(getTime().getTimestamp())
projectInfo = {
    "name": projectName,
    "author": "系统录制",
    "loginEnvId": "",
    "supplyUsername": "",
    "supplyPassword": "",
    "hospUsername": "",
    "hospPassword": "",
    "description": "该项目为系统录制自动生成的项目",
    "list": []
}
projectId = commonController("interProject").insert(projectInfo)


class Counter:
    def __init__(self):
        self.num = 0

    def request(self, flow: mitmproxy.http.HTTPFlow):

        if flow.request.host == "vhsupply.staging.viewchain.net":
            if "application/json" in flow.request.headers["accept"]:
                self.num = self.num + 1
                sys = "supply"
                interName = flow.request.path
                path = flow.request.path
                method = flow.request.method
Beispiel #8
0
def deleteById():
    _id = request.args.get('_id')
    collectionName = request.args.get('collectionName')
    res = commonController(collectionName).deleteById(_id)
    return res
Beispiel #9
0
def getById():
    _id = request.args.get('_id')
    collectionName = request.args.get('collectionName')
    res = commonController(collectionName).getById(_id)
    return json.dumps(res)
Beispiel #10
0
def getList():
    name = request.args.get('name')
    collectionName = request.args.get('collectionName')
    res = commonController(collectionName).getList(name)
    return json.dumps(res)
Beispiel #11
0
def save():
    jsonInfo = json.loads(request.get_data(as_text=True))
    collectionName = jsonInfo["collectionName"]
    res = commonController(collectionName).save(jsonInfo)
    return res