Skip to content

Commit

Permalink
replace PICT depend
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis-me committed Aug 25, 2019
1 parent cc4131b commit 1946b07
Show file tree
Hide file tree
Showing 15 changed files with 526 additions and 227 deletions.
428 changes: 216 additions & 212 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified CHANGELOG.md
Binary file not shown.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* django 2.0.8
* jquery页面和后台交互
* bootstrap3.3 页面框架
* 接口自动生成模糊用例(支持window平台)
* 接口自动生成模糊用例


## 如何使用
Expand All @@ -17,7 +17,7 @@
- 在登录菜单维护登录信息
- 新建模块
- 新建用例
- 管理模糊用例(基于PICT自动生成,暂时只支持windows平台),在lib目下有安装文件
- 管理模糊用例
- 任务管理,关联模块,然后运行任务
- 在DashBroad中查看报告

Expand Down
196 changes: 196 additions & 0 deletions api/Log/292cd06e-c70c-11e9-b1d4-bcee7b76a849.log

Large diffs are not rendered by default.

Empty file added api/Log/param.txt
Empty file.
Empty file added api/Log/param_result.txt
Empty file.
Binary file not shown.
98 changes: 98 additions & 0 deletions api/base/BaseFuzzParams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import uuid
from allpairspy import AllPairs
# pip install allpairspy

from collections import OrderedDict


class BaseFuzzParams(object):
""" 设置接口的逆向参数
自动生成模糊接口参数第一步,提前准备逆向场景
Args:
d: dict类型,正向接口参数
Returns:
dict
Raises:
"""

def __get_data(self, d):
data = {}
for i in d:
data[i] = []
# data[i].append({"info": "正确的值", "code": 1, "value": d[i], "key": i})
data[i].append({"info": "为空", "code": -1, "value": "", "key": i})
data[i].append({"info": "错误的值", "code": -2, "value": self.__param_format(type(d[i])), "key": i})
data[i].append({"info": "删除", "code": -3, "key": i})
return data

'''
生成逆向场景参数
'''

def __param_format(self, key):
if key == str:
return str(uuid.uuid1())
elif key == int:
return 963852 # 也可以使用随机整数的方式
elif key == list:
return [str(uuid.uuid1())]
elif key == dict:
return {}
else:
return "null"

'''
得到逆向场景参数后,用AllPairs生成全对偶参数
'''

def __set_fuzz(self, d):
data = []
for i, par in enumerate(AllPairs(OrderedDict(d))):
app = []
for j in par:
app.append(j)
data.append(app)

dd = []
for i in data:
d = []
for j in range(len(i)):
d.append(i[j])
dd.append(d)

d2 = []
for i in dd:
d1 = []
for j in i:
app = {}
if j.get("code", -9) == -1:
app[j["key"]] = ""
elif j.get("code", -9) == -3:
pass
else:
app[j["key"]] = j["value"]
app["info"] = j["key"] + j["info"]
d1.append(app)
d2.append(d1)
return d2
'''
对外的函数,处理生成的对偶场景接口参数
Returns:
[{},{}]
'''
def param_fi(self, d):
g_data = self.__get_data(d)
s_fuzz = self.__set_fuzz(g_data)
data = []
for i in s_fuzz:
for j in range(len(i)):
_info = ""
for k in range(len(i)):
_info = _info + "," + i[k]["info"]
i[0].update(i[k])
i[0]["info"] = _info
data.append(i[0])
break
return data
5 changes: 3 additions & 2 deletions api/base/BaseReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def file_iterator(file_name, chunk_size=2612000):
break

file_name = os.path.join(settings.BASE_DIR, "api/Log", file_path + ".log")
http_file = "http://192.168.56.1:8001/api/Log/" + file_path + ".log"
http_file = "http://192.168.1.101:8001/api/Log/" + file_path + ".log"
# 192.168.1.100:8001在apache中设置
response = HttpResponse(file_iterator(file_name))
response['Content-Type'] = 'application/octet-stream'
Expand All @@ -79,7 +79,8 @@ def file_iterator(file_name, chunk_size=512):
break

file_name1 = os.path.join(settings.BASE_DIR, "api/Report", file_path + ".xlsx")
http_file = "http://192.168.56.1:8001/api/Report/" + file_path + ".xlsx"
http_file = "http://192.168.1.101:8001/api/Report/" + file_path + ".xlsx"

response = HttpResponse(file_iterator(file_name1))
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{0}"'.format("report.xlsx")
Expand Down
15 changes: 8 additions & 7 deletions api/base/BaseViewFuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from django.views.decorators.csrf import csrf_exempt

from api.base.BaseElementEnmu import Element
from api.base.BaseParams import BaseParams
# from api.base.BaseParams import BaseParams
from ..models import Case, FuzzCase
from ..base.BaseFile import BaseFile as bf


from ..base.BaseFuzzParams import BaseFuzzParams
import ast
class BaseViewFuzz:

@staticmethod
Expand All @@ -25,11 +25,12 @@ def fuzz(request, path, mid, cid):
@staticmethod
@csrf_exempt
def batch_fuzz(id):
bf.mk_file(Element.PICT_PARAM)
bf.mk_file(Element.PICT_PARAM_RESULT)
# bf.mk_file(Element.PICT_PARAM)
# bf.mk_file(Element.PICT_PARAM_RESULT)
c = Case.objects.get(pk=id)
md = model_to_dict(c)
params = BaseParams().param_fi(md["params"])["params"]
# md = model_to_dict(c)
# params = BaseParams().param_fi(md["params"])["params"]
params = BaseFuzzParams().param_fi(ast.literal_eval(c.params))
for i in params:
_info = i["info"]
i.pop("info")
Expand Down
Binary file not shown.
Binary file modified api/base/__pycache__/BaseReport.cpython-35.pyc
Binary file not shown.
Binary file modified api/base/__pycache__/BaseViewFuzz.cpython-35.pyc
Binary file not shown.
7 changes: 3 additions & 4 deletions api/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ var id = 0
$(".btn-log").click(function(){
$.rpc.req("download_log","post",{ "log": $(this).attr("log")},function(resp){
if (resp && resp["code"] == 0) {
alert("成功")
location.reload()
window.location.href = resp["path"]
} else {
if (resp && resp["code"] ) {
alert(resp.msg)
Expand All @@ -42,8 +41,8 @@ var id = 0
$(".btn-excel").click(function(){
$.rpc.req("download_excel","post",{ "excel": $(this).attr("excel")},function(resp){
if (resp && resp["code"] == 0) {
alert("成功")
location.reload()
window.location.href = resp["path"]

} else {
if (resp && resp["code"] ) {
alert(resp.msg)
Expand Down
Binary file modified db.sqlite3
Binary file not shown.

0 comments on commit 1946b07

Please sign in to comment.