Repository navigation
Add tests for admin DLQ routes, admin suspension, storage, profile pictures, and route mounts - #311
Merged
Tybravo merged 1 commit intoOct 22, 2026
Conversation
…l upload Resolve issues SwiftChainn#232, SwiftChainn#234, SwiftChainn#235, SwiftChainn#236. - Add integration tests for the admin DLQ routes covering list pagination, retry success, retry failure with retryCount increments, resolved-entry rejection, 404, and admin-only gating (SwiftChainn#232). - Add unit tests for admin user suspension: controller reason and ban validation, service status rules (409, 404, 400, 422, 403), and audit log entries (SwiftChainn#235). - Add storage driver tests (local disk round-trip, S3 with a fake client, driver factory) and profile picture pipeline tests (Sharp resize, JPEG encoding, replace and delete flows) (SwiftChainn#234). - Add a route mount smoke test that walks the Express router stack, checks each route returns a JSON envelope without crashing, verifies handlers passed to routers are imported, and checks route files are not both unmounted and documented in the README (SwiftChainn#236). Fix: LocalStorageDriver.upload() now rejects keys that resolve outside the upload root, matching the existing check in delete(). Previously a key such as "../escape.txt" was written outside the upload directory.
Collaborator
|
Well done and Thank you for your contribution |
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.
Summary
This PR adds test coverage for the admin DLQ routes, admin user suspension, the storage drivers and profile picture pipeline, and a route-mount smoke test. It also fixes a path traversal gap in the local storage driver's upload path that the storage tests exposed.
closes #232
closes #234
closes #235
closes #236
Implementation details
#232 Admin DLQ routes (
tests/adminDlqRoutes.test.ts)page/limit), 401 without a token, 403 for non-admins.pending, records the error, and incrementsretryCount; repeated failures accumulate; already-resolved entries return 400; unknown IDs return 404; non-admins get 403.stellarService.submitEscrowLockis mocked.#235 Admin user suspension
tests/unit/controllers/adminController.test.ts: reason required and trimmed (400),banmust be boolean (400),bandefaults to false,ban: truepassed through, 409/404 forwarded from the service, 401 without an actor, andrequireRole(ADMIN)returns 403 for non-admins.tests/unit/services/adminService.test.ts(real MongoDB): suspend and ban apply status and reason; 409 for already-suspended or already-banned; 404 unknown user; 400 malformed ID; 422 self-action; 403 targeting another admin; audit log entry includes the acting admin ID and reason.#234 Storage and profile pictures
tests/unit/services/storage.service.test.ts: local driver round-trip on a temp directory, nested keys, no-op delete of a missing file, traversal rejected on upload and delete; S3 driver with a fake client (signed URL returned, upload/delete commands, error propagation); factory selects the driver from config and caches it until reset.tests/unit/services/profilePicture.service.test.ts: real Sharp. Oversized images fit within 500px and are encoded as JPEG; small images are not enlarged; non-image input returns 500; unsupported MIME and oversize return 400; replacement deletes the previous key; old-file delete failure does not fail the request; delete clears fields;isValidImage.Source fix (
src/services/storage.service.ts)LocalStorageDriver.upload()previously built the path withpath.joinand no containment check, so a key such as../escape.txtwas written outside the upload root. Upload and delete now share aresolveWithinRoothelper that rejects any key resolving outside the root.#236 Route mount smoke test (
tests/unit/routes/mountSmoke.test.ts)routes/index.tsrouter stack to collect every mounted route (more than 50).successand does not leak aReferenceError/TypeErrortext.router.<verb>()orrouter.use()is bound by an import or declaration in its route file.routes/index.tsand named in the README fails the test. Currently none do.Tests and results
Command run:
Result: 6 suites passed, 68 tests passed, 0 failed.
Coverage of touched files (from that run):
storage.service.ts97.95% lines,profilePicture.service.ts86.81%,dlqController.ts94.11%,dlqService.ts92.85%,adminController.ts53.84%,adminService.ts63.82%. The loweradminService/adminControllerfigures come fromgetAdminDisputesand the disputes controller, which are outside this issue's scope.ESLint: clean on all touched files. Prettier applied.
Full
pnpm testwas not run as part of this PR (see known limitations).Compatibility and security considerations
LocalStorageDriver. Keys that already resolved inside the upload root behave as before. Keys that escaped now throw instead of writing outside the directory.Known limitations
maxAttemptslimit and an exhausted state. Neither exists inDlqService: retries are unbounded and a failed retry returns the entry topending. I did not invent that behavior in this PR; it needs a maintainer decision.jest.setup.jspinsMONGOMS_VERSION=7.0.14, but Jest loadstests/jest.setup.ts, which does not. Without the env var, tests download MongoDB 6.0.14, which was slow and interrupted on my machine. The Mongo-backed suites pass withMONGOMS_VERSION=7.0.14. Consider pinning intests/jest.setup.tsas a follow-up.main, not caused by this PR:npx tsc --noEmitreports errors insrc/services/escrow.service.ts(duplicateAuditLogidentifier, a sort typing error, and a missingScanLapsedFundingWindowsResult) and intests/unit/services/idempotency.service.test.ts(missinguuidtypes).pnpm run buildalso fails on ignored build scripts. Neither is touched here.backend/tests/...; this repository keepssrc/andtests/at the root, so the files are placed there.indexerRoutes.ts), which the README does not document.