fix(smoke): 手动解析Set-Cookie——cookiejar在http下拒存Secure cookie导致登录态丢失

This commit is contained in:
yumoqing 2026-09-01 16:58:40 +08:00
parent b86b39e051
commit f19fd76c25

View File

@ -89,13 +89,17 @@ def main():
break
if login_case and os.environ.get("SMOKE_PASS"):
status, text, headers, err = req(opener, base, login_case, None, verify_ssl)
# 从 cookiejar 提取会话名
# 手动解析 Set-Cookiecookiejar 在 http:// 下会拒绝带 Secure 属性的 cookie
names = []
for ck in cj:
names.append("%s=%s" % (ck.name, ck.value))
session_cookie = "; ".join(names)
if status != 200:
print("[LOGIN-FAIL] 登录用例返回 %s,后续需登录的用例将跳过: %s" % (status, (err or text[:100])))
if headers is not None:
for hv in headers.get_all("Set-Cookie", []):
pair = hv.split(";", 1)[0].strip()
if "=" in pair:
names.append(pair)
session_cookie = "; ".join(names) if names else None
if status != 200 or not session_cookie:
print("[LOGIN-FAIL] 登录用例返回 %s cookie=%s,后续需登录的用例将跳过: %s"
% (status, bool(session_cookie), (err or text[:100])))
passed, failed, skipped = [], [], []
for c in cases: