Part 05 · Execution · 5.3A
API, networking và security: execution labs
Tập trung vào request bị retry, response bị mất, authorization theo object và network timing thay vì chỉ happy-path controller. Mọi lab phải giữ evidence đã redacted và có gate định lượng.
Safety: chạy trong local/staging cô lập, dùng fixture giả, không dùng credential thật hoặc public target. Ghi version/config, command, timestamps và cleanup.
Lab A · Idempotent POST và lost response
create table idempotency_records (principal_id, operation, key, request_hash, resource_id, status, response, primary key(principal_id, operation, key));
- POST payment/order với
Idempotency-Key; persist key, fingerprint và effect atomically. - Gửi 20 concurrent requests cùng key/payload.
- Commit DB rồi proxy/test hook drop response đầu tiên; client retry cùng key.
- Gửi cùng key nhưng payload/amount khác.
- Thiết kế TTL dài hơn retry/reconciliation window và chạy cleanup.
Assertions
- Một logical operation tạo đúng một effect.
- Retry trả cùng resource/outcome; mismatch trả 409/422 theo contract.
- Timeout giữ trạng thái unknown/reconcile, không bị map thành definite failure.
Lab B · Timeout budget qua nhiều hop
client deadline 2000ms; gateway budget 1800ms; service DB + downstream budget 1500ms; retry attempts nằm trong remaining deadline
- Inject DNS/connect/TLS/first-byte/body delays riêng.
- Đo phase timing và connection-pool wait bằng một trace ID.
- Tạo nested retries ở gateway/service rồi đo amplification.
- Chuyển retry ownership về một layer, thêm jitter/cancellation.
Gate: có waterfall/timeline, downstream attempts trước/sau fix, queue/pool occupancy và tổng latency nằm trong deadline.
Lab C · Object-level authorization
- Tạo user A/B, account/order thuộc A và token B có role hợp lệ.
- Test B đọc/update/delete object A, đổi path/body owner ID và thử mass assignment.
- Test expired/wrong audience/missing scope; phân biệt 401 và 403.
- Audit denied decisions có correlation nhưng không log token/PII.
- Rate-limit theo principal + operation; kiểm tra NAT/shared-IP caveat.
Gate: role hợp lệ không bypass ownership; admin override explicit và audit được; query scope không dựa trên UI.
Deliverables và Definition of Done
- OpenAPI/Problem Details contract và test cases.
- Concurrent duplicate, lost-response và mismatch evidence.
- Network phase evidence, deadline budget và retry-attempt count.
- Authorization matrix theo principal/object/action và negative tests.
- Redaction assertion cho logs, cleanup record và residual-risk note.
Review gate: reviewer phải tái chạy được fixture từ README/runbook, thấy expected failure trước fix và control sau fix, mà không cần secret ngoài phạm vi.