diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d51e8b..ecc9b1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,18 @@ # Lịch sử thay đổi -## [0.2.0] - Chưa phát hành +## [0.2.1] - Chưa phát hành + +### API và dữ liệu + +- Đã cập nhật năm GET proxy v2 theo myFAP Android 2.0.7/build 32: profile, marks summary, applications, kiểm tra feedback và notification bỏ query `Authen`. Credential vẫn nằm trong Bearer/Checksum; header dùng key mới sau refresh. V1 và output giữ nguyên. Cả năm command đã được nghiệm thu trên CLI v2/HN với HTTP/body 200; xem bằng chứng từ app, CLI và các giới hạn tại [báo cáo build 32](docs/discovery/build32-verification.md). + +## [0.2.0] - 18/11/2026 ### API và dữ liệu - Thêm tùy chọn `--ics` và `--full` cho `myfap exams`: xuất lịch thi ra định dạng iCalendar chuẩn RFC 5545 (giờ Việt Nam, UID/DTSTAMP UTC, CRLF); mặc định xuất ICS đưa đầy đủ các thông tin quan trọng (Môn, Phòng thi `roomNo`, Ngày công bố `dateofPublication`), chỉ ẩn mã slot UUID, ghi chú phụ và điểm danh; cờ `--full` kèm toàn bộ thông tin phụ vào sự kiện lịch; xuất JSON mặc định tiếp tục bảo toàn đầy đủ 100% dữ liệu gốc. - Thêm `myfap other feedbacks` đọc danh sách feedback student qua `GetStudentFeedbacks`, chỉ có trên proxy API v2; envelope đã kiểm chứng live nhưng item schema chưa có positive (danh sách rỗng trên tài khoản kiểm chứng). -- `transcript --pretty` phân tích HTML bảng điểm toàn khóa thành JSON cấu trúc: mỗi bảng giữ header riêng (bảng chính 10 cột `No`…`Status`, bảng phụ 7 cột) và hàng dữ liệu keyed theo header, chuẩn hoá ` `; không dùng `--pretty` vẫn giữ chuỗi HTML nguyên bản theo contract. +- `transcript --pretty` phân tích HTML bảng điểm toàn khóa thành JSON cấu trúc: mỗi bảng giữ header riêng (bảng chính 10 cột `No`…`Status`, bảng phụ 7 cột) và hàng dữ liệu keyed theo header, chuẩn hóa ` `; không dùng `--pretty` vẫn giữ chuỗi HTML nguyên bản theo contract. - `doctor --api-version v2 --online` báo thêm `backend_version` qua `GetVersion` POST bootstrap; GET bị proxy từ chối 405 và route v1 đã 404. `myfap version` vẫn chỉ đọc package version offline. - Thêm [phân tích khoảng trống endpoint](docs/discovery/endpoint-gap-analysis.md) đối chiếu 82 route của APK với adapter: CLI phủ toàn bộ operation đọc student (ngoại trừ `GetStudentFeedbackForm` đang gate có chủ đích chờ `feedbackId` thực tế); donor/employee, login thay thế và OTA được ghi rõ out of scope. - Chuyển training và nhóm rating vào `other`: dùng `myfap other training` và `myfap other rating list`, không giữ command root cũ. Endpoint, policy retry và capability từng version không đổi. diff --git a/docs/cli/command-endpoints.md b/docs/cli/command-endpoints.md index 09c6188..3e707f4 100644 --- a/docs/cli/command-endpoints.md +++ b/docs/cli/command-endpoints.md @@ -4,12 +4,14 @@ Tài liệu này hợp nhất mapping command → operation → method/URL → c ## Bổ sung Phase 6 đang review +**Cập nhật build 32 (18/11/2026):** năm lệnh `other profile`, `marks --summary`, `applications`, `other feedback`, `other notification` chỉ gửi `CampusCode`, `rollNumber` trong query v2, bỏ `Authen`. V1 giữ nguyên. `marks --summary` gọi `GetSemesterMark`; hai luồng xem điểm còn lại dùng `marks` (`GetStudentMark`) và điểm chi tiết (`GetMarkByCourse`). Cả năm command đã được nghiệm thu trên CLI v2/HN với HTTP/body 200. [Báo cáo build 32](../discovery/build32-verification.md) ghi riêng bằng chứng tĩnh, traffic app qua Fiddler và kết quả chạy CLI. + Mapping theo mốc Phase 5 trong tài liệu này được giữ làm lịch sử. Capability đọc mới, query ngoại lệ, doctor và giới hạn hiện tại nằm tại [coverage Phase 6](../discovery/phase6-coverage.md); đối chiếu toàn bộ 82 route của APK với CLI nằm tại [phân tích khoảng trống endpoint](../discovery/endpoint-gap-analysis.md). Các dòng “chưa tích hợp” ở phần inventory Phase 5 bên dưới cần đọc theo mốc commit ban đầu, không phải trạng thái code Phase 6 mới nhất. Chưa publish Phase 6 hoặc đánh dấu các luồng ghi đã đạt. ## Phạm vi theo kế hoạch - **Phase 4:** phủ command đọc hiện có, lập coverage và kiểm chứng live. Xem [coverage Phase 4](../discovery/phase4-coverage.md). -- **Phase 5:** chuẩn bị và nghiệm thu pipeline phát hành. Có code và CI xanh chưa đồng nghĩa đã publish `0.2.0`; xem [checklist Phase 5](../discovery/phase5.md). +- **Phase 5:** chuẩn bị và nghiệm thu pipeline phát hành. Có code và CI xanh chưa đồng nghĩa đã publish `0.2.1`; xem [checklist Phase 5](../discovery/phase5.md). - **Phase 6:** thêm các chức năng/API mới, nghiệm thu trước khi tạo tag/publish theo quyết định ngày 23/10/2026. Không tự mở route chỉ vì có tên trong APK; cần contract, capability, fixture và kiểm chứng riêng. Ba giai đoạn trên theo mục Phase 4–6 trong `PLAN.md` và `PLAN-PHASES.md` của workspace phân tích. Hai file kế hoạch nằm ngoài repository CLI; không cần đóng gói chúng vào artifact. diff --git a/docs/cli/development.md b/docs/cli/development.md index 9e987b6..1316adb 100644 --- a/docs/cli/development.md +++ b/docs/cli/development.md @@ -46,7 +46,7 @@ uv run --locked --group ci python -m unittest discover -s tests -v uv build --out-dir dist uv run --locked --group ci python -m twine check --strict dist/*.whl dist/*.tar.gz uv run --locked --group ci python scripts/check_artifacts.py --dist-dir dist -uv run --locked --group ci python scripts/smoke_install.py --artifact-dir dist --expected-version 0.2.0 +uv run --locked --group ci python scripts/smoke_install.py --artifact-dir dist --expected-version 0.2.1 ``` Thư mục artifact phải chỉ chứa wheel/sdist của version hiện tại và manifest. Nếu còn file build cũ, copy ra ngoài trước khi chạy diff --git a/docs/cli/releasing.md b/docs/cli/releasing.md index 11b0e4e..88e97c0 100644 --- a/docs/cli/releasing.md +++ b/docs/cli/releasing.md @@ -6,9 +6,9 @@ Xem [release notes](../../CHANGELOG.md), [checklist Phase 5](../discovery/phase5 ## 1. Quyết định phạm vi trước release -`0.2.0` mặc định v2 khi chưa có session; option `--api-version`, `MYFAP_API_VER` và binding session có thứ tự ưu tiên như [hướng dẫn chọn version](api-versions.md). CLI không fallback im lặng. Trước tag, maintainer phải xác nhận: +Phiên bản chuẩn bị phát hành là `0.2.1`, mặc định v2 khi chưa có session; option `--api-version`, `MYFAP_API_VER` và binding session có thứ tự ưu tiên như [hướng dẫn chọn version](api-versions.md). CLI không fallback im lặng. Trước tag, maintainer phải xác nhận: -- Chấp nhận phạm vi và known issues trong mục `0.2.0` của `CHANGELOG.md`. +- Chấp nhận phạm vi và known issues trong mục `0.2.1` của `CHANGELOG.md`, cùng các giới hạn còn áp dụng từ `0.2.0`. - Ba finding v1 vẫn được ghi đúng: news/notification HTTP 200/body 201, fee HTTP 404 trên APHL; nguyên nhân chưa biết. Không gọi chúng là đã sửa, empty hợp lệ hoặc unsupported trên mọi campus. - Positive fee/survey được hoãn theo quyết định ngày 19/10/2026; schema live có dữ liệu vẫn chưa kiểm chứng. Việc hoãn không chặn chuyển Phase 5 nhưng không phải bằng chứng backend đạt. - Reader độc lập đã kiểm ICS (lịch học `schedule --ics` và lịch thi `exams --ics`); import vào ứng dụng lịch thật đã kiểm chứng. Theo quyết định ngày 23/10/2026, phát hành `v0.2.0` sau khi hoàn thiện và nghiệm thu phạm vi Phase 6 (toàn bộ read student v1+v2, doctor, transcript --pretty, exams --ics; các thao tác ghi mục 4–5 giữ gate do thiếu dữ liệu tài khoản). @@ -38,7 +38,7 @@ Cấu hình sau cần được maintainer kiểm tra trực tiếp; file workflo ## 3. Chuẩn bị commit và tag 1. Kiểm working tree sạch, PR chuẩn bị release đã merge và lấy `main`/tag mới nhất. -2. Đối chiếu `[project].version`, root package trong `uv.lock`, CLI và artifact. Baseline đã là `0.2.0`; không bump lại từ `0.1.8`. Chỉ chạy `uv lock` khi metadata thực sự đổi, không sửa tay lockfile hoặc dùng `--upgrade` cho release thông thường. +2. Đối chiếu `[project].version`, root package trong `uv.lock`, CLI và artifact; tất cả phải là `0.2.1`. Bản `0.2.0` đã có release, không dùng lại tag hoặc version đó cho bản cập nhật này. Chỉ chạy `uv lock` khi metadata thực sự đổi, không sửa tay lockfile hoặc dùng `--upgrade` cho release thông thường. 3. Kiểm PyPI để biết version mục tiêu đã tồn tại hay chưa. Nếu version đã phát hành trước đó mà không phải đang phục hồi cùng release/artifact, dừng và để maintainer chọn version mới. 4. Chạy regression, build, Twine, validator và cài artifact theo [hướng dẫn phát triển](development.md#kiểm-tra-trên-máy-local). Ghi commit, lệnh, exit code và các phần chưa kiểm chứng. 5. Duyệt mục version trong `CHANGELOG.md`, coverage và quyết định phạm vi ở mục 1. Tag phải trỏ tới commit thuộc `origin/main`. @@ -51,8 +51,8 @@ git switch main git pull --ff-only origin main git status --short --branch # Xác nhận version, notes, CI và phạm vi trước hai lệnh tiếp theo. -git tag -a v0.2.0 -m "Phát hành myfap 0.2.0" -git push origin v0.2.0 +git tag -a v0.2.1 -m "Phát hành myfap 0.2.1" +git push origin v0.2.1 ``` Không dùng `--force`, không di chuyển/xóa tag để sửa một release đã upload. Stable pipeline chỉ nhận tag chuẩn `vX.Y.Z`, không nhận prerelease hoặc thành phần số có zero đứng đầu. diff --git a/docs/cli/v2-contracts.md b/docs/cli/v2-contracts.md index c29f7e9..dbaac55 100644 --- a/docs/cli/v2-contracts.md +++ b/docs/cli/v2-contracts.md @@ -2,6 +2,8 @@ Tài liệu này ghi lại adapter v2 và phạm vi các route còn lại. CLI mặc định v2 khi chưa có session; xem [thứ tự chọn version](api-versions.md) và quy tắc tương thích session cũ. Module transport không tự dò phiên bản, refresh session hoặc diễn giải JSON response. +Hợp đồng GET đã được cập nhật theo APK **2.0.7/build 32**; xem [bằng chứng và giới hạn nghiệm thu](../discovery/build32-verification.md). Nguồn `module_599.js` bên dưới thuộc build 31. Ma trận route ghi rõ những query đã đổi. + ## Transport và operation đã hỗ trợ `myfap.v2.request()` trả về `requests.Response` nguyên bản. Lớp gọi phía trên chịu trách nhiệm chạy `read_response`, phân loại `401` và quyết định retry. Transport chỉ dựng request, kiểm tra tham số và che lỗi mạng khỏi thông tin credential. @@ -39,13 +41,13 @@ Các route trên cùng dùng base URL `https://fap-proxy.fpt.edu.vn/MyFAP/`. Hea | `AuthenticationByFeIdCode` | `POST` | unsupported | Nhánh code exchange của app đang tắt | | `GetStudentById` | `GET` | supported | Query `CampusCode`, `rollNumber` | | `RetriveImage` | `GET` | supported | Phase 6: photo JSON opaque; không fetch/decode ảnh | -| `CheckUpdateProfile` | `GET` | supported | Vẫn giữ query `Authen` theo app | +| `CheckUpdateProfile` | `GET` | supported | Build 32: query `CampusCode`, `rollNumber`, không `Authen` | | `GetSemester` | `GET` | supported | Query rỗng | | `GetSubjets` | `GET` | supported | Query `CampusCode` | | `GetSubjectBySemester` | `GET` | supported | Phase 6: query `CampusCode`, `Semester`; không rollNumber | | `GetCourseOfSemester` | `GET` | supported | Phase 6: query `CampusCode`, `semester`, `rollNumber` | | `GetStudentMark` | `GET` | supported | Query `CampusCode`, `rollNumber`, `Semester` | -| `GetSemesterMark` | `GET` | supported | Phase 6: query `CampusCode`, `rollNumber`, `Authen`; không query kỳ, reader riêng | +| `GetSemesterMark` | `GET` | supported | Build 32: query `CampusCode`, `rollNumber`, không `Authen`/kỳ; reader riêng; CLI v2/HN đã live 200/200 | | `GetMarkByCourse` | `GET` | supported | Query `CampusCode`, `CourseId`, `rollNumber` | | `AcademicTranscript` | `GET` | supported | Phase 6: query `CampusCode`, `rollNumber`; policy bound key, live chưa xác minh | | `GetDiemphongtrao` | `GET` | supported | Phase 6: query `CampusCode`, `rollNumber`, `semester`; policy bound key | @@ -59,13 +61,13 @@ Các route trên cùng dùng base URL `https://fap-proxy.fpt.edu.vn/MyFAP/`. Hea | `GetBalance` | `GET` | supported | Phase 6: query `CampusCode`, `rollNumber`; giữ payload, không diễn giải nợ | | `GetTop10News` | `GET` | supported | Query `CampusCode`, `type` | | `SearchNews` | `GET` | supported | Phase 6: query `CampusCode`, `type`, `keysearch` | -| `GetApplication` | `GET` | supported | Vẫn giữ query `Authen` theo app | -| `CheckOpenFeedBack` | `GET` | supported | Vẫn giữ query `Authen` theo app | +| `GetApplication` | `GET` | supported | Build 32: query `CampusCode`, `rollNumber`, không `Authen` | +| `CheckOpenFeedBack` | `GET` | supported | Build 32: query `CampusCode`, `rollNumber`, không `Authen` | | `AddRate` | `POST` | unsupported | Vẫn giữ query `Authen` theo app | | `UpdateTokedevices` | `GET` | unsupported | Query `CampusCode`, `Email`, `tokendevice` | -| `GetNotificationByRoll` | `GET` | supported | Vẫn giữ query `Authen` theo app | +| `GetNotificationByRoll` | `GET` | supported | Build 32: query `CampusCode`, `rollNumber`, không `Authen` | | `UpdateTokenDonor` | `GET` | unsupported | Donor flow | -| `GetNotificationByDonor` | `GET` | unsupported | Vẫn giữ query `Authen` theo app | +| `GetNotificationByDonor` | `GET` | unsupported | Build 32 bỏ query `Authen`; chưa mở donor capability | | `GetTokenWithEmp` | `GET` | unsupported | Employee flow | | `GetAllActiveCampus` | `POST` | supported | Body `{}` | | `GetCampusInfo` | `GET` | supported | Query `CampusCode`, `rollNumber` | @@ -80,7 +82,9 @@ Các route trên cùng dùng base URL `https://fap-proxy.fpt.edu.vn/MyFAP/`. Hea Sau nhóm đọc Phase 6 và đợt mở rộng endpoint 24/10/2026, ma trận có 31 operation được hỗ trợ trong code: 27 operation đọc, 3 bootstrap và 1 handshake. `doctor --api-version v2 --online` gọi `GetApiActive` rồi `GetVersion` bằng bootstrap, không xác nhận session hoặc campus tài khoản. Capability mới chưa đồng nghĩa đã nghiệm thu live; xem [coverage Phase 6](../discovery/phase6-coverage.md). Xem thêm [bảng hợp nhất command/method/URL v1 và v2](command-endpoints.md) để phân biệt capability trong adapter, command thực sự tồn tại và kết quả live. -Bảy route giữ `Authen` trong query của adapter app là `CheckUpdateProfile` (`module_599.js:136`), `GetSemesterMark` (`223`), `GetApplication` (`429`), `CheckOpenFeedBack` (`443`), `AddRate` (`467`), `GetNotificationByRoll` (`491`) và `GetNotificationByDonor` (`532`). Trong số này, CLI đã triển khai năm route `CheckUpdateProfile`, `GetApplication`, `CheckOpenFeedBack`, `GetNotificationByRoll` và `GetSemesterMark`; `AddRate`/`GetNotificationByDonor` vẫn chưa được hỗ trợ. Route điểm danh chi tiết đổi từ `getCourseAttendance` của v1 sang `GetCourseAttendance` ở v2 (`module_599.js:363-364`); wrapper v1 không đủ để ghi nhận capability v2. +Ở build 31, bảy route có query `Authen` là `CheckUpdateProfile`, `GetSemesterMark`, `GetApplication`, `CheckOpenFeedBack`, `AddRate`, `GetNotificationByRoll` và `GetNotificationByDonor` (`module_599.js:136,223,429,443,467,491,532`). Build 32 (`module_604.js`, fn#7514/7538/7594/7598/7614/7622) bỏ trường này ở cả sáu GET; POST `AddRate` giữ nguyên. + +CLI áp dụng query mới cho năm GET đã hỗ trợ. FAP key của binding hiện tại vẫn dùng cho Bearer và Checksum; CLI chưa hỗ trợ `AddRate` hoặc donor. Route điểm danh chi tiết tiếp tục dùng alias v2 `GetCourseAttendance`; contract v1 giữ nguyên. ## Giới hạn hiện tại diff --git a/docs/discovery/build32-verification.md b/docs/discovery/build32-verification.md new file mode 100644 index 0000000..a3ad2b3 --- /dev/null +++ b/docs/discovery/build32-verification.md @@ -0,0 +1,81 @@ +# Đồng bộ hợp đồng myFAP 2.0.7 — build 32 + +CLI được đối chiếu ngày 18/11/2026, lấy commit `0d862be4fb5e3c6b02a7f3708333aeb51b0d9b33` làm mốc. +Báo cáo ghi riêng bằng chứng tĩnh, traffic của app và kết quả nghiệm thu CLI sau sửa. +Quy tắc chọn API giữ nguyên: session mới dùng v2; session cũ thiếu version được hiểu là v1. + +## Hợp đồng thay đổi + +Năm GET v2 dưới đây chỉ gửi `CampusCode`, `rollNumber` trong query, bỏ `Authen`: + +| Command | Operation | Bằng chứng tĩnh build 32 | Fiddler LiveTraffic của app | CLI sau sửa, v2/HN | +|---|---|---|---|---| +| `other profile` | `CheckUpdateProfile` | fn#7514 | #350: HTTP 200, data boolean | Exit 0, HTTP/body 200, data boolean | +| `marks --summary` | `GetSemesterMark` | fn#7538 | Chưa quan sát được request | Exit 0, HTTP/body 200, data list | +| `applications` | `GetApplication` | fn#7594 | #327: HTTP 200, data list rỗng | Exit 0, HTTP/body 200, data list | +| `other feedback` | `CheckOpenFeedBack` | fn#7598 | #351: HTTP 200, data boolean | Exit 0, HTTP/body 200, data boolean | +| `other notification` | `GetNotificationByRoll` | fn#7614 | #296: HTTP 200, data list có phần tử | Exit 0, HTTP/body 200, data list | + +Bytecode cũng xác nhận `GetNotificationByDonor` (fn#7622) bỏ query `Authen`; +CLI vẫn chưa hỗ trợ donor. `AddRate` (fn#7606) tiếp tục giữ `Authen` +trong query POST và chưa được CLI hỗ trợ. + +Nguồn trong workspace phân tích: `new-fap/analysis-32/modules/module_604.js` +và `new-fap/analysis-32/index.android.disasm.txt`. APK base build 32 có SHA-256 +`98025a7d21259249cb8b750432ab2aa6c0f3e3cdb2ee9975ffc8a2c62ad6bfa4`; +bundle Hermes có SHA-256 `490bda4349c4d8e1cc2ed6a6e31519e4ed4f9b6214847f1933000a8134a5961a`. +Các tệp phân tích này không nằm trong repo hoặc package CLI. + +## Header, chữ ký và giới hạn quan sát + +- Bốn request quan sát qua Fiddler có header `Authorization`, `Checksum`, `ClientCode`, + `CampusCode`; không có `X-Signature`. Checksum có timestamp và padding `%3d`, + không thấy double-encode `%253d`. +- Theo bytecode và signer của CLI, Authorization là `Bearer `. + Checksum dùng HMAC-SHA256 trên `MyFAP`, chuyển kết quả + sang Base64, đổi padding `=` thành `%3d` đúng một lần rồi nối `:`. + Query không tham gia HMAC này. +- Fiddler MCP ẩn Authorization và body `code`, nên HTTP 200 chưa đủ để xác nhận + body code 200 hay kiểm tra trực tiếp giá trị credential/HMAC. +- Traffic của app cho thấy request không có query `Authen` đã nhận HTTP 200. + Chưa có thử nghiệm đối chứng để biết backend có từ chối query thừa hay không. +- Các session #649 (`GetStudentMark`) và #632 (`GetMarkByCourse`) là route khác; + chúng không thay thế bằng chứng live cho `GetSemesterMark`. + +## Chính sách CLI và nghiệm thu + +CLI dùng FAP key của binding v2 cho cả Bearer và Checksum trên năm GET, +kể cả sau refresh. Wrapper `GetSemesterMark` của APK gọi helper mà không +truyền credential. CLI giữ chính sách authenticated-read đã được kiểm chứng +ở các lượt đọc trước; không dùng credential rỗng hoặc thử unauth rồi fallback. +V1, OAuth, session, reader summary và giới hạn retry vẫn giữ nguyên. + +Regression dựng request bằng Requests, dùng HTTP giả và credential tổng hợp. +Các test kiểm tra query không chứa key, header đổi sau refresh, v1 giữ query cũ +và output giữ kiểu boolean/list. Dữ liệu notification được tạo riêng cho test, +không sao chép response của tài khoản. + +Ngày 18/11/2026, **5/5 command CLI** đã được nghiệm thu trên v2/HN bằng phiên FEID +mới và file session tạm. Mỗi command gửi một GET, query chỉ có `CampusCode`, +`rollNumber`, có Authorization và Checksum khớp credential/timestamp theo signer +CLI. Cả năm command exit 0, stdout là JSON hợp lệ, HTTP/body 200. Harness quan sát +request tại Requests, giữ nguyên request/response và gọi backend thật; không +phát lại capture hoặc dùng fixture thay backend. Kết quả thô chỉ được xử lý +trong RAM; metadata được lọc trước khi in. Logout exit 0, session và thư mục tạm đã được dọn. + +Kết quả chỉ áp dụng cho một binding v2/HN, chưa xác nhận mọi campus, +tài khoản hoặc tình huống expiry/App Check. Refresh/retry sau sửa được kiểm tra +bằng HTTP giả; chưa thử gây lỗi có chủ ý trên backend thật. CLI đã gọi đúng +`GetSemesterMark`; Fiddler vẫn chưa ghi nhận route này từ app. + +Kiểm thử local: 44 test liên quan đều đạt; toàn bộ suite có 437 test, 433 đạt/4 skip, +exit 0. Hai test mới kiểm tra URL của request và việc từ chối query Authen do caller đưa vào. +Regression URL thất bại ở cả năm operation trước sửa và đạt sau sửa. +Các bước build wheel/sdist, Twine strict, kiểm tra artifact và cài thử bằng pip đều +exit 0, dùng artifact mới trong thư mục tạm ngoài repo. Lượt kiểm tra trên dùng +package `0.2.0`; dependency và pipeline publish giữ nguyên. Bản cập nhật build 32 +được chuẩn bị phát hành dưới version `0.2.1`. + +Rating, push và feedback form/submit tiếp tục tạm hoãn, giữ các điều kiện về schema/ack. +Các finding v1 và TODO positive fee/survey vẫn mở. Báo cáo chỉ ghi metadata, +không kèm giá trị query, token, response thô, thông tin tài khoản hoặc đường dẫn máy cá nhân. diff --git a/docs/discovery/phase4-coverage.md b/docs/discovery/phase4-coverage.md index b3a3ab4..fbac4bd 100644 --- a/docs/discovery/phase4-coverage.md +++ b/docs/discovery/phase4-coverage.md @@ -27,12 +27,14 @@ Xem [command → method → endpoint → URL → capability](../cli/command-endp ## Quy tắc transport +Kết quả Phase 4 trong bảng trên thuộc build 31. Hợp đồng query hiện đã theo [build 32](build32-verification.md); kết quả HTTP/body 200 của lượt cũ không thay thế nghiệm thu CLI sau sửa. + - V2 chỉ gửi các operation có trong allowlist đọc. Route ghi, stub hoặc chưa có capability vẫn bị chặn trước HTTP. - GET và POST dùng header theo capture app: `Accept`, `Accept-Encoding`, `User-Agent`, `ClientCode`, `CampusCode`, `Authorization` và `Checksum`. Chỉ POST có JSON body mới thêm `Content-Type: application/json`. - Các command đọc cần session qua proxy, gồm nhóm `info` và `other`, kiểm tra capability trước khi nạp session. Version được chọn theo option rồi metadata session; lệnh thiếu capability không handshake, refresh hoặc gọi API dữ liệu. - Survey giữ host và chữ ký riêng. Khi dùng session v2, CLI nhắc trên stderr rằng request đi tới `survey.fpt.edu.vn`; stdout vẫn chỉ chứa JSON khi có `--stdout`. - `GetSemester` không có query; `GetWeekByDate` chỉ có `date`; các route còn lại dùng đúng case query trong APK. -- Bốn route `CheckOpenFeedBack`, `CheckUpdateProfile`, `GetApplication` và `GetNotificationByRoll` vẫn có `Authen` trong query. Giá trị này lấy từ credential binding hiện tại, không giữ bản cũ sau refresh. +- Từ build 32, `CheckOpenFeedBack`, `CheckUpdateProfile`, `GetApplication`, `GetNotificationByRoll` và `GetSemesterMark` bỏ query `Authen`. Sau refresh, Bearer/Checksum dùng credential mới; query campus/roll giữ nguyên. - Retry đọc tối đa một lần khi server báo hết phiên rõ ràng. Timeout, 403, 5xx, App Check và lỗi operation không fallback sang v1. - `termID` được giữ opaque; CLI chọn kỳ theo `startDate` và giữ thứ tự server khi ngày trùng nhau. diff --git a/docs/discovery/phase6-coverage.md b/docs/discovery/phase6-coverage.md index 01bd7ee..67e3756 100644 --- a/docs/discovery/phase6-coverage.md +++ b/docs/discovery/phase6-coverage.md @@ -4,6 +4,8 @@ Nhóm đọc ban đầu tại `c829b7004ea2dbb7f99cf1dc3827070039bb9ea5`, bổ s ## Command và contract đã nối qua CLI +Query hiện đã đồng bộ [build 32](build32-verification.md). Ngày 18/11, CLI v2/HN đã gọi đủ năm GET thay đổi, bao gồm `GetSemesterMark`, và đều nhận HTTP/body 200. Kết quả ngày 24/10 bên dưới vẫn thuộc build 31. + URL dữ liệu v1 là `https://api.fpt.edu.vn/fap/api/MyFAP/`; v2 là `https://fap-proxy.fpt.edu.vn/MyFAP/`. Tất cả operation dữ liệu trong bảng dùng GET. Không ghi query có giá trị, token, checksum hoặc thông tin tài khoản vào tài liệu. | Command | Operation | v1 / v2 | Điểm contract quan trọng | Bằng chứng hiện tại | @@ -12,9 +14,9 @@ URL dữ liệu v1 là `https://api.fpt.edu.vn/fap/api/MyFAP/`; v2 l | `courses --semester` | `GetCourseOfSemester` | Có / Có | Query `semester` chữ thường; thiếu option dùng resolver `startDate` | Fixture explicit/latest; live v2/HN 200/200, v1: xem kết quả APHL bên dưới | | `other subjects --semester` | `GetSubjectBySemester` | Có / Có | Query `Semester` chữ hoa; signer v1 là semester; không có option vẫn `GetSubjets`, không lookup kỳ | Fixture hai version; live v2/HN 200/200, v1: xem kết quả APHL bên dưới | | `news --search --type` | `SearchNews` | Có / Có | `type`, `keysearch`; signer v1 là type; search rỗng bị chặn | Fixture Unicode/reserved characters; live v2/HN 200/200 | -| `transcript`, `transcript --pretty` | `AcademicTranscript` | Có / Có | Không lookup kỳ; `--pretty` phân tích HTML thành JSON keyed theo header từng bảng (chuẩn hoá ` `), mặc định giữ chuỗi gốc | Fixture parser/CLI; live v2/HN 200/200 — `--pretty` cho 2 bảng 49+2 dòng, header khớp dữ liệu thật | +| `transcript`, `transcript --pretty` | `AcademicTranscript` | Có / Có | Không lookup kỳ; `--pretty` phân tích HTML thành JSON keyed theo header từng bảng (chuẩn hóa ` `), mặc định giữ chuỗi gốc | Fixture parser/CLI; live v2/HN 200/200 — `--pretty` cho 2 bảng 49+2 dòng, header khớp dữ liệu thật | | `other training --semester` | `GetDiemphongtrao` | Có / Có | Query `semester`; thiếu option dùng resolver | Fixture; live v2/HN 200/200 với bound key, list rỗng | -| `marks --summary` | `GetSemesterMark` | Có / Có | Không có query kỳ; v1 `CampusCode`, `rollNumber`, `Authen`, **không checksum**; v2 có query Authen mới sau refresh | Fixture parser/refresh; live v2/HN 200/200 với envelope data list | +| `marks --summary` | `GetSemesterMark` | Có / Có | Không có query kỳ; v1 giữ `CampusCode`, `rollNumber`, `Authen`, **không checksum**; v2 build 32 chỉ `CampusCode`, `rollNumber`, credential qua header | Fixture parser/refresh; CLI v2/HN live 200/200 cả lịch sử build 31 và nghiệm thu build 32 ngày 18/11 | | `info photo` | `RetriveImage` | Có / Có | Chỉ JSON, bảo toàn chuỗi opaque kể cả HTML entity; không tải URL hoặc decode ảnh | Live v2/HN 200/200, data string; định dạng ảnh chưa xác minh | | `other rating list` | `GetStudentRate` | Có / Không | V1 đọc, ký bằng roll number; v2 stub bị chặn trước load session/HTTP | Fixture và live v1/APHL 200/200, danh sách rỗng | | `other feedbacks` | `GetStudentFeedbacks` | Không / Có | V2-only; query `CampusCode`, `rollNumber`, không query `Authen` (bytecode dòng 613); credential qua header Bearer | Fixture contract; live 24/10 200/200 list rỗng — item schema chưa positive | @@ -29,6 +31,8 @@ Cột v1/v2 là capability trong code, không bảo đảm backend mọi campus ## Policy và phần chưa xác minh +Phần mô tả caller `module_599.js` và thí nghiệm credential dưới đây ghi nhận hành vi ở build 31. Sang build 32, summary bỏ query `Authen`; CLI vẫn giữ chính sách Bearer/Checksum. Xem [báo cáo cập nhật](build32-verification.md). + - Các read mới kế thừa binding và tối đa một refresh/retry khi server báo expiry rõ. Không tự refresh/logout từ 201 không rõ nghĩa, 403, timeout, 5xx hoặc App Check. Capability đọc không mở đường ghi. - Với transcript/training/summary, caller của APK (module_599.js) gọi wrapper GET **không truyền credential header**: wrapper (dòng 898–906) mặc định credential chuỗi rỗng khi thiếu tham số thứ tư, `_buildHeaders` (747–781) khi đó tạo header không `Authorization` và `_makeChecksum` (726–746) ký bằng bootstrap token. Chỉ `GetSemesterMark` (218–224) đặt FAP key trong query `Authen`; `AcademicTranscript` (266–272) và `GetDiemphongtrao` (280–286) chỉ có query campus/roll/semester. CLI giữ **policy authenticated read dùng FAP key của binding hiện tại** cho cả ba — không sao chép credential rỗng của app, không thử unauth rồi fallback, không nới reader chung. Thí nghiệm transport có kiểm soát (bảng cuối file) cho thấy proxy hiện tại **từ chối** mọi biến thể lệch khỏi policy này; vậy nhánh credential rỗng trong bytecode không được server chấp nhận — hoặc app thật bơm token ở tầng khác (Axios wrapper `module_1(Axios2)` chưa phục dựng) hoặc proxy đã đổi hành vi so với APK build 31. CLI không thay đổi. - Reader tổng kết chỉ dành cho `GetSemesterMark`: raw JSON array, envelope có data list, hoặc JSON string chứa trọn array. Giới hạn xử lý cục bộ 1 MiB. Không cắt tùy tiện chuỗi giữa dấu ngoặc; XML/HTML wrapper chưa xác minh bị từ chối bằng lỗi payload an toàn. Reader chung của operation khác không được nới lỏng. diff --git a/docs/discovery/phase6.md b/docs/discovery/phase6.md index 2080d39..b92b09c 100644 --- a/docs/discovery/phase6.md +++ b/docs/discovery/phase6.md @@ -1,5 +1,7 @@ # Phase 6: mở rộng command và endpoint trước phát hành +**Quyết định ngày 18/11/2026:** session mới mặc định dùng v2; session cũ giữ version đã lưu. Quy định v1 mặc định ở mốc 23/10 bên dưới được giữ để tra cứu lịch sử. Xem [quy tắc chọn version](../cli/api-versions.md) và [cập nhật build 32](build32-verification.md). + Nhánh triển khai `feat/phase6-command-expansion` bắt đầu từ `main` tại `75fc7b4aa33a13b9b39eab898f61e2e693f4baf9`, sau khi [PR #9](https://github.com/WindowScary321/myfap-api-cli/pull/9) được merge. Theo quyết định ngày **23/10/2026**, Phase 5 chỉ chuẩn bị pipeline; **hoãn tag/publish đến sau khi hoàn thiện và nghiệm thu phạm vi Phase 6**. Giữ baseline `0.2.0`, Python >=3.9, v1 mặc định và v2 opt-in. Nhóm command đọc đã có implementation và fixture CLI/HTTP; xem [coverage Phase 6](phase6-coverage.md). Dấu đã kiểm bên dưới chỉ áp dụng cho code/fixture được nêu, không thay thế live hoặc nghiệm thu backend. Phần thiếu contract/schema vẫn giữ gate rõ; không đánh dấu toàn Phase 6 hoàn tất khi các yêu cầu bắt buộc còn mở. @@ -31,13 +33,13 @@ Mỗi mục cần đi trọn CLI → wrapper → transport v1/v2 → fixture/tes - [x] **`transcript` → `AcademicTranscript`:** hỗ trợ theo contract cả v1/v2, không lookup kỳ; chưa thêm formatter nghiệp vụ khi schema data chưa được xác minh. - [x] **`other training --semester` → `GetDiemphongtrao`:** query `semester` chữ thường, dùng resolver khi thiếu kỳ; giữ bound credential phù hợp. -- [x] **`marks --summary` → `GetSemesterMark`:** không lookup kỳ hoặc thêm query semester. V1 dùng đúng `CampusCode`, `rollNumber`, `Authen`, **không checksum**; v2 giữ query `Authen` mới sau refresh. +- [x] **`marks --summary` → `GetSemesterMark`:** không lookup kỳ hoặc thêm query semester. V1 dùng `CampusCode`, `rollNumber`, `Authen`, **không checksum**. Từ build 32, v2 bỏ query `Authen`; Bearer/Checksum vẫn dùng key hiện tại. Xem [giới hạn live build 32](build32-verification.md). - [x] Từ chối tổ hợp summary với `--courseid`/`--pretty`; nếu `--semester` không áp dụng thì báo lỗi, không âm thầm bỏ qua. - [x] Reader riêng cho summary kiểm HTTP/App Check/expiry trước khi đọc raw array/envelope/text. Chỉ parse dạng đã có bằng chứng, có giới hạn; malformed/unknown phải báo payload error, không cắt tùy tiện giữa dấu ngoặc rồi trả success. - [x] Chốt khác biệt credential v2 ở các caller decompile của transcript/training/summary bằng bytecode/contract và kiểm đọc. Không mặc định sao chép credential rỗng, thử unauth rồi fallback hoặc nới reader chung cho mọi endpoint. **Nghiệm thu nhóm:** -- [x] Test exact casing, no-semester/no-checksum, signing identity và dựng Authen mới sau refresh; giữ nguyên command marks cũ. +- [x] Test kiểm tra casing và query không có kỳ/checksum. Sau refresh, v1 dựng Authen mới; v2 giữ query không có Authen và ký bằng key hiện tại. Command marks cũ giữ nguyên. - [x] Fixture được ghi rõ synthetic; các schema hoặc credential chưa live xác nhận tiếp tục có nhãn unverified. ## 3. Photo và doctor @@ -106,7 +108,7 @@ Nghiệm thu mục 3 và mở rộng endpoint hoàn tất ngày 24/10/2026 sau k Checkpoint nhóm đọc khép ngày 24/10/2026. (1) Build/Twine/validator/pip smoke chạy lại trên code mới: `uv build` wheel+sdist 0.2.0, Twine strict PASSED cả hai, artifact validator exit 0 với manifest SHA-256 `abcaef1b70e20a1e200b6458c58677d3d6d876c2b50819e6f5e8df73b900dae7` (không docs/tasks/tests/session/capture trong distribution), pip smoke hai venv sạch exit 0; full regression 403 test như trên. (2) Mapping/contract/coverage đã cập nhật kèm phân tích khoảng trống endpoint. (3) Quét toàn bộ lệnh đọc bằng **login/browser mới** với session tạm (hai lượt, đều đã logout): 29 lệnh chạy trong lượt chính — success có dữ liệu gồm cả **attendance detail positive đầu tiên** (param trích cục bộ từ courses) và **news search v2 list(50)**; data rỗng hợp lệ (marks, applications, training, feedbacks, marks --courseid str rỗng); survey giữ not-found theo contract; fee v2 list không rỗng nhưng **không đóng positive fee**; rating list exit 1 đúng thiết kế v1-only trên session v2; lệnh bảng semesters đạt ở lượt phụ (lượt chính sai cú pháp `--stdout` do harness, exit 2 không phải lỗi CLI). Chi tiết metadata tại coverage Phase 6; không dùng 200/nonempty để đóng positive fee/survey và không dùng v2 để đóng finding v1. -Theo yêu cầu mở rộng của maintainer (24/10/2026), `transcript --pretty` phân tích HTML bảng điểm toàn khóa thành JSON cấu trúc: mỗi bảng giữ header riêng và hàng keyed theo header (bảng chính 10 cột `No`…`Status`, bảng phụ 7 cột), chuẩn hoá ` `. Schema chốt bằng phân tích cấu trúc dữ liệu thật trên máy cá nhân (chỉ in skeleton/tên cột, không in giá trị); fixture test tổng hợp theo schema đó. RED→GREEN 5 test (4 parser + 1 CLI seam, gồm nhánh không `--pretty` giữ nguyên chuỗi); full suite 408 test, 404 đạt/4 skip, exit 0; live `--pretty` cho 2 bảng 49+2 dòng đúng header thật, mặc định vẫn giữ chuỗi HTML theo contract cũ. +Theo yêu cầu mở rộng của maintainer (24/10/2026), `transcript --pretty` phân tích HTML bảng điểm toàn khóa thành JSON cấu trúc: mỗi bảng giữ header riêng và hàng keyed theo header (bảng chính 10 cột `No`…`Status`, bảng phụ 7 cột), chuẩn hóa ` `. Schema chốt bằng phân tích cấu trúc dữ liệu thật trên máy cá nhân (chỉ in skeleton/tên cột, không in giá trị); fixture test tổng hợp theo schema đó. RED→GREEN 5 test (4 parser + 1 CLI seam, gồm nhánh không `--pretty` giữ nguyên chuỗi); full suite 408 test, 404 đạt/4 skip, exit 0; live `--pretty` cho 2 bảng 49+2 dòng đúng header thật, mặc định vẫn giữ chuỗi HTML theo contract cũ. Nghiệm thu mục 6 hoàn tất ngày 24/10/2026, trừ hộp cuối chờ maintainer. (1) RED→GREEN ghi cho từng feature mới (feedbacks 3 test, doctor GetVersion, transcript --pretty 5 test) qua CLI thật + HTTP giả, fixture tổng hợp; mutation check trên worktree tạm 3/3 bị test bắt: đổi casing query `semester`→`Semester` ở `get_courses`, đổi signer SearchNews từ type sang `MAGIC_ID`, bỏ guard no-retry trong `_get` — đều làm focused test fail rồi khôi phục. (2) `uv sync --locked --group ci` sạch; full suite **408 test, 404 đạt/4 skip, exit 0 trên cả Python 3.11 lẫn 3.9** (venv 3.9 tạm riêng); `git diff --check` sạch. (3) Build/Twine/validator/pip smoke chạy lại trên commit cuối: manifest SHA-256 `b15ff78b0a7fcca70b249258dbcd4479253bc702eace8bc7b079879caa848131`; CI GitHub Actions đạt trên commit code `8529176` (matrix Ubuntu/Windows × Python 3.9/3.11). (4) Lượt review thứ hai có cấu trúc trên toàn bộ diff PR (14 file code/test, +1355/−30) theo 4 trục: query contract, credential và write safety sạch (khớp mutation và test); parser ghi 4 finding robustness (rowspan rác, `isOnline` boolean, slot vượt nửa đêm, sanitize tên file xuất) — đã ghi vào CHANGELOG known issues và TODO, không phải lỗ hổng bảo mật, chờ maintainer quyết sửa trước `0.2.0` hay nhận known issue. Giới hạn trung thực: kênh agent review độc lập bị giới hạn concurrency của tài khoản sau 4 lần thử, lượt review này do session reviewer thực hiện. README/CHANGELOG/coverage cập nhật theo đúng kết quả. (5) PR #10 Draft từ nhánh riêng; mọi commit push đều có comment SHA/lệnh/exit code/giới hạn. diff --git a/docs/discovery/todo.md b/docs/discovery/todo.md index b2cef08..492e98c 100644 --- a/docs/discovery/todo.md +++ b/docs/discovery/todo.md @@ -9,6 +9,8 @@ Kết quả GitHub Actions và bình luận kiểm tra được theo dõi trực ## Kiểm chứng live còn mở trước khi phát hành +- [x] **CLI theo build 32:** ngày 18/11/2026 đã nghiệm thu năm GET sau sửa query trên v2/HN bằng phiên FEID mới và session tạm. Cả năm command exit 0, HTTP/body 200, stdout là JSON hợp lệ, query không có Authen; lượt chạy bao gồm `marks --summary` (`GetSemesterMark`). Session tạm đã được dọn. [Báo cáo build 32](build32-verification.md) ghi riêng bằng chứng từ app và CLI; kết quả chưa được xác nhận trên campus khác hoặc tình huống hết phiên thật. + - [x] Chạy lại `news`, `other notification` và `other fee` trên v1/APHL bằng session tạm ngày 19/10/2026. News/notification nhận HTTP 200/body 201; fee nhận HTTP 404. Lệnh đối chứng `info student` đạt 200/200 trước và sau; session/lock tạm đã xóa. Xem [báo cáo live v1](phase4-coverage.md#chạy-lại-ba-lệnh-v1-ngày-19102026). - [ ] Xác minh ý nghĩa body 201 của `news` v1 và đối chiếu trường hợp có dữ liệu. Lượt live mới vẫn có `data: null`, message null hoặc không có. Không gộp mọi code 201 vào hết phiên hoặc coi đó là danh sách rỗng hợp lệ. - [ ] Xác định nguyên nhân body 201 của `other notification` v1. Request khớp path/query/checksum của app; session đối chứng vẫn đọc được, chưa xác nhận lỗi thuộc backend hay điều kiện tài khoản. diff --git a/myfap/v2.py b/myfap/v2.py index a51ce0e..1b78f8e 100644 --- a/myfap/v2.py +++ b/myfap/v2.py @@ -1,4 +1,4 @@ -"""HTTP contracts for the opt-in FAP proxy adapter.""" +"""HTTP contracts for the FAP proxy adapter.""" import base64 import hashlib @@ -46,7 +46,6 @@ "GetCampusInfo": ("rollNumber",), "GetWeekByDate": ("date",), } -_AUTHEN_QUERY_OPERATIONS = frozenset({"CheckOpenFeedBack", "CheckUpdateProfile", "GetApplication", "GetNotificationByRoll", "GetSemesterMark"}) READ_OPERATIONS = frozenset(_READ_QUERY_FIELDS) SUPPORTED_OPERATIONS = BOOTSTRAP_OPERATIONS | READ_OPERATIONS | {"AuthenticationByFeId"} @@ -62,7 +61,7 @@ def _positive_int(value): ) -def _read_params(operation, params, campus, credential): +def _read_params(operation, params, campus): query = {} if operation not in {"GetSemester", "GetWeekByDate"}: if params.pop("CampusCode", campus) != campus: @@ -82,9 +81,6 @@ def _read_params(operation, params, campus, credential): if not valid: raise ApiError("Giá trị trong query API v2 không hợp lệ.") query.update(params) - if operation in _AUTHEN_QUERY_OPERATIONS: - # The query and signature must use the same freshly bound key after refresh. - query["Authen"] = credential return query @@ -124,7 +120,7 @@ def request(session, operation, *, credential=None, campus=None, params=None, bo else: if body is not None: raise ApiError("Operation đọc API v2 không nhận JSON body.") - params = _read_params(operation, params, campus, credential) + params = _read_params(operation, params, campus) headers = { "Accept": "application/json, text/plain, */*", "Accept-Encoding": "gzip", diff --git a/pyproject.toml b/pyproject.toml index bdab958..d491836 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "myfap" -version = "0.2.0" +version = "0.2.1" description = "CLI Tool dựa trên MyFAP API dành cho Sinh Viên FPTU" readme = "README.md" license = "MIT" diff --git a/tests/test_api_v2.py b/tests/test_api_v2.py index c991e65..cfe8abd 100644 --- a/tests/test_api_v2.py +++ b/tests/test_api_v2.py @@ -108,7 +108,6 @@ def test_v2_schedule_uses_header_key_exact_parameter_case_and_existing_output(se def test_existing_read_wrappers_use_v2_contracts_and_preserve_output(self): student = {"CampusCode": "TEST", "rollNumber": "TEST+ROLL"} with_semester = {**student, "Semester": "Fall2026"} - with_authen = {**student, "Authen": "FAKE_OLD_KEY"} cases = ( (api.MyFapEssential, "get_week", ("2026-10-17",), "GetWeekByDate", {"date": "2026-10-17"}, "42"), (api.MyFapEssential, "get_news", (), "GetTop10News", {"CampusCode": "TEST", "type": 1}, []), @@ -118,12 +117,17 @@ def test_existing_read_wrappers_use_v2_contracts_and_preserve_output(self): (api.MyFapClient, "get_schedule_by_week", (42, "Fall2026", 2026), "GetActivityStudentByWeek", {**with_semester, "week": 42, "year": 2026}, []), (api.MyFapClient, "get_attendances", ("Fall2026",), "GetStudentAttendances", with_semester, []), (api.MyFapClient, "get_course_attendance", ("Fall2026", "DEMO", "CLASS"), "GetCourseAttendance", {**with_semester, "SubjectCode": "DEMO", "ClassName": "CLASS"}, []), - (api.MyFapClient, "get_applications", (), "GetApplication", with_authen, []), + (api.MyFapClient, "get_applications", (), "GetApplication", student, []), (api.MyFapClient, "get_student_info", (), "GetStudentById", student, [{"fixture": "student"}]), (api.MyFapClient, "get_campus_info", (), "GetCampusInfo", student, [{"fixture": "campus"}]), - (api.MyFapOther, "check_open_feedback", (), "CheckOpenFeedBack", with_authen, True), - (api.MyFapOther, "check_update_profile", (), "CheckUpdateProfile", with_authen, False), - (api.MyFapOther, "get_notification", (), "GetNotificationByRoll", with_authen, []), + (api.MyFapOther, "check_open_feedback", (), "CheckOpenFeedBack", student, True), + (api.MyFapOther, "check_update_profile", (), "CheckUpdateProfile", student, False), + (api.MyFapOther, "get_notification", (), "GetNotificationByRoll", student, [{ + "id": "FAKE-NOTICE", "title": "Synthetic notice", "contents": "Synthetic content", + "entryBy": "FAKE-SENDER", "entryDate": "2026-11-18", "rollnumbers": "TEST+ROLL", + "topic": "Synthetic topic", "campusCode": "TEST", "pType": True, + "uRL": "https://example.invalid/notice", + }]), (api.MyFapOther, "get_fee", (), "GeFeeByRoll", student, [ {"IsPaid": True, "invoice": "FAKE-PAID", "amount": 1000}, {"IsPaid": False, "invoice": "FAKE-UNPAID", "amount": "2000.50"}, @@ -144,7 +148,7 @@ def test_existing_read_wrappers_use_v2_contracts_and_preserve_output(self): self.session.post.assert_not_called() self.auth.refresh_session.assert_not_called() - def test_query_authen_and_canonical_reads_are_rebuilt_after_refresh(self): + def test_v2_reads_keep_query_stable_and_rebind_headers_after_refresh(self): cases = ( (api.MyFapOther, "check_open_feedback", (), "CheckOpenFeedBack"), (api.MyFapOther, "check_update_profile", (), "CheckUpdateProfile"), @@ -173,9 +177,10 @@ def refresh(): self.assertTrue(second.args[0].endswith("/" + operation)) self.assertEqual(second.kwargs["headers"]["Authorization"], "Bearer FAKE_NEW_KEY") self.assertNotEqual(first.kwargs["headers"]["Checksum"], second.kwargs["headers"]["Checksum"]) - if operation in {"CheckOpenFeedBack", "CheckUpdateProfile", "GetNotificationByRoll", "GetApplication"}: - self.assertEqual(first.kwargs["params"]["Authen"], "FAKE_OLD_KEY") - self.assertEqual(second.kwargs["params"]["Authen"], "FAKE_NEW_KEY") + self.assertEqual(first.kwargs["headers"]["Authorization"], "Bearer FAKE_OLD_KEY") + self.assertEqual(first.kwargs["params"], second.kwargs["params"]) + self.assertNotIn("Authen", first.kwargs["params"]) + self.assertNotIn("Authen", second.kwargs["params"]) def test_new_v2_reads_preserve_empty_errors_and_never_fall_back(self): cases = ( diff --git a/tests/test_phase4_transport.py b/tests/test_phase4_transport.py index dd318c4..68648a1 100644 --- a/tests/test_phase4_transport.py +++ b/tests/test_phase4_transport.py @@ -23,9 +23,8 @@ def test_parity_routes_use_exact_app_query_and_bound_credential(self): ("GetSubjets", {}, {"CampusCode": "TEST"}), ("GetWeekByDate", {"date": "2026-10-17"}, {"date": "2026-10-17"}), *((name, self.query, {"CampusCode": "TEST", **self.query}) for name in ( - "GeFeeByRoll", "GetStudentById", "GetCampusInfo")), - *((name, self.query, {"CampusCode": "TEST", **self.query, "Authen": "fake-key"}) for name in ( - "CheckOpenFeedBack", "CheckUpdateProfile", "GetApplication", "GetNotificationByRoll")), + "GeFeeByRoll", "GetStudentById", "GetCampusInfo", "CheckOpenFeedBack", + "CheckUpdateProfile", "GetApplication", "GetNotificationByRoll", "GetSemesterMark")), *((name, self.term_query, {"CampusCode": "TEST", **self.term_query}) for name in ( "GetActivityStudent", "GetStudentMark", "GetScheduleExam", "GetStudentAttendances")), ("GetMarkByCourse", {**self.query, "CourseId": 42}, {"CampusCode": "TEST", **self.query, "CourseId": 42}), @@ -52,15 +51,17 @@ def test_parity_routes_use_exact_app_query_and_bound_credential(self): self.assertNotIn("json", call.kwargs) signer.assert_called_once_with("fake-key") - def test_query_authen_is_rebuilt_from_each_current_credential(self): - for operation in ("CheckOpenFeedBack", "CheckUpdateProfile", "GetApplication", "GetNotificationByRoll"): + def test_build32_query_stays_credential_free_when_headers_change(self): + for operation in ("CheckOpenFeedBack", "CheckUpdateProfile", "GetApplication", "GetNotificationByRoll", "GetSemesterMark"): with self.subTest(operation=operation): self.send(operation, self.query, credential="fake-old") self.send(operation, self.query, credential="fake-new") first, second = self.session.request.call_args_list[-2:] - self.assertEqual(first.kwargs["params"]["Authen"], "fake-old") - self.assertEqual(second.kwargs["params"]["Authen"], "fake-new") + self.assertEqual(first.kwargs["params"], {"CampusCode": "TEST", **self.query}) + self.assertEqual(second.kwargs["params"], first.kwargs["params"]) + self.assertEqual(first.kwargs["headers"]["Authorization"], "Bearer fake-old") self.assertEqual(second.kwargs["headers"]["Authorization"], "Bearer fake-new") + self.assertNotEqual(first.kwargs["headers"]["Checksum"], second.kwargs["headers"]["Checksum"]) self.assertNotIn("Authen", self.query) def test_prepared_get_and_post_requests_use_app_headers(self): diff --git a/tests/test_phase6_summary.py b/tests/test_phase6_summary.py index 1c8dc89..8f072ce 100644 --- a/tests/test_phase6_summary.py +++ b/tests/test_phase6_summary.py @@ -81,8 +81,10 @@ def test_summary_has_exact_query_and_never_looks_up_semester(self): self.assertEqual(json.loads(result.stdout), {"code": 200, "data": [{"synthetic": True}]}) request.assert_called_once() self.assertTrue(request.call_args.args[1].endswith("/GetSemesterMark")) - self.assertEqual(request.call_args.kwargs["params"], { - "CampusCode": "TEST", "rollNumber": "TEST000", "Authen": "FAKE_KEY"}) + query = {"CampusCode": "TEST", "rollNumber": "TEST000"} + if version == "v1": + query["Authen"] = "FAKE_KEY" + self.assertEqual(request.call_args.kwargs["params"], query) if version == "v2": self.assertEqual(request.call_args.kwargs["headers"]["Authorization"], "Bearer FAKE_KEY") @@ -97,7 +99,7 @@ def test_conflicting_summary_options_fail_before_auth(self): self.assertIn("--summary", Text.from_ansi(result.stderr).plain) auth.assert_not_called() - def test_summary_rebuilds_authen_after_single_refresh(self): + def test_summary_refreshes_once_with_version_specific_credentials(self): from pathlib import Path from tempfile import TemporaryDirectory from unittest.mock import patch @@ -118,7 +120,16 @@ def refresh(auth): self.assertEqual(result.exit_code, 0, result.output) self.assertEqual(request.call_count, 2) rotation.assert_called_once() - self.assertEqual(request.call_args.kwargs["params"]["Authen"], "FAKE_NEW") + first, second = request.call_args_list + if version == "v1": + self.assertEqual(first.kwargs["params"]["Authen"], "FAKE_OLD") + self.assertEqual(second.kwargs["params"]["Authen"], "FAKE_NEW") + else: + self.assertEqual(first.kwargs["params"], {"CampusCode": "TEST", "rollNumber": "TEST000"}) + self.assertEqual(second.kwargs["params"], first.kwargs["params"]) + self.assertEqual(first.kwargs["headers"]["Authorization"], "Bearer FAKE_OLD") + self.assertEqual(second.kwargs["headers"]["Authorization"], "Bearer FAKE_NEW") + self.assertNotEqual(first.kwargs["headers"]["Checksum"], second.kwargs["headers"]["Checksum"]) self.assertNotIn("checksum", request.call_args.kwargs["params"]) diff --git a/tests/test_v2.py b/tests/test_v2.py index 7dd7a0f..436d002 100644 --- a/tests/test_v2.py +++ b/tests/test_v2.py @@ -93,6 +93,33 @@ def test_semester_has_empty_query_and_schedule_uses_exact_v2_case(self): self.assertEqual(prepared.headers["Checksum"], "fake%3d:123") self.assertFalse(call.kwargs["allow_redirects"]) + def test_build32_reads_keep_credentials_out_of_prepared_urls(self): + operations = ("CheckUpdateProfile", "GetSemesterMark", "GetApplication", "CheckOpenFeedBack", "GetNotificationByRoll") + with requests.Session() as session, patch.object(session, "send", return_value=Mock()) as send, \ + patch.object(v2, "create_checksum", return_value="fake%3d:123") as signer: + for operation in operations: + with self.subTest(operation=operation): + query = {"rollNumber": "FAKE+ROLL"} + v2.request(session, operation, credential="FAKE_PRIVATE_KEY", campus="TEST", params=query) + prepared = send.call_args.args[0] + self.assertEqual(parse_qs(urlsplit(prepared.url).query), {"CampusCode": ["TEST"], "rollNumber": ["FAKE+ROLL"]}) + self.assertNotIn("FAKE_PRIVATE_KEY", prepared.url) + self.assertEqual(prepared.headers["Authorization"], "Bearer FAKE_PRIVATE_KEY") + self.assertEqual(prepared.headers["Checksum"], "fake%3d:123") + self.assertIsNone(prepared.body) + self.assertNotIn("Content-Type", prepared.headers) + self.assertEqual(query, {"rollNumber": "FAKE+ROLL"}) + self.assertEqual(signer.call_count, len(operations)) + signer.assert_called_with("FAKE_PRIVATE_KEY") + + def test_build32_reads_reject_explicit_authen_before_http(self): + for operation in ("CheckUpdateProfile", "GetSemesterMark", "GetApplication", "CheckOpenFeedBack", "GetNotificationByRoll"): + with self.subTest(operation=operation), self.assertRaises(ApiError) as caught: + v2.request(self.session, operation, credential="fake", campus="TEST", + params={"rollNumber": "FAKE", "Authen": "PRIVATE_VALUE"}) + self.assertNotIn("PRIVATE_VALUE", str(caught.exception)) + self.session.request.assert_not_called() + def test_response_is_returned_without_classification_or_retry(self): self.response.status_code = 401 self.assertIs(v2.request(self.session, "GetSemester", credential="fake", campus="TEST"), self.response) diff --git a/uv.lock b/uv.lock index 2af4001..df69d1d 100644 --- a/uv.lock +++ b/uv.lock @@ -995,7 +995,7 @@ wheels = [ [[package]] name = "myfap" -version = "0.2.0" +version = "0.2.1" source = { editable = "." } dependencies = [ { name = "beautifulsoup4" },