Files
novalon-manage-system/test-suite/tests/e2e/test_signature.py
T
张翔 b0f91d74f5 feat: 统一JWT密钥配置并修复签名验证问题
修复前端签名生成中bodyString硬编码问题
添加start-frontend.sh脚本启动前端服务
统一manage-app和gateway的JWT密钥配置
修复Repository扫描路径问题
更新测试配置和依赖
重构表名映射为sys_user和sys_role
完善用户实体类字段映射
添加集成测试配置和测试用例
2026-04-02 12:28:49 +08:00

52 lines
1.4 KiB
Python

import hmac
import hashlib
import base64
import time
import json
import requests
SECRET = 'NovalonManageSystemSecretKey2026'
def generate_signature(method, path, query='', body='', timestamp=None, nonce=None):
if timestamp is None:
timestamp = int(time.time() * 1000)
if nonce is None:
nonce = f"{int(timestamp)}-{hash(time.time())}"
string_to_sign = f"{method}\n{path}\n{query}\n{body}\n{timestamp}\n{nonce}"
signature = hmac.new(
SECRET.encode('utf-8'),
string_to_sign.encode('utf-8'),
hashlib.sha256
).digest()
signature_base64 = base64.b64encode(signature).decode('utf-8')
return signature_base64, timestamp, nonce
method = 'POST'
path = '/api/auth/login'
body = ''
signature, timestamp, nonce = generate_signature(method, path, body=body)
print(f"X-Signature: {signature}")
print(f"X-Timestamp: {timestamp}")
print(f"X-Nonce: {nonce}")
headers = {
'Content-Type': 'application/json',
'X-Signature': signature,
'X-Timestamp': str(timestamp),
'X-Nonce': nonce
}
response = requests.post('http://localhost:8080/api/auth/login',
headers=headers,
data='{"username":"admin","password":"admin123"}',
verify=False)
print(f"\nResponse Status: {response.status_code}")
print(f"Response Body: {response.text}")