remove functions from utils

This commit is contained in:
httprunner
2018-08-11 17:29:48 +08:00
parent ffb9a757e2
commit b92c234951
9 changed files with 48 additions and 58 deletions

View File

@@ -1,9 +1,23 @@
import hashlib
import hmac
import json
from functools import wraps
from httprunner import utils
from flask import Flask, make_response, request
from httprunner.built_in import gen_random_string
try:
from httpbin import app as httpbin_app
HTTPBIN_HOST = "127.0.0.1"
HTTPBIN_PORT = 3458
except ImportError:
httpbin_app = None
HTTPBIN_HOST = "httpbin.org"
HTTPBIN_PORT = 80
FLASK_APP_PORT = 5000
HTTPBIN_SERVER = "http://{}:{}".format(HTTPBIN_HOST, HTTPBIN_PORT)
SECRET_KEY = "DebugTalk"
app = Flask(__name__)
@@ -31,6 +45,17 @@ data structure:
"""
token_dict = {}
def get_sign(*args):
content = ''.join(args).encode('ascii')
sign_key = SECRET_KEY.encode('ascii')
sign = hmac.new(sign_key, content, hashlib.sha1).hexdigest()
return sign
def gen_md5(*args):
return hashlib.md5("".join(args).encode('utf-8')).hexdigest()
def validate_request(func):
@wraps(func)
@@ -74,7 +99,7 @@ def get_token():
data = request.get_json()
sign = data.get('sign', "")
expected_sign = utils.get_sign(user_agent, device_sn, os_platform, app_version)
expected_sign = get_sign(user_agent, device_sn, os_platform, app_version)
if expected_sign != sign:
result = {
@@ -83,7 +108,7 @@ def get_token():
}
response = make_response(json.dumps(result), 403)
else:
token = utils.gen_random_string(16)
token = gen_random_string(16)
token_dict[device_sn] = token
result = {