Skip to content

test(pagination): property tests for cursor round-trip and tamper rej…#653

Open
Mayorlay wants to merge 1 commit into
CredenceOrg:mainfrom
Mayorlay:test/pagination-cursor-properties
Open

test(pagination): property tests for cursor round-trip and tamper rej…#653
Mayorlay wants to merge 1 commit into
CredenceOrg:mainfrom
Mayorlay:test/pagination-cursor-properties

Conversation

@Mayorlay

Copy link
Copy Markdown

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

…ection

Verifies decode(encode(c))==c and single-byte mutation rejection in
lib/pagination.ts.
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add fast-check property tests for the cursor encode/decode round-trip and tamper rejection in lib/pagination.ts

1 participant