test(fifa17): harden SBC retail acceptance
This commit is contained in:
@@ -278,7 +278,7 @@ def cmd_parse(args):
|
||||
os.makedirs(out_dir, exist_ok=True)
|
||||
out_path = os.path.join(out_dir, "transactions.jsonl")
|
||||
|
||||
total, skipped = 0, 0
|
||||
total, skipped, filtered = 0, 0, 0
|
||||
with open(out_path, "w") as out:
|
||||
for conn_id in sorted(conns):
|
||||
c = conns[conn_id]
|
||||
@@ -298,6 +298,9 @@ def cmd_parse(args):
|
||||
m = re.match(r"(\S+)\s+(\S+)\s+(HTTP/\d\.\d)", rl)
|
||||
method, target, ver = (m.group(1), m.group(2), m.group(3)) if m else ("?", rl, "?")
|
||||
path, _, query = target.partition("?")
|
||||
if args.path_prefix and not path.startswith(args.path_prefix):
|
||||
filtered += 1
|
||||
continue
|
||||
st = re.match(r"HTTP/\d\.\d\s+(\d+)", sl)
|
||||
req_t, req_unix = time_at(c["marks"]["c2s"], rend - 1)
|
||||
res_t, res_unix = time_at(c["marks"]["s2c"], max(send - 1, 0))
|
||||
@@ -342,9 +345,14 @@ def cmd_parse(args):
|
||||
total += 1
|
||||
|
||||
os.chmod(out_path, 0o644)
|
||||
detail = []
|
||||
if skipped:
|
||||
detail.append("%d unpaired messages reported above" % skipped)
|
||||
if filtered:
|
||||
detail.append("%d transactions excluded by path prefix" % filtered)
|
||||
print("wrote %s (%d transactions across %d connections%s)"
|
||||
% (out_path, total, len(conns),
|
||||
"; %d unpaired messages reported above" % skipped if skipped else ""))
|
||||
"; " + "; ".join(detail) if detail else ""))
|
||||
return 0
|
||||
|
||||
|
||||
@@ -587,6 +595,8 @@ def main():
|
||||
# fixture for the whole response.
|
||||
p.add_argument("--max-body", type=int, default=0,
|
||||
help="bytes; 0 = keep every body in full")
|
||||
p.add_argument("--path-prefix", default="",
|
||||
help="emit only transactions whose request path starts with this prefix")
|
||||
p.set_defaults(fn=cmd_parse)
|
||||
|
||||
s = sub.add_parser("snapshot")
|
||||
|
||||
@@ -123,8 +123,8 @@ def main():
|
||||
|
||||
body = json.dumps({"squad": [1, 2, 3], "note": "x" * 300}).encode()
|
||||
reqs = [
|
||||
b"GET /ut/game/fifa17/userMassInfo HTTP/1.1\r\nHost: t\r\n\r\n",
|
||||
b"POST /ut/game/fifa17/purchased/items HTTP/1.1\r\nHost: t\r\n"
|
||||
b"GET /ut/game/fifa17/sbs/sets HTTP/1.1\r\nHost: t\r\n\r\n",
|
||||
b"POST /ut/game/fifa17/sbs/challenge/101/squad HTTP/1.1\r\nHost: t\r\n"
|
||||
b"Content-Type: application/json\r\nContent-Length: %d\r\n\r\n" % len(body) + body,
|
||||
b"GET /chunked?deviceId=DEADBEEFCAFE&keep=yes HTTP/1.1\r\nHost: t\r\n\r\n",
|
||||
b"GET /ut/game/fifa17/hub HTTP/1.1\r\nHost: t\r\nConnection: close\r\n\r\n",
|
||||
@@ -180,8 +180,8 @@ def main():
|
||||
if len(txs) == 4:
|
||||
check("methods and paths in order",
|
||||
[(t["request"]["method"], t["request"]["path"]) for t in txs] ==
|
||||
[("GET", "/ut/game/fifa17/userMassInfo"),
|
||||
("POST", "/ut/game/fifa17/purchased/items"),
|
||||
[("GET", "/ut/game/fifa17/sbs/sets"),
|
||||
("POST", "/ut/game/fifa17/sbs/challenge/101/squad"),
|
||||
("GET", "/chunked"),
|
||||
("GET", "/ut/game/fifa17/hub")])
|
||||
check("request body preserved byte-for-byte",
|
||||
@@ -210,6 +210,20 @@ def main():
|
||||
qtx is not None and "keep=yes" in qtx["request"]["query"],
|
||||
qtx["request"]["query"] if qtx else "")
|
||||
|
||||
print("== path-scoped fixture ==")
|
||||
r = subprocess.run(
|
||||
[sys.executable, TOOL, "parse", "--session", SESSION,
|
||||
"--path-prefix", "/ut/game/fifa17/sbs/"],
|
||||
capture_output=True, text=True)
|
||||
print(" " + r.stdout.strip().replace("\n", "\n "))
|
||||
filtered = [json.loads(l) for l in
|
||||
open(os.path.join(SESSION, "sanitized", "transactions.jsonl"))]
|
||||
check("SBC prefix emits only the two SBC transactions", len(filtered) == 2,
|
||||
"got %d" % len(filtered))
|
||||
check("SBC save body remains byte-exact after scoped parse",
|
||||
len(filtered) == 2 and
|
||||
base64.b64decode(filtered[1]["request"]["body_b64"]) == body)
|
||||
|
||||
srv.shutdown()
|
||||
print()
|
||||
print("all checks passed" if not fails else "%d FAILED: %s" % (len(fails), fails))
|
||||
|
||||
Reference in New Issue
Block a user