Skip to content

fix: resolve issues #2090, #2091, #2092, and #2093 - #2337

Merged
K1NGD4VID merged 2 commits into
LabsCrypt:mainfrom
lockoabosede8-byte:fix/issues-2090-2091-2092-2093
Nov 24, 2026
Merged

K1NGD4VID merged 2 commits into
LabsCrypt:mainfrom
lockoabosede8-byte:fix/issues-2090-2091-2092-2093

Conversation

@lockoabosede8-byte

@lockoabosede8-byte lockoabosede8-byte commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

This PR resolves four testing and regression gaps across backend middleware and utility handlers:

  • [test] Cover async handler rejected promises #2090: [test] Cover async handler rejected promises
    • Fixed asyncHandler in backend/src/utils/asyncHandler.ts by wrapping handler invocation in try/catch prior to Promise.resolve, capturing synchronous exceptions before they can escape.
    • Added deterministic tests in backend/src/utils/__tests__/asyncHandler.test.ts for promise rejections occurring after headers are sent (res.headersSent === true), non-Error normalization with cause/stack preservation, and Express error handling lifecycle integration.
  • [test] Cover rate limiter distributed counters #2091: [test] Cover rate limiter distributed counters
    • Added tests in backend/src/middleware/__tests__/rateLimiter.test.ts for Redis connection outages and reconnection failures, asserting fail-open behavior (passOnStoreError: true) and degradation alerting.
    • Added tests for key isolation across client IP addresses, limiter prefixes, compound keys (ip:publicKey), and Redis store key prefixing.
    • Added tests for standard RFC rate limit headers (RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset), legacy header omission, 429 contract with Retry-After, and quota recovery after window expiration.
  • [test] Cover loan access tenant boundaries #2092: [test] Cover loan access tenant boundaries
    • Added test coverage in backend/src/middleware/__tests__/loanAccess.test.ts enforcing strict tenant boundaries in requireLoanOwner (blocking admins, lenders, and unrelated users from claiming ownership).
    • Added test coverage for requireLoanBorrowerAccess role boundaries (admin/lender view authorization vs unrelated user rejection, role casing sensitivity).
    • Added tests verifying authentication and loanId format validation take precedence before database lookups or role bypasses.
  • [test] Cover pause guard state races #2093: [test] Cover pause guard state races
    • Added deterministic race tests in backend/src/middleware/__tests__/pauseGuard.test.ts for concurrent setPauseState operations and error propagation.
    • Added cache synchronization tests verifying stale in-memory state is properly updated to match database state (updatePauseStateFromDatabase).
    • Added resilience tests for empty database results and null contract/reason fields, and verified request handling across pause/unpause transitions.

Verification

  • npm --prefix backend run typecheck passed (0 errors).
  • npm --prefix backend run lint passed (0 errors).
  • npm --prefix backend run format:check passed.
  • All 86 tests passed across asyncHandler.test.ts, rateLimiter.test.ts, loanAccess.test.ts, and pauseGuard.test.ts.

Closes #2090
Closes #2091
Closes #2092
Closes #2093.

LabsCrypt#2093

- LabsCrypt#2090: [test] Cover async handler rejected promises
- LabsCrypt#2091: [test] Cover rate limiter distributed counters
- LabsCrypt#2092: [test] Cover loan access tenant boundaries
- LabsCrypt#2093: [test] Cover pause guard state races
@github-actions github-actions Bot added the security:malware-suspected Automated malware indicator found in a pull request label Nov 24, 2026
@github-actions

Copy link
Copy Markdown

Malware detection scan flagged this pull request

The scan found 2 indicator(s) in the PR diff. This PR is blocked until a maintainer reviews the flagged files.

  • backend/src/middleware/__tests__/rateLimiter.test.ts — hidden-appended-config-payload (high)
  • backend/src/utils/__tests__/asyncHandler.test.ts — hidden-appended-config-payload (high)

This is an automated triage signal; maintainers must verify whether the finding is malicious or intentional.

@K1NGD4VID
K1NGD4VID merged commit 2f0bde2 into LabsCrypt:main Nov 24, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security:malware-suspected Automated malware indicator found in a pull request

Projects

None yet

2 participants