test(pagination): property tests for cursor round-trip and tamper rej…#653
Open
Mayorlay wants to merge 1 commit into
Open
test(pagination): property tests for cursor round-trip and tamper rej…#653Mayorlay wants to merge 1 commit into
Mayorlay wants to merge 1 commit into
Conversation
…ection Verifies decode(encode(c))==c and single-byte mutation rejection in lib/pagination.ts.
|
@Mayorlay Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add property-based tests for cursor round-trip and tamper rejection
Adds src/lib/pagination.property.test.ts with fast-check property tests covering four
invariants in lib/pagination.ts:
Round-trip — decode(encode(c)) === c holds for arbitrary string pairs and Date timestamps,
proving the encode/decode bijection across the full input space.
Tamper-rejection — For every byte position in an encoded cursor, any mutation that changes the
decoded payload is rejected: decodeCursor either returns null (format destroyed) or throws
PaginationValidationError (HMAC mismatch). Base64url padding-bit-only flips are correctly
identified and excluded — they change the encoded string but not the decoded content, so HMAC
still matches and the original value is returned unchanged (not a bypass).
parsePositiveInteger semantics — Accepts positive integers [1, MAX_LIMIT]; rejects floats,
negatives, zero, and non-numeric strings via parsePaginationParams.
Limit clamping — Missing limit defaults to DEFAULT_LIMIT; valid range [1, MAX_LIMIT] passes
through; anything above MAX_LIMIT throws PaginationValidationError.
All 11 tests run with a fixed seed (0xc0ffee) for deterministic CI reproduction.
Tested: npm run test -- pagination.property — 11/11 pass
Lint: No errors introduced (test files are excluded from ESLint by project config)
Build: No new TypeScript errors
▸ Credits: 0.14 • Time: 7s
Add property-based tests for cursor round-trip and tamper rejection
Adds src/lib/pagination.property.test.ts with fast-check property tests covering four
invariants in lib/pagination.ts:
Round-trip — decode(encode(c)) === c holds for arbitrary string pairs and Date timestamps,
proving the encode/decode bijection across the full input space.
Tamper-rejection — For every byte position in an encoded cursor, any mutation that changes the
decoded payload is rejected: decodeCursor either returns null (format destroyed) or throws
PaginationValidationError (HMAC mismatch). Base64url padding-bit-only flips are correctly
identified and excluded — they change the encoded string but not the decoded content, so HMAC
still matches and the original value is returned unchanged (not a bypass).
parsePositiveInteger semantics — Accepts positive integers [1, MAX_LIMIT]; rejects floats,
negatives, zero, and non-numeric strings via parsePaginationParams.
Limit clamping — Missing limit defaults to DEFAULT_LIMIT; valid range [1, MAX_LIMIT] passes
through; anything above MAX_LIMIT throws PaginationValidationError.
All 11 tests run with a fixed seed (0xc0ffee) for deterministic CI reproduction.
Tested: npm run test -- pagination.property — 11/11 pass
Lint: No errors introduced (test files are excluded from ESLint by project config)
Build: No new TypeScript errors
▸ Closes #636