Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(message): hold the media response body, not only its headers

Yudhi Armyndharisc1e84397d691
diff --git a/CHANGELOG.md b/CHANGELOG.md
index debd2a288..7c99b8d0b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Turkish (`tr`) dashboard translation. Thanks @codedByCan.
- `AUDIT_RETENTION_DAYS` is checked at boot, so a typo fails startup with a named error instead of silently reverting to the 90-day default. It is validated as an integer of any sign rather than a positive one, because both `0` and any negative value are documented switches that disable audit-log pruning entirely.
- `message.controller.spec.ts` holds the two headers the stored-media download sends, `X-Content-Type-Options: nosniff` and `Content-Disposition: attachment`; deleting either had passed every suite in the repo.
+- That same spec now also holds the passthrough declaration and the returned bytes, so a media response carrying both security headers and no body at all no longer passes it.
- Optional `quotedMessageId` on every `send-*` message endpoint and its MCP tool, so a reply can carry media, a location, a contact card or a poll instead of only text. An id the engine cannot resolve now fails the send rather than delivering the message unquoted. Thanks @nirizr for the report.
### Fixed
diff --git a/src/modules/message/message.controller.spec.ts b/src/modules/message/message.controller.spec.ts
index b82574fe9..7a8069025 100644
--- a/src/modules/message/message.controller.spec.ts
+++ b/src/modules/message/message.controller.spec.ts
@@ -1,3 +1,5 @@
+import { StreamableFile } from '@nestjs/common';
+import { RESPONSE_PASSTHROUGH_METADATA } from '@nestjs/common/constants';
import { MessageController } from './message.controller';
import type { MessageService } from './message.service';
import type { BulkMessageService } from './bulk-message.service';
@@ -35,4 +37,29 @@ describe('MessageController — stored media download', () => {
it('sends the media as an attachment, so it is never rendered on the API origin', async () => {
expect((await mediaResponseHeaders())['Content-Disposition']).toBe('attachment');
});
+
+ /**
+ * The headers above are set on the response object directly, so they survive a handler that sends
+ * no body at all — a `404` with a perfect `Content-Disposition` would satisfy both. What actually
+ * carries the bytes is the returned `StreamableFile`, and Nest only sends that when the response
+ * parameter is declared passthrough: without it Nest treats the handler as having taken the
+ * response over and discards the return value entirely. Both halves are asserted here so the pair
+ * above cannot end up describing a response that is never sent.
+ *
+ * Nest records the flag under its own metadata key rather than in the route arguments, and only
+ * when it is truthy — so reading it back is what distinguishes `@Res({ passthrough: true })` from
+ * a bare `@Res()`.
+ */
+ it('declares the response passthrough, so Nest sends the returned file rather than discarding it', () => {
+ expect(Reflect.getMetadata(RESPONSE_PASSTHROUGH_METADATA, MessageController, 'getChatMedia')).toBe(true);
+ });
+
+ it('returns the stored bytes as the response body', async () => {
+ const res = { set: () => undefined } as unknown as Response;
+
+ const body = await controller.getChatMedia('session-1', '[email protected]', 'msg-1', res);
+
+ expect(body).toBeInstanceOf(StreamableFile);
+ expect(body.getStream().read()).toEqual(Buffer.from('GIF89a'));
+ });
});